I wanted a nice way to do an hourly backup of a mysql database and only keep a days worth.
In the past I have written scripts that would check how many files were there or used find to delete
old only.
I wondered if I could use logrotate to handle this since it is installed on most systems and is simple to use.
Unfortunately it doesn't understand the term hourly and only does daily and monthly.
I wrote my backup script and created a simple logrotate.conf file but left out the section that said
how often to run.
[root@server1 bin]# cat backup-www-db.logrotate
/var/database_backup/mysql_dump.sql {
# hourly
rotate 24
compress
delaycompress
missingok
create 640 root adm
}
Then I just told the backup script to run logrotate as the first thing it does giving it that config file:
/usr/sbin/logrotate /usr/adm/bin/backup-www-db.logrotate
It rotates the previous database dump and compresses them.
It only runs when the script runs so I set cron to run every hour and we have a nice simple solution.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment