Updated 29 April 2019


Rsnapshot is a backup utility, written in Perl and Rsync-based. It makes periodic backup of filesystems easier. Rsnapshot uses hard links for data deduplication. Backup is a necessary part of system administration, as there is always a risk of data loss, such as hard disk failure, accidental data deletion, malware, or else a file system failure.

Rsnapshot allows you to make several levels of snapshots (alpha, beta, gamma, etc.) and assign any names to them, as well as rotate them, removing obsolete ones. This manual refers to 6 alpha, 7 beta and 4 gamma copies.

To create a new snapshot, the rsnapshot sync command is used, which places all the specified data in the .sync directory in the backup path.

To put a snapshot at the alpha level, use the rsnapshot alpha command. At first start, the '.sync' directorysync will be renamed to alpha.0. On the second run, alpha.0 will be renamed to alpha.1 and the current copy will be saved as alpha.0. Thus, alpha.0 will always contain the latest snapshot. Subsequent snapshots will also be renamed and stored until their number reaches six - in this case, a copy of alpha.5 will be deleted and replaced with alpha.4.

To visualize creation of a snapshot, see the diagram below:

              |           .sync           |
                ∇          -->
alpha level | 0 | 1 | 2 | 3 | 4 | 5 | - |
                ∇            -->
beta level  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | - |
                ∇      -->
gamma level | 0 | 1 | 2 | 3 | - |

The beta snapshot is created from the oldest copy of the alpha level (alpha.5) with the rsnapshot beta command.

In other words, alpha.0 derives from the file system, alpha.1 from alpha.0, beta.0 from the latest alpla (alpha.5), beta.1 from beta.0, gamma.0 from the latest beta (beta.6).


If alpha.5 does not exist at the moment rsnapshot beta is executed, while alpha.4 does exist, the beta.0 snapshot will not be created. Nonetheless, the other beta snapshots will be rotated. Therefore, you should not run the subsequent levels more often than the preceding ones.


First install rsnapshot:

emerge -a app-backup/rsnapshot


Make basic settings by editing, if necessary, the backup path and/or the number and levels of snapshots:


# path to the local directory where snapshots will be stored
snapshot_root   /var/calculate/snapshots

# levels and number of snapshots
retain  alpha   6
retain  beta    7
retain  gamma   4


Note that fields are Tab -spaced!

Check the list of paths that will not be backuped:

- /dev/*
- /lost+found
- /tmp/*
- /usr/portage/*
- /var/lib/layman/*
- /lxc/*/snaps
- /lxc/*/rootfs/dev/*
- /lxc/*/rootfs/tmp/*
- /lxc/*/rootfs/usr/portage/*
- /lxc/*/rootfs/var/lib/layman/*
- /lxc/*/rootfs/var/log/*
- /lxc/**/calculate/packages
- /lxc/**/remote/distfiles
- /packages
- /remote/distfiles
- /snapshots/*
- /var/calculate/snapshots/*

Local snapshots

Path configuration

The example below describes the backup paths (root of the file system and the /var/calculate directory) for the current system via the backup parameter:


backup  /               localhost/rootfs/
backup  /var/calculate  localhost/calculate

From now on, paths ~localhost/rootfs~ and ~localhost/calculate~~~ will be created in the storage directory as the filesystem root and the /var/calculate locations, respectively.

Creating a snapshot

To prepare the data to be backuped, run:

rsnapshot sync

If necessary, this command can be interrupted or restarted as many times as you need. After the synchronization is complete, proceed to alpha level rotation:

rsnapshot alpha

Running again rsnaphost sync will prepare a new backup. rsnapshot alpha will perform the rotation and move the synchronized data to level alpha0.

When alpha snapshots have filled the level, you will be able to move the latest snapshot to the beta level instead of deleting it. To do this, run rsnapshot beta before running rsnapshot alpha.

alpha level | 0 | 1 | 2 | 3 | 4 | 5 |
                        alpha.6     |
beta level  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | - |

Executing these commands in the reverse order will cause the last alpha copy to be deleted first, then an alpha level of 6 items to be formed, and then the last item to be moved to the beta level, which will reduce the alpha queue by 1.

              +---+---+---+---+---+---+ +---+
alpha level | 0 | 1 | 2 | 3 | 4 |   | | 6 |
              +---+---+---+---+---+---+ +---+
                        alpha.5     |
beta level  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | - |

Scheduling snapshots

Add a daily .sync snapshotting procedure to cron. Synchronization may take a while; make sure you schedule sufficient time to complete it (12 hours approx.). Tell the system to make daily alpha and beta copies every Saturday, and gamma copies on the first of each month.


Before you create an alpha copy, you must create a beta, and a gamma one before you create a beta.

As deleting an obsolete copy can take some time, a pause (1 hour) should be added between rotations.



# run rsnapshot
0 0 * * *   root    /usr/bin/rsnapshot sync &>/dev/null
0 10 1 * *  root    /usr/bin/rsnapshot gamma &>/dev/null
0 11 * * 6  root    /usr/bin/rsnapshot beta &>/dev/null
0 12 * * *  root    /usr/bin/rsnapshot alpha &>/dev/null

Setting up snapshots for a remote node

Backup server configuration

Generate a ssh key for password-less access to the distant host on the backup server:

ssh-keygen -b 4096 -f /root/.ssh/backup.key

Add the key to be used for all clients:


rsync_long_args     --delete --numeric-ids --delete-excluded --rsh="ssh -i /root/.ssh/backup.key

Specify the locations for which snapshots will be created:


backup     example/rootfs/
backup  example/calculate/


  • is the network name of the host,
  • rootfs and calculate are the locations to be described in the configuration file of the rsyncd client

Client configuration

Create a file on the remote computer to be snapshot, containing the description of the directories to be synchronized. Assign new names to them, rootfs and calculate:


uid = root
gid = root
read only = true

    path = /

    path = /var/calculate

Copy the previously generated server public key to the remote host, adding rsync at the beginning of the line:

command="rsync --config=/etc/rsyncd-backup.conf --server --daemon .",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding

You should obtain something like that:


command="rsync --config=/etc/rsyncd-backup.conf --server --daemon .",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCohMEmkUVd72YI+gRXyCSL2YWQGg3tmy1SiKJ4i3enTpVf7oY+SDSk/WDJUkBisOh1VGWbtylCqez6K4/rkIxtQmog/L6KmnVEv/MKPXCfRb0SletaLLRhoLB9yjPJltzS+q/983yBIJKYO9jBJQbDYYdqPIuGidQ6xjX+OuJoCL/akKoaQxBm+92k+hp9Yi7RxGX12Y0WMD6XCZEZcktjGX/FyzIaRV9Ikt+0uHRZBo9lwEtEWEXY3coYauBr9A9XbtXPy4sGDXJsePKi7lxGi880IVgZgABMgPo9B8hVPVBplvKa5tUaj5C7s+lrZ0VI3Nr7i3c4cVwSnOcFlg9Z root@backup

Distributing nodes to different snapshot repositories

If computers for which snapshots are made are accessed over a low-speed connection, it is reasonable to split the storage into multiple backups.

Create an rsnapshot configuration file for local computers:


include_conf    `/bin/cat /etc/rsnapshot.conf`
snapshot_root   /var/calculate/snapshots/local
lockfile        /var/run/
include_conf    `/bin/cat /etc/rsnapshot.d/local.*.zone`
include_conf    `/bin/cat /etc/rsnapshot.d/`


Note that fields are Tab -spaced!

These settings refer to the common ones described in / etc / rsnapshot.conf , and replace the values for the lock file and the root of the snapshot storage volume. /etc/rsnapshot.d provides all zone files starting with local and

Create a rsnapshot config file for remote hosts:


include_conf    `/bin/cat /etc/rsnapshot.conf`
snapshot_root   /var/calculate/snapshots/remote
lockfile        /var/run/
include_conf    `/bin/cat /etc/rsnapshot.d/remote.*.zone`

Unlike the previous configuration file, this one provides only zone file names starting with remote.

Local snapshots will be saved at /var/calculate/snapshots/local, and remote snapshots at /var/calculate/snapshots/remote

Specify the locations for which snapshots will be created: