Rsnapshot is an open-source local/remote filesystem backup utility written in Perl, which leverages the power of Rsync and SSH to create scheduled incremental backups of Linux/Unix filesystems.
Rsnapshot only takes up the space of a single full backup plus the differences, allowing you to store backups on a local drive, external USB stick, NFS-mounted drive, or over the network to another machine via SSH.
In this article, we’ll walk you through the process of installing, setting up, and using Rsnapshot to create hourly, daily, weekly, and monthly local backups, as well as remote backups.
Installing Rsnapshot Backup in Linux
First, you need to install and enable the EPEL (Extra Packages for Enterprise Linux) repository, as Rsnapshot is not included by default in RHEL-based distributions.
On Ubuntu-based distributions, rsnapshot is available in the default repositories, so you can install it using the apt package manager:
Once installed, you can verify the installation by checking the version.
Setting Up SSH Passwordless Login
To back up remote Linux servers, you need to configure SSH for passwordless login between the backup server and the remote machine.
Generate SSH public/private key pairs by following these commands:
Next, copy the public key to the remote server:
Configuring Rsnapshot in Linux
The configuration file for rsnapshot is located in /etc/rsnapshot.conf, open this configuration file with a text editor like nano or vim:
Some of the important settings you’ll need to configure include:
Snapshot Backup Directory
To set the directory where your backups will be stored, you need to edit the snapshot_root line in the configuration file.
Set Backup Intervals
Rsnapshot supports multiple backup intervals like daily, weekly, and monthly. You can set how often you want your backups by uncommenting the following lines:
Set Backup Directories
To back up local directories, add the directory paths.
For remote backups, specify the remote server and directory to back up, like so:
Enable Remote Backups
To enable remote backups over SSH, uncomment the cmd_ssh line:
If you have changed the default SSH port, update the ssh_args line to reflect the custom port (e.g., port 7851):
Exclude Files and Directories
You can exclude certain files and directories from being backed up by creating an exclude file.
Add exclusions in the following format:
In your rsnapshot.conf file, reference the exclude file:
After configuring Rsnapshot, verify that your setup is correct by running:
You should see the message “Syntax OK“. If there are any errors, fix them before proceeding.
Finally, you can run Rsnapshot manually using the command for the interval you want to back up:
Automating Rsnapshot with Cron
To automate the backup process, configure cron jobs to run Rsnapshot at specific intervals by adding the following to your /etc/cron.d/rsnapshot file:
Setting Up Rsnapshot Reports
Rsnapshot includes a script to send backup reports via email. To set it up, copy the script and make it executable:
Now, edit your rsnapshot.conf file and add the --stats flag to the rsync_long_args section:
Then, add the report to your cron job to email the report:
Monitoring Rsnapshot Backups
You can monitor your backups by checking the log files. By default, Rsnapshot logs backup activities in /var/log/rsnapshot.log.
Conclusion
Rsnapshot is an excellent choice for managing backups on Linux systems. With its efficient use of rsync, you can easily back up your files locally and remotely.