Your submission was sent successfully! Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

How to install and configure rsnapshot

rsnapshot is an rsync-based filesystem snapshot utility. It can take incremental backups of local and remote filesystems for any number of machines. rsnapshot makes extensive use of hard links, so disk space is only used when absolutely necessary. It leverages the power of rsync to create scheduled, incremental backups.

Install rsnapshot

To install rsnapshot open a terminal shell and run:

sudo apt-get install rsnapshot

If you want to backup a remote filesystem, the rsnapshot server needs to be able to access the target machine over SSH without password. For more information on how to enable this please see OpenSSH documentation. If the backup target is a local filesystem there is no need to set up OpenSSH.

Configure rsnapshot

The rsnapshot configuration resides in /etc/rsnapshot.conf. Below you can find some of the options available there.

The root directory where all snapshots will be stored is found at:

snapshot_root       /var/cache/rsnapshot/

Number of backups to keep

Since rsnapshot uses incremental backups, we can afford to keep older backups for a while before removing them. You set these up under the BACKUP LEVELS / INTERVALS section. You can tell rsnapshot to retain a specific number of backups of each kind of interval.

retain  daily   6
retain  weekly    7
retain  monthly   4

In this example we will keep 6 snapshots of our daily strategy, 7 snapshots of our weekly strategy, and 4 snapshots of our monthly strategy. These data will guide the rotation made by rsnapshot.

Remote machine access

If you are accessing a remote machine over SSH and the port to bind is not the default (port 22), you need to set the following variable with the port number:

ssh_args       -p 22222

What to backup

Now the most important part; you need to decide what you would like to backup.

If you are backing up locally to the same machine, this is as easy as specifying the directories that you want to save and following it with localhost/ which will be a sub-directory in the snapshot_root that you set up earlier.

backup  /home/          localhost/
backup  /etc/           localhost/
backup  /usr/local/     localhost/

If you are backing up a remote machine you just need to tell rsnapshot where the server is and which directories you would like to back up.

backup root@example.com:/home/ example.com/    +rsync_long_args=--bwlimit=16,exclude=core
backup root@example.com:/etc/  example.com/    exclude=mtab,exclude=core

As you can see, you can pass extra rsync parameters (the + appends the parameter to the default list – if you remove the + sign you override it) and also exclude directories.

You can check the comments in /etc/rsnapshot.conf and the rsnapshot man page for more options.

Test configuration

After modifying the configuration file, it is good practice to check if the syntax is OK:

sudo rsnapshot configtest

You can also test your backup levels with the following command:

sudo rsnapshot -t daily

If you are happy with the output and want to see it in action you can run:

sudo rsnapshot daily

Scheduling backups

With rsnapshot working correctly with the current configuration, the only thing left to do is schedule it to run at certain intervals. We will use cron to make this happen since rsnapshot includes a default cron file in /etc/cron.d/rsnapshot. If you open this file there are some entries commented out as reference.

0 4  * * *           root    /usr/bin/rsnapshot daily
0 3  * * 1           root    /usr/bin/rsnapshot weekly
0 2  1 * *           root    /usr/bin/rsnapshot monthly

The settings above added to /etc/cron.d/rsnapshot run:

  • The daily snapshot everyday at 4:00 am
  • The weekly snapshot every Monday at 3:00 am
  • The monthly snapshot on the first of every month at 2:00 am

For more information on how to schedule a backup using cron please take a look at the Executing with cron section in Backups - Shell Scripts.

Further reading

This page was last modified 10 months ago. Help improve this document in the forum.