automatic backups in linux using rdiff-backup
I’ve used several backup solutions to backup important servers to other machines. For a while there, I was content with my little rsync script and a cron job. But, I wanted something a little more robust. I did a little digging and found rdiff-backup.
I like the way rdiff-backup works because it’s backup server initiated — this is nice if you have a backup “server” at home behind a dynamic (cable-modem, DSL, etc.) internet connection that might not always have the same IP address. It really doesn’t even need to be a server, just any old installation of Linux with a nice sized hard drive (might I recommend an LVM partition), will do.
When I backed up from the actual servers to the backup server I was always worried about my dynamic dns not resolving correctly, whle I *know* the actual server will always keep the same IP. It also makes it possible for the backup server to backup multiple “servers.” And, if you’re really clever, you can actually have the script first synch a file list from the server it is going to backup, and then perform the backup — this is so you don’t have to specify directories that you may not know or care to know about from the server itself.
Here are my notes and some good setup help:
See:
the rdiff wiki and:
http://rdiff-backup.solutionsfirst.com.au/index.php/UnattendedRdiff
http://www.linode.com/wiki/index.php/AutomatedRdiffBackup
You’ll first need to do some ssh-key-exchanging. See the above guide (gentoo-specific in parts, but not all).
Once your backup server is able to ssh into the server (and technically only run rdiff-backup) without requesting a password, you’re ready to configure it to run automatically.
Here’s my /etc/cron.daily/daily-backup.cron :
#! /bin/bash
# run the rdiff-backup script
/usr/bin/rdiff-backup --include-globbing-filelist
/root/backup_file_list.txt
--exclude '**' fa.cetio.us-backup::/ /backups/
exit 0
Just create this file (assuming you’re using a modern day cron like vixie that has these daily helper directories), and chmod +x (make it executable). You can see it refers to a backup_file_list.txt that has:
- [directories to exclude]
[directories to include]
So, I’ve got a few directories in there to include:
/var/www/example.com/htdocs
and in doing so, have to exclude:
- /var/www/
and
- /var/
So as not to back up the entire /var directory.
Very cool stuff.
