Auto-Delete old logs and backups

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
palinka
Senior user
Senior user
Posts: 1725
Joined: 2017-09-12 17:57

Auto-Delete old logs and backups

Post by palinka » 2018-07-22 19:18

I just ran across this useful script and I thought it would be good to share.

Save as .cmd and run in task scheduler. I run this on both log files (for 10 days) and backups (for 3 days).

Code: Select all

forfiles /p "C:\Program Files (x86)\hMailServer\Logs" /s /m *.* /D -10 /C "cmd /c del @path"
/s is the switch to add subfolders, which I don't have any, but I left it there anyway. Doesn't hurt.

One thing is while running on logs - I could not get the script to work manually due to UAC and the fact the folder is protected, but setting task scheduler to run as SYSTEM worked fine.

User avatar
jimimaseye
Moderator
Moderator
Posts: 8363
Joined: 2011-09-08 17:48

Re: Auto-Delete old logs and backups

Post by jimimaseye » 2018-07-22 19:44

You could incorporate the cleanup in your nightly backup as suggested here: viewtopic.php?f=21&t=28139 (scroll down the bottom of the first post to the section "LOG FILES"). That one looks up and determines where the log files are making the script independent of configuration.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

palinka
Senior user
Senior user
Posts: 1725
Joined: 2017-09-12 17:57

Re: Auto-Delete old logs and backups

Post by palinka » 2018-07-22 22:14

I read the entire thread (before posting this topic, actually).. I especially like the email notification. I will install those scripts sooner or later.

What I posted here is for the novice like me. ;-) And it is working. :-)

User avatar
jimimaseye
Moderator
Moderator
Posts: 8363
Joined: 2011-09-08 17:48

Re: Auto-Delete old logs and backups

Post by jimimaseye » 2018-07-22 22:26

Yep. It's a good option. My suggestion was offering people by suggestion a place to run it inclusive with the backup scripts (irrespective of whether they choose compress as my offering or delete of logs as you have offered. Some might want to combine both methods of deleting very old and compressing more recent).
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
mattg
Moderator
Moderator
Posts: 20632
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Auto-Delete old logs and backups

Post by mattg » 2018-07-23 01:17

And yet under Australian law, I need to keep my logs for 5 years, so I ZIP mine each month with a script
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

palinka
Senior user
Senior user
Posts: 1725
Joined: 2017-09-12 17:57

Re: Auto-Delete old logs and backups

Post by palinka » 2018-07-23 21:13

mattg wrote:
2018-07-23 01:17
And yet under Australian law, I need to keep my logs for 5 years, so I ZIP mine each month with a script
I'm an outlaw already... :twisted:

Post Reply