Last updated: Apr 13, 2007
rdiff-backup is a remote incremental backup tool which is both simple and very complete. It can be used in many situations (mirroring, local or remote backups using push or pull methods…).
For a full description, you can visit rdiff-backup official homepage and read the documentation for an overview of all the features.
I use this tool to make all my backups on a central server. The ever-running servers are backed up using the pull method, whereas the workstations, which contain the higher quantities of data, are backed up using the push method[1]
rdiff-backup always uses the following syntax:
rdiff-backup [options] <source> <target>
Where both <source> and <target> can be local or remote (in the latter case, the syntax is [user@]host::/remote-dir).
For this article, we assume that:
The aim of this document is to backup given files and directories, with the possibility to exclude either given files/directories or files/directories that match a defined pattern. Files and directories to include or exclude from the backup are listed in separate files.
In the following examples, we will use 2 files: backup.include, which lists the files and directories to be backed up, and backup.exclude which lists the files and directories to be excluded from the backup.
Both have the same very simple syntax: one file or directory per line.
If you specify a directory, all the files and subdirectories will be backed up (remember that rdiff-backup can be used as a mirror tool).
Thanks to the --{ex,in}clude-globbing-filelist options, we can even use file globbing.
Typically, you surely want to backup personal data (usually stored in /home), your configuration files (in /etc), as well as your local mail file.
Because you lack of space, you don’t want to back up your ogg or mp3 encoded audio files all stored in your ~/Music directory; you also want to exclude from the backup the several iso images that can be anywhere in your home (let’s say you can download them again later if a disaster happens!); finally, you decide to exclude from the backup a qemu hd image that you don’t use (are you one of these persons who like keeping old things just because “they can be useful”?). Your files would be as follows:
backup.include:
/home/toto/ /etc/ /var/mail/toto
backup.exclude:
/home/toto/Music **.iso /home/toto/qemu/qemu-hd.img
For detailed syntax of file globbing, please read carefully the man page, section “File selection”.
For this first example, we will backup data locally, let’s say from one partition to another, or, better, from one hard disk to another. The following script will be called directly by root, and the data will be saved to a partition mounted as /mnt/backups.
local-backup.sh:
rdiff-backup --print-statistics --terminal-verbosity 2 \ --exclude-globbing-filelist /path/to/backup.exclude \ --include-globbing-filelist /path/to/backup.include \ --exclude / / /mnt/backups/
Note that the options order is important: if you don’t indicate the exclude list before the include list, the script won’t work as desired (see documentation for explanations).
In this example, we will backup the data to a remote host called backserv. As already specified, you need to have an ssh access to this host (ideally using a public key without passphrase - see the “Unattended rdiff-backup HOWTO” in external resources).
remote-push-backup.sh:
rdiff-backup --print-statistics --terminal-verbosity 2 \ --exclude-globbing-filelist /path/to/backup.exclude \ --include-globbing-filelist /path/to/backup.include \ --exclude / / user@backserv::/var/backups/
Here, the method is different, but the result is quite the same. The idea is to pull the data from a remote host to a local directory. This method allows to set up easily a central backup server (no special configuration has to be made on the client side).
remote-pull-backup.sh:
rdiff-backup --print-statistics --terminal-verbosity 2 \ --exclude-globbing-filelist /path/to/backup.exclude \ --include-globbing-filelist /path/to/backup.include \ --exclude / user@desk1::/ /var/backups/
The restoring process is very well explained in the official documentation: http://www.nongnu.org/rdiff-backup/examples.html#restore
Just an example to restore one directory from the version backed up 10 days ago in a given directory:
rdiff-backup -r 10D user@backserv::/remote/ ./local/
Remember it is very important to test your backups!
rdiff-backup’s --remove-older-than mode can be used to delete older increments.
This section assumes that rdiff-backup has been used in the past to back up to host::/remote-dir, but all commands would work locally too, if the hostname were ommitted.
The following command deletes all information concerning file versions which have not been current for 2 weeks:
rdiff-backup --remove-older-than 2W host::/remote-dir
Note that an existing file which hasn’t changed for a year will still be preserved. But a file which was deleted 15 days ago cannot be restored after this command is run.
You should run such a command on a regular basis so as to preserve your disk space.
You will find here some information about me and my different projects. I am involved in several open source projects, and try to promote Free software. This site is thus mainly dedicated to Free Software use on GNU/Linux systems. Please do not hesitate to contact me for any comments on this site.