
Introduction
rsnapshot is a powerful filesystem snapshot utility that leverages rsync to facilitate easy and efficient backups of both local and remote systems via SSH. One of its standout features is its ability to use hard links to minimize the disk space required for snapshots. In this guide, we’ll walk through the process of installing and setting up rsnapshot on an Ubuntu 16.04 system, but the instructions are also applicable to other Debian and Ubuntu distributions.
Installation
Before starting the installation, it’s always a good practice to update your server to ensure all packages are up to date. Run the following command:
apt-get update
Next, install rsnapshot using Ubuntu’s package manager:
apt-get install rsnapshot -y
Configuration
After installation, you need to configure rsnapshot by editing its configuration file:
nano /etc/rsnapshot.conf
If nano
isn’t installed, you can install it by running:
apt-get install nano
Set the Backup Directory: Define where you want to store your backups by setting the snapshot_root
parameter. For example:
snapshot_root /backup/
Ensure that each directory path ends with a trailing slash (/
). If the directory doesn’t exist, rsnapshot will create it when it runs.
Enable SSH and Disk Usage Commands: Uncomment the following lines to enable SSH and disk usage tracking:
cmd_ssh /usr/bin/ssh
cmd_du /usr/bin/du
Define Retention Policy: Decide how many old backups you want to keep. For instance, to keep six hourly snapshots, seven daily backups, and four weekly backups, use the following configuration:
retain alpha 6
retain beta 7
retain gamma 4
Specify Backup Sources: If you are backing up directories on the same machine, specify them like this:
backup /home/ localhost/
To back up a remote system using rsync over SSH, ensure SSH is enabled and configured, then specify the remote path like this:
backup root@example.com:/home/ example.com/
Ensure you have key-based logins enabled for the root user on the remote server for this to work seamlessly.
Save and exit the configuration file by pressing CTRL + O
to save and CTRL + X
to exit.
Testing
Before running the backup, it’s crucial to test your configuration:
rsnapshot configtest
If the configuration is correct, you’ll receive a “Syntax OK” message. Next, perform a test run to verify that the snapshot works as expected:
rsnapshot -t alpha
The output should show the commands rsnapshot would run to perform the backup. If everything looks correct, remove the -t
option to execute the actual backup:
rsnapshot alpha
Scheduling Backups
To automate backups, you can schedule rsnapshot to run at specific intervals using cron. rsnapshot includes a default cron file that you can modify:
nano /etc/cron.d/rsnapshot
Uncomment the lines for alpha
, beta
, and gamma
to enable the scheduling:
0 */4 * * * root /usr/bin/rsnapshot alpha
30 3 * * * root /usr/bin/rsnapshot beta
0 3 * * 1 root /usr/bin/rsnapshot gamma
This configuration will create an alpha
snapshot every four hours, a beta
snapshot daily at 3:30 AM, and a gamma
snapshot weekly on Mondays at 3:00 AM.
Conclusion
With rsnapshot configured and scheduled, your server is now set up to automatically create filesystem backups, either on the same server or a remote one. This ensures your data is securely backed up and easily recoverable in case of any issues.