The last few days I have been testing backup software to automatically backup my desktop Ubuntu system. I’ve only just got it set up, but rdiff-backup is exactly what I was looking for and seems to be working very well.

rdiff-backup tries to “combine the best features of a mirror and an incremental backup”. It’s a command line utility that not only gives you a plain mirror of your files, but also allows you to retrieve previous versions of your files using the extra difference data it keeps. This means you can quickly copy and paste to restore a file from your most recent backup, or retrieve the contents of files as they were at the time of any previous backup. rdiff-backup has built in support for network backups over SSH and is network-efficient and fast thanks to its incremental nature. It’s also possible to run rdiff-backup on Windows, soon I’ll be investigating whether it will work as a backup solution for the Windows systems on my network.

If you’re looking for an simpler graphical backup tool, check out A Guide to System Backup and Restore in Ubuntu. The rest of this post will go though how I’ve set up rdiff-backup to backup my home directory to a hard drive connected to another Ubuntu system on my network.

SSH public key authentication
If you want to schedule automatic rdiff-backups over the network you will need to use public keys with SSH so rdiff-backup can log into the remote system without a password. This assumes that both the remote and local systems already have SSH servers installed.

On your local system create new key pair with no passphrase for your user:
ssh-keygen -t rsa

Use the ssh-copy-id tool to give the new public key to the remote backup system:
ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 2222 backups@192.168.1.40'

Finally, test logging in to the remote system without a password:
ssh -p 2222 backups@192.168.1.40

Install rdiff-backup
When operating over the network, rdiff-backup is required to be installed on both systems. Ideally both copies of rdiff-backup will be the exact same version. If your local and remote systems are both running the same version of Ubuntu, you can install it from the repositories. If you’ve got different versions of Ubuntu, there is a PPA available with the latest version of rdiff-backup for every supported version of Ubuntu except dapper. Unfortunately my remote backups server is still running dapper, but I didn’t have any trouble installing the latest version of rdiff-backup from source.

Write your backup script
rdiff-backup’s options are pretty easy to configure. Be sure to read the page of examples as well as the manpage as you write your backup command. Here’s my backup.sh script file for running a backup of my home directory:

#!/bin/shrdiff-backup --print-statistics --remote-schema 'ssh -p 2222 %s rdiff-backup --server' --exclude /home/tom/Virtual\ Machines --exclude /home/tom/Videos --exclude /home/tom/.gvfs --exclude /home/tom/.local/share/Trash /home/tom backups@192.168.1.40::/media/backups/backups/tom-rdiffrdiff-backup --remove-older-than 1M --remote-schema 'ssh -p 2222 %s rdiff-backup --server' backups@192.168.1.40::/media/backups/backups/tom-rdiff

The first command connects to my backups server with ssh on port 2222 and backs up my home directory while excluding some directories with files I won’t mind loosing (be sure to exclude your trash and gvfs folders). The second command removes increments older than one month to save disk space.

Restoring files
rdiff-backup doesn’t require anything special to restore files; just browse to the remote folder and all your files will be there. If you need it, you can use rdiff-backup to recover files from dates in the past. Check the links I posted in the last section for more on how to do this.

Automate it
I’ve scheduled my backup to run every Sunday when I’m not going to be on the computer using cron. Edit your user’s cron file with this command:
crontab -e

Here’s my cron line for backing up. See the Ubuntu documentation page for help with writing your own. I’ve also redirected stdout from the backup script to a log file so I can watch the rdiff-backup statistics.
0 2 * * 0 /home/tom/backup.sh >> backup.log

I’ve just finished setting up this new backup system, so I’ll update this page if I find that I need to make changes. What software are you backing up your Linux systems with? I’d be interested to hear how many of you are using rdiff-backup as well.


Related Posts