rdiff-backup provides an easy way to maintain reverse-incremental backups of your data. Reverse incremental backups are different from normal incremental backups by synthetically updating the full backup and keeping reverse diffs of all the files changed. It is best illustrated by an example. Let’s consider backups taken on three consecutive days:
1. Full backup (1st day).
2. Full backup (2nd day), reverse-diff: 2nd -> 1st.
3. Full backup (3rd day), reverse diffs: 3rd -> 2nd, 2nd -> 1st.
Compare that with the regular incremental backup model which would be:
1. Full backup (1st day).
2. Diff: 2nd -> 1st, full backup (1st day).
3. Diffs: 3rd -> 2nd, 2nd -> 1st, full backup (1st day).
This especially makes purging old backups easier. Reverse incremental backups allows you to simply purge the reverse-diffs as they expire. This happens because newer backups never depend on older ones. In contrast, in the regular incremental model, each incremental backup depends on each prior backup in the chain, going back to the full backups. Thus, you can’t remove the full backup until all the incremental backups that depend on it expire as well. This means that most of the time you need to keep more than one full backups, which takes up precious disk space.
rdiff-backup has some disadvantages as well:
1. Backups are not encrypted, making it unsuitable as-is for remote backups.
2. Only the reverse-diffs are compressed.
The advantages of
rdiff-bakcup make it suitable to create local Time Machine-like backups.
The following script, set via cron to run daily, can be used to take backups of your home directory:
#! /bin/sh SOURCE="/home/user/" TARGET="/home/user/backups/rdiff-home/" ## Backup rdiff-backup --exclude-if-present .nobackup --exclude-globbing-filelist /home/user/backups/home-exclude --print-statistics $SOURCE $TARGET ## Remove old data rdiff-backup --remove-older-than 1M --force --print-statistics $TARGET
where `/home/user/backups/home-exclude should look like:
+ /home/user/Desktop + /home/user/Documents + /home/user/Music + /home/user/Pictures + /home/user/Videos + /home/user/.vim + /home/user/.vimrc + /home/user/.ssh + /home/user/.gnupg **
In order to select only certain files and directories to backup.
--exclude-if-present .nobackup allows you to easily add a
.nobackup file to directories you wish to ignore. The
--force argument when purging the old backups allows it to remove more than one expired backup in a single run.
Listing backup chains:
$ rdiff-backup -l ~/backups/rdiff-home/
Restoring files from the most recent backup is simple. Because
rdiff-backup keeps the latest backup as a normal mirror on the disk, you can simply copy the file you need out of the backup directory. To restore older files:
$ rdiff-backup --restore-as-of 10D ~/backups/rdiff-home/.vimrc restored_vimrc