How to Install and Use Rsnapshot (Making Server's Backups)

LawrenceLawrence Moderator
edited May 12 in Linux Applications


rsnapshot is a filesystem snapshot utility based on rsync. rsnapshot makes it easy to make periodic snapshots of local machines, and remote machines over ssh. The code makes extensive use of hard links whenever possible, to greatly reduce the disk space required.

This howto will show you how to install and set up rsnapshot. We are using Ubuntu 16.04 distribution, however you should be able to use it for all Debian and Ubuntu distributions we offer on Time4VPS.


Like always, first of all, we recommend to update your server. It can be done simply executing:

apt-get update

Install the program using the apt-get utility from Ubuntu’s default repositories:

apt-get install rsnapshot -y


After you have installed rsnapshot, you will need to edit the configuration file.

nano /etc/rsnapshot.conf

Note: if you do not have nano installed on your server (you are getting "-bash: nano: command not found") simply run:

apt-get install nano

First thing we need where you would like to store your backups. Set snapshot_root to path where you want to keep the backups:

snapshot_root /backup/

Note: Each directory needs a trailing slash (/) to be read correctly.
Note: If this directory does not already exist, rsnapshot will create it when it runs.

Also uncomment (remove the “#” from before the line) cmd_ssh and i lines:
cmd_ssh	/usr/bin/ssh
cmd_du /usr/bin/du
Next, we need to consider how many old backups we would like to keep. In following example, after 6 "hourly" snapshots the oldest "hourly" is deleted. The top entry (in this case "hourly") is copied from the source, while the remaining entries simply link to the latest snapshot from one level above.

In other words, to keep six backups a day (four-hour interval) [alpha], seven daily backups (one week) [beta], and four weekly backups (one month) [gamma], specify:
retain  alpha      6
retain beta 7
retain gamma 4
Finally, you’ll 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/

In addition to full paths on the local filesystem, you can also backup remote systems using rsync over ssh. If you have ssh installed and enabled (via the cmd_ssh parameter), you can specify a path like:

backup [email protected]:/home/

Note: Have in mind that you must have key-based logins enabled for the root user at, without passphrases in order this to function properly.

If everything is set up, just save and close nano: CTRL + O and CTRL + X.


We should test that everything works as expected. To test that your configuration has the correct syntax, simply run:

rsnapshot configtest

If your file is error-free, you will receive a “Syntax OK” message. If you got this message you can perform test f the snapshot to make sure we are producing the expected resules:

rsnapshot -t alpha

It should look something like this:
echo 9148 > /var/run/ 
mkdir -m 0700 -p /backups/
mkdir -m 0755 -p /backups/alpha.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
/home/ /backups/alpha.0/localhost/
mkdir -m 0755 -p /backups/alpha.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded /etc/ \
mkdir -m 0755 -p /backups/alpha.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
/usr/local/ /backups/alpha.0/localhost/
touch /backups/alpha.0/
If everything seems right you can try to setup backup for the first time, just remove "-t" from the previews command:

rsnapshot alpha

This will run the backup that we setup in our configuration file.


Finally we can schedule it to run at certain intervals. We will use cron to make this happen. rsnapshot includes a default cron file that we can edit to achieve what we want:

nano /etc/cron.d/rsnapshot

Uncomment (remove the “#” from before the line) alpha, beta and gamma lines. At the end it should look like:
# This is a sample cron file for rsnapshot.
# The values used correspond to the examples in /etc/rsnapshot.conf.
# There you can also set the backup points and many other things.
# To activate this cron file you have to uncomment the lines below.
# Feel free to adapt it to your needs.

0 */4 * * * root /usr/bin/rsnapshot alpha
30 3 * * * root /usr/bin/rsnapshot beta
0 3 * * 1 root /usr/bin/rsnapshot gamma
#30 2 1 * * root /usr/bin/rsnapshot delta
These settings will run add a snapshot to the “alpha” directory within our “/backup/” directory every four hours, add beta (daily) snapshot everyday at 3:30, add a gamma (weekly) snapshot every Monday at 3:00.


That's it! We just configured our server to automatically make filesystem backups and save it to the same server or to remote server.
Sign In or Register to comment.