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.

To install it open a terminal shell and run:

sudo apt-get install rsnapshot

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

Configuration

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:

 snapshot_root       /var/cache/rsnapshot/

How many old backups you would like to keep. Since rsnapshot uses incremental backups, we can afford to keep older backups for awhile before removing them. You set these up under the BACKUP LEVELS / INTERVALS section. You 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.

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

And the most important part, you need to decide on 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 fun88体育 is and which directories you would like to back up.

backup [email protected]:/home/ example.com/    +rsync_long_args=--bwlimit=16,exclude=core
backup [email protected]:/etc/  example.com/    exclude=mtab,exclude=core

As you can see you can see you can pass extra rsync parameters (the + append 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 is a 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 to 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 Executing with cron section in Backups - Shell Scripts.

References

Last updated 1 year, 3 months ago. Help improve this document in the forum.