Oct 22, 2021 by Thibault Debatty | 664 views
In this blog post we show how to use
rsnapshot to configure nice and easy rolling backups.
rsnapshot is actually a script that relies on
rsync to perform the backups. This is actually extremely clever, as
rsync uses hard links and only creates a copy of files that have been modified since the last backup.
This has 2 advantages:
This is actually pretty similar to the way
git handles commits internally...
As easy as
sudo apt install rsnapshot
The configuration file is located at
/etc/rsnapshot.conf. The most important directives are:
snapshot_root : where rsnapshot must save backups. This should be an external device or a directory on a network drive...
no_create_root : rsnapshot should abort if the root directory is absent (i.e. if the external drive is removed or the network drive unavailable):
retain : allows to define different "kinds" of backups and the number of copies to keep for each. I like to keep 7 daily backups, 5 weekly backups and 12 monthly backups. So my configuration looks like:
retain daily 7 retain weekly 5 retain monthly 12
backup : indicates which directories must be saved, and where inside the
snapshot_root, for example:
backup /var/www www/
Good to know:
backupdirectives in your configuration...
Finally, you can test your configuration with
sudo rsnapshot configtest
Now, we must configure crontab such that daily backups take place every day, weekly backups every week, and montly backup every month:
sudo nano /etc/crontab
## rsnapshot backups # m h dom mon dow user cmd 55 1 * * * root rsnapshot daily 55 2 * * 1 root rsnapshot weekly 55 3 1 * * root rsnapshot monthly
After a few days (and months), your
snapshot_root directory will be filled with the appropriate backups directories...