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:
#!/bin/bash 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 . 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.