Skip to main content
Welcome guest. | Register | Login | Post

backup using rdiff-backup

rdiff-backup is a commandline utility to backup one directory in another. Both the source and destination directory may be on other computers than the one on which the command is issued, but of course don't need to be. The backup will consist of a copy of the latest versions of the backed-up files (so retrieving the newest backup is easy, just copy it back with cp or your favourite filemanager) and an archive of differences between the newest versions of files and older versions (of previous backups).

I wrote the following script to do my backups for me:


rdiff-backup --exclude-device-files --exclude-fifos --exclude-sockets --exclude-other-filesystems --exclude /lost+found / /mnt/backup/2008/root
rdiff-backup --exclude-fifos --exclude-sockets --exclude-other-filesystems --exclude /home/lost+found /home /mnt/backup/2008/home
rdiff-backup --exclude /boot/lost+found /boot /mnt/backup/2008/boot

(note: each line except #!/bin/bash starts with rdiff-backup, even though it probably doesn't look like that if your browser window isn't wide enough. Be careful with copy-pasting... actually you shouldn't copy and paste this, since it's most likely not tuned for your system)

The syntax of the command is rdiff-backup [options] [source] [destination].
If the destination is a subdirectory of the source, make sure it is excluded using --exclude. I don't know what will happen if you don't do that Smiling . In this script the destination is implicitly excluded because it is on another filesystem than the source (in this case, source = internal disk, destination = external disk).

Other things that will be excluded by --exclude-other-filesystems are /proc, /sys, probably /dev if you use udev or devfs (and with 99% certainty you do), etc. On my system /tmp and /var/tmp are also excluded (like they should be - no sense in backing those up) because those are on a ramdisk, you probably need to exclude them explicitly.

--exclude-device-files probably isn't needed since I use udev, but it doesn't do any harm. fifos and sockets generally are temporary things, so you don't want to back those up either. lost+found directories are supposed to be empty, when they're not you shouldn't be making backups but copying your disk to a new one ASAP - so no sense in backing those up.

You may be surprised I exclude other filesystems in the line used to backup /home . It's because I have some mountpoints for FUSE (more specifically, sshfs) within my home directory. I don't think those will ever be mounted while I do a backup, but you never know... and downloading the whole filesystem of some server into my backup doesn't seem like a good idea!

As mentioned before, to restore the latest version of a file, you simply copy it back. To restore a file as it was some day in the past, you would for example do this:

rdiff-backup -r 2007-12-31 /mnt/backup/2008/home/yournamehere/report.odt /home/yournamehere/report-oldversion.odt

(this should be only one line)

I didn't need to do that yet.

There are some more options to rdiff-backup (and I told nothing about remote backups, which are just as easy as local ones), so do check out the documentation and the manual page.


I just updated my backup

I just updated my backup script a little. Be cautious, this won't be tested until the next time I backup!


rdiff-backup -v5 --exclude-device-files --exclude-fifos --exclude-sockets --exclude-other-filesystems --exclude /lost+found / /mnt/backup/2008/root
rdiff-backup -v5 --exclude 'ignorecase:**/cache' --exclude-fifos --exclude-sockets --exclude-other-filesystems --exclude /home/lost+found /home /mnt/backup/2008/home
rdiff-backup -v5 --exclude /boot/lost+found /boot /mnt/backup/2008/boot

-v5 should cause some information about the backup process to be shown.

--exclude 'ignorecase:**/cache' should prevent the junk in various caches from being backed up. ignorecase causes the rule to also match Cache and CACHE and even cAcHe. The ** matches anything of any length, possibly containing /es. Do not use this cache exclusion if your home directory contains anything important named "cache". Also, do not use it outside /home, because likely there will be some things named "cache" that actually aren't caches (eg some things in the linux kernel headers).
If unsure, try locate -i /cache/ (beware, that shows only directories named cache, not files, but those would be caches, and you don't want to see all cache.h's).

Important tips


Important tips, it is very very useful for administrators, I think the command lines is hard to use for newbie, rdiff-backup need one GUI tool, like putty, one all-in-one tool can make all jobs to be easy to do.

The ignorecase:**/cache

The ignorecase:**/cache thing doesn't work, I'm not sure why and couldn't really be bothered to find out. I now exclude each cache directory with a separate --exclude

It's not just useful for

It's not just useful for administrators, home users need to backup too. I'd like to use this opportunity to remind everyone of the three B's:


Really, you don't want to find out what it's like when your disk dies and you don't have recent backups.

Are command lines really hard to use for newbies? Do we perhaps need easier to read/use documentation for command line utilities?

You confused me by talking about putty. It's just a terminal emulator for MS Windows, right?

I agree a GUI for rdiff-backup would be nice. To backup, a file tree in which any file or directory can be included or excluded by ticking a checkbox next to it, and a big "backup!" button. Th