bak - backup script
About
bak is a python backup script that utilizes rsync and hardlinks for efficient and convenient backups. Furthermore, backup rotation is achieved through simple expiration rules.
How It Works
This script utilizes rsync to backup any number of specified directories on other hosts to a local machine. You specify host, source, destination, and other options in the /etc/bak.conf file. Here is an example:
[mail.example.com] host=mail.example.com sources=/var /etc /home dest=/pub/bak
When added to a daily cronjob, this will cause the /var, /etc, and /home directories on mail.example.com to be incrementally backed up to the /pub/bak/mail.example.com/date/ directory. rsync will use hard-links to ensure that only a single copy of all unchanged files are saved to disk. You can cd into the backup directory at anytime and see your files.
You can also specify backup rotation parameters in the /etc/bak.conf to control when backups expire. The default is
num_days=14 num_weeks=10 num_months=12 num_years=10
This means that incremental backups for the last 14 days will be saved. Furthermore, the Sunday backup for the last 10 weeks will also be preserved as well as the first Sunday backup of each month for the last 12 months. Lastly, the first Sunday backup of the year will be preserved for 10 years.
Download
bak-0.14.tar.gz
Alternatively, browse the git repo or clone it
git clone http://brooks.nu/git/bak
RPM is also available.
Install
- Untar the source
tar xzvf tar-XXX.tar.gz
- Run the installation command
make install
- Edit the
/etc/bak.confto setup your backups.
The install script will put the script called bak in your /usr/sbin/ directory. It will also put a sym-link to this executable in your /etc/cron.daily directory. This will make the backup script run daily. You can instead remove the sym-link and add the script to your crontab.
SSH keys
As root, or whichever user your cronjob will run as, you will want to setup ssh keys so this script can run without human intervention to type in the password. Setting up ssh keys is simple.
- Create your keys
ssh-keygen
Select an empty passphrase and choose the default location
- Put the id_rsa.pub file in your authorized key file:
cd ~/.ssh cat id_rsa.pub >> authorized_keys
- Copy the
id_rsa.pub,id_rsa, andauthorized_keysfile to all your hosts.scp id_rsa id_rsa.pub authorized_keys host.example.com:.ssh/
- Test it out to see that you can ssh around without typing in your password.