-2

I have a cron to backup 3 files every Hour, they are SQL backups - in the format name-name-bak-2015-12-1919:30:01.sql

I need a way to rotate and delete the older ones say every 7 days?

Thought of using log rotate and looking for advice

I'am Using Debian 8

Thanks

Chris

Froggiz
  • 3,043
  • 1
  • 19
  • 30

1 Answers1

0

To add a logrotate script, you can create a file, and add it to /etc/logrotate.d/

This is the file script content:

/yourfolder/name-name-bak-*.sql {
       weekly
       missingok
       rotate 14
       compress
       delaycompress
       notifempty
       create 640 root root
}

In this case:

  • weekly it will be run once per week
  • missingok If the log file is missing, go on to the next one without issu- ing an error message
  • rotate 14 Log files are rotated 14 times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather then rotated.
  • compress Old versions of log files are compressed with gzip by default.
  • delaycompress Postpone compression of the previous log file to the next rota- tion cycle. This has only effect when used in combination with compress. It can be used when some program can not be told to close its logfile and thus might continue writing to the previ- ous log file for some time.
  • notifempty Do not rotate the log if it is empty
  • create 640 root root Set user group and rights to the rotated files

more information on the man page : http://www.linuxcommand.org/man_pages/logrotate8.html

To launch manually (or test) your script, you can use the following command:

logrotate --force /etc/logrotate.d/yourfilename
Froggiz
  • 3,043
  • 1
  • 19
  • 30