Rsnapshot: A Powerful Backup Tool Based on Rsync

Linux

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.

sudo dnf install epel-release
sudo dnf install rsnapshot

On Ubuntu-based distributions, rsnapshot is available in the default repositories, so you can install it using the apt package manager:

sudo apt install rsnapshot

Once installed, you can verify the installation by checking the version.

rsnapshot -v

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:

ssh-keygen -t rsa

Next, copy the public key to the remote server:

ssh-copy-id user@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:

sudo nano /etc/rsnapshot.conf
OR
sudo vi /etc/rsnapshot.conf

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.

snapshot_root   /data/backup/

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:

interval    hourly    6
interval    daily     7
interval    weekly    4
interval    monthly   3

Set Backup Directories

To back up local directories, add the directory paths.

backup    /home/     localhost/
backup    /etc/      localhost/

For remote backups, specify the remote server and directory to back up, like so:

backup    root@remote-server:/home/     /data/backup/

Enable Remote Backups

To enable remote backups over SSH, uncomment the cmd_ssh line:

cmd_ssh    /usr/bin/ssh

If you have changed the default SSH port, update the ssh_args line to reflect the custom port (e.g., port 7851):

ssh_args    -p 7851

Exclude Files and Directories

You can exclude certain files and directories from being backed up by creating an exclude file.

sudo nano /data/backup/exclude.txt

Add exclusions in the following format:

- /var/cache
- /tmp
+ /etc
+ /home

In your rsnapshot.conf file, reference the exclude file:

exclude_file    /data/backup/exclude.txt

After configuring Rsnapshot, verify that your setup is correct by running:

sudo rsnapshot configtest

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:

sudo rsnapshot hourly

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:

0 */4 * * *    root    /usr/bin/rsnapshot hourly
30 3 * * *     root    /usr/bin/rsnapshot daily
0 3 * * 1      root    /usr/bin/rsnapshot weekly
30 2 1 * *     root    /usr/bin/rsnapshot monthly

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:

sudo cp /usr/share/doc/rsnapshot/utils/rsnapreport.pl /usr/local/bin/
sudo chmod +x /usr/local/bin/rsnapreport.pl

Now, edit your rsnapshot.conf file and add the --stats flag to the rsync_long_args section:

rsync_long_args --stats --delete --numeric-ids --delete-excluded

Then, add the report to your cron job to email the report:

0 */4 * * * root /usr/bin/rsnapshot hourly 2>&1 | /usr/local/bin/rsnapreport.pl | mail -s "Hourly Backup Report" [email protected]

Monitoring Rsnapshot Backups

You can monitor your backups by checking the log files. By default, Rsnapshot logs backup activities in /var/log/rsnapshot.log.

cat /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.

Products You May Like

Articles You May Like

Oppo Find X8, Find X8 Pro Official-Looking Renders Show Off Design; Oppo Watch X, Enco X3 Set to Debut on October 24
Milky Way Could Be Part of a Much Larger Cosmic Structure, Possibly Linked to the Shapley Concentration
OxygenOS 15 Global Launch Date Set for October 24, Company Teases AI Features
Call of Duty: Black Ops 6, Modern Warfare 3 and Warzone Coming to Xbox Cloud Gaming in October
Amazon Launches Kindle Colorsoft Signature Edition; Refreshes Lineup With Improved Paperwhite and Scribe Models

Leave a Reply

Your email address will not be published. Required fields are marked *