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:
<br /> #! /bin/sh</p> <p>SOURCE="/home/user/"<br /> TARGET="/home/user/backups/rdiff-home/"</p> <p>## Backup<br /> rdiff-backup --exclude-if-present .nobackup --exclude-globbing-filelist /home/user/backups/home-exclude --print-statistics $SOURCE $TARGET</p> <p>## Remove old data<br /> rdiff-backup --remove-older-than 1M --force --print-statistics $TARGET<br />
where `/home/user/backups/home-exclude should look like:
<br /> + /home/user/Desktop<br /> + /home/user/Documents<br /> + /home/user/Music<br /> + /home/user/Pictures<br /> + /home/user/Videos<br /> + /home/user/.vim<br /> + /home/user/.vimrc<br /> + /home/user/.ssh<br /> + /home/user/.gnupg</p> <p>**<br />
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:
<br /> $ rdiff-backup -l ~/backups/rdiff-home/<br />
Restoring files from the most recent backup is simple. Because
rdiff-backupkeeps 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:
<br /> $ rdiff-backup --restore-as-of 10D ~/backups/rdiff-home/.vimrc restored_vimrc<br />