These days, with digital storage cheaper than ever, and people accumulating increasing amounts of invaluable digital data (e.g., family videos), there is no excuse not to have a backup regime in case of hardware failure.
This article describes a simple automated backup scheme using the tool rsnapshot, which is based on rsync. rsnapshot makes a specified number of incremental backups of specified filetrees, using hard links to save space on the backup medium.
- Add an entry like the following in your fstab:
/dev/disk/by-label/backup /mnt/backup ext4 noatime,nodiratime,noauto 0 0
In this example, the filesystem is ext4, identified by the label backup, and attaches to a special mount point /mnt/backup. The noauto option means that this backup filesystem will not be mounted by default.
Create cron scripts for the different backup intervals:
echo "### RSNAPSHOT DAILY ###"
mount /mnt/backup && rsnapshot -c /etc/rsnapshot.d/daily.conf daily || echo "Backup failure"
echo "### RSNAPSHOT WEEKLY ###"
mount /mnt/backup && rsnapshot -c /etc/rsnapshot.d/weekly.conf daily || echo "Backup failure"
echo "### RSNAPSHOT MONTHLY ###"
mount /mnt/backup && rsnapshot -c /etc/rsnapshot.d/monthly.conf daily || echo "Backup failure"
These scripts must be executable.
rsnapshot configuration files
Set up the rsnapshot configuration files referred to in the scripts above.
rsnapshot configuration files are tab delimited. Be careful to always use tabs instead of spaces for the options.
Filetree specifications are in rsync format. See the rsync man page for details.
First a base configuration:
# Default config version
# So the hard disk is not polluted in case the backup filesystem is not available
# Standard settings
# For convenience, so that mount points can be taken as backup starting points
# Store all backups in one directory per machine
# A useful alternative may be to create a separate directory for each interval
Then, here are sample configuration files for daily, weekly and monthly backups:
# Daily (30 increments)
retain daily 30
backup /home/me/ localhost/
# Weekly (12 increments)
retain weekly 12
backup /etc/ localhost/
backup /var/db/pkg/world localhost/
backup /boot/ localhost/
# Monthly (6 increments)
retain monthly 6
backup / localhost/
In these files, the second argument of backup specifies a container directory for the backups, usually referring to the machine (in this case, localhost). This can be changed to any name of your choosing.
To restore the localhost backups specified above, we would use
rsync -a /mnt/backup/localhost/monthly.0/ /mnt/myroot/
rsync -a /mnt/backup/localhost/weekly.0/ /mnt/myroot/
rsync -a /mnt/backup/localhost/daily.0/ /mnt/myroot/
where /mnt/myroot is the mount point of the fresh root filesystem. In the paths above *.0 refers to the latest increment.
It is also possible to make remote backups via rsync or SSH -- see the rsnapshot man page for details.
If you are crazy enough to use btrfs you can leverage its snapshot feature with rsnapshot. Walter Werther has a guide on this: