This script is designed to be used by processes that create tarred and compressed backups every hour or every day. These backups accumulate, taking up disk space.
By running this rotator script once per hour shortly before your hourly backup cron runs, you can save 24 houly backups, 7 daily backups and an arbitrary number of weekly backups (the default is 52).
Here's what the script will do:
This will effectively turn a user_backups dir like this:
backups/ world.tar.bz2
...into this:
user_backups_archive/ world/ hourly/ world-2008-01-01.tar.bz2
Those hourly tarballs will continue to pile up for the first 24 hours, after which a daily directory will appear. After 7 days, another directory will appear for the weekly tarballs as well.
Backups are moved from the incoming arrivals directory to the archives. If you do not produce hourly backups, but only produce daily backups, they system will only save the daily backups.
In step three, we added a cronjob for 30 minutes after each hour. This would be a good setting if for example your backups cron runs every hour on the hour. It's best to do all your rotating shortly before your backups.
You can edit the defaults in the script below, or create a config file in /etc/default/rotate-backups or $HOME/.rotate-backupsrc
The config file format follows the Python ConfigParser format (http://docs.python.org/library/configparser.html). Here is an example:
[Settings]
backups_dir = /var/backups/latest/
archives_dir = /var/backups/archives/
hourly_backup_hour = 23
weekly_backup_day = 6
max_weekly_backups = 52
backup_extensions = "tar.gz",".tar.bz2",".jar"
log_level = ERROR
Python 2.7
(I have not tested this with Python 3)
If you have comments or improvements, let me know:
Adam Feuer adamf@pobox.com http://adamfeuer.com
This script is based on the DirectAdmin backup script written by Sean Schertell