Rsnapshot: A Powerful Backup Tool Based on Rsync

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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

28 Comments

Leave a Reply
  1. The ignore file seems not to work. I excluded some files and directories but rsnapshot copies these anyways. I tried it with + and - and without and changed the position… file is readable, with no errors.

    Reply
  2. Hi Ravi,

    Thanks for the article,

    Actually I have configured rsnapreport.pl in cron but I am getting null report of hourly. Could you please help me out why I am getting null mails instead of report. ?

    Reply
    • @Roshan,

      Have you checked backups? does backups happening? please confirm first and then check the cron entries correctly..

      Reply
  3. Using rsnapshot for about three years now. Nice introduction to rsnapshot. Thanks!
    Now I believe there’s not a word on how to recover / restore (as often on backup articles)…
    Here are tools I’d recommand you to check out:
    – I haven’t found rsnapreport.pl but there’s rsnapstat which is a fork in python [1].Gives a syntax error atm but I hope will be fixed
    – rsnapshot-once by Philipp C Heckel is freakin cool to insure consistent incremental backups [2] is the best wrapper

    @JJMacey, SystemBack does what you want. You might want to take a look, it’s a freaking kiss tool, that’s even able to backup a system on a live CD!
    Oh and Rtfazeberdee’s right on ksnapshot.

    [1] https://github.com/rmiceli/rsnapstats
    [2] https://github.com/binwiederhier/rsnapshot-once

    Reply
  4. A rather opening howto. Now it would be nice to include a few lines on **How to Restore**, might comes handy in a backup strategy ;) Especially as the rsnapshot official howto is very sparce in this field.

    Reply
  5. There’s a simple web app for backups with rsnapshot: ElkarBackup -www.elkarbackup.prg-.
    And it runs on any Debian/Ubuntu system. Raspberry PI included!

    Reply
  6. I’ve been using rsnapshot since Rubel’s original article 10+ years ago. In the current incarnation the syntax of paths is easy to screw up and so testing a configuration file without actually transferring files and with verbosity is essential for debugging the configuration. Attention to detail for setting up the cron job is similarly essential. When I get these worked out I then back up both so that it is relatively easy to reinstall when things disappear after a system upgrade.

    The automatic nature of rsnapshot is fantastic but it also can lead to complacency. It is wise to check the backups from time to time to make sure they’re still being made as planned. This is especially true after a system upgrade or the transfer of a system to new hardware. Particular attention made to confirming passwordless ssh login to target systems is still in effect when changes are made. It’s really annoying to find out that important data is not backed up because some months earlier an upgrade made ssh passwords obsolete.

    Reply
  7. All works fine, but the reports dont delivered to my email work, Why? I have to setup the email server function in this server? or where I put the pop and smtp servers to this work fine?
    Thanks

    Reply
  8. when i try to backup locally it works fine. but when i try to back up a remote server it gives me an error message.

    [kavinda@SVR1 ~]$ rsnapshot configtest
    —————————————————————————-
    rsnapshot encountered an error! The program was invoked with these options:
    /usr/bin/rsnapshot configtest
    —————————————————————————-
    ERROR: /etc/rsnapshot.conf on line 222:
    ERROR: backup [email protected].1.6:/home/ /data/backup/ – Backup destination \
    /data/backup/ must be a local, relative path
    ERROR: ———————————————————————
    ERROR: Errors were found in /etc/rsnapshot.conf,
    ERROR: rsnapshot can not continue. If you think an entry looks right, make
    ERROR: sure you don’t have spaces where only tabs should be.

    My /etc/rsnapshot.conf
    backup [email protected].1.6:/home/ /data/backup/

    Reply
  9. It looks like snapshot_root is a (temporary?) local directory where the backup will be stored. I can’t have that, since my server has used, say, 25GB of storage on a 40GB disk. NFS or USB mount is not an option. Replacing the disk is also not an option (besides, I don’t want to always have double the space I actually need/use). It’s a virtual server at a provider, so everything costs money. I won’t open up NFS over the internet, and I can’t reach the server to plug in anything.

    SSH to home is the only option for me. Which is there, but for what exactly? Can rsnapshot not “simply” backup directly via SSH without the use of a local directory? rsync can do this, but I don’t see how rsnapshot would.

    Another thing, how to restore?… Say I have to rebuild my server, Ubuntu is freshly installed. Then what?

    Reply
      • thank you very much for posting such a nice and useful concepts for linux administrators..

        my problem is ..

        i have configured rnapshot…..intervals i have kept is daily.0

        according to rsnapshot.conf it should take everyday backup at night 2 30 pm..

        and it should be incremental backup..

        every day it is taking backup..tats ok

        but for me problem is it is consuming lot of bandwidth for my internet..

        tat means my internet consuming will takes place every sunday..
        tat is every sunday it is taking or consuming 8 gb of internet ..

        plz help me on this..

        Reply
  10. If I am daily backing up a local directory, say /backup/ into rsnapshot directory /backup_r/, is there any way of NOT requiring /backup_r/daily.0/backup/ to be a copy, but rather a set of links to /backup, thereby saving disk space?

    Thanks.

    Lester

    Reply
  11. the claim “taking up the space of one single full backup plus differences” i do not think is true . All my 6 hoyrly backups have the same size, 13 Mb each.
    George Bouras

    Reply
    • No they don’t
      that’s what you see because of hard links
      actual physical space is full backups + changed files (not mere diffs)

      try creating hard links with ln and see if by yourself

      Reply
  12. Ravi,

    Thanks for the article!

    Normally to back-up files, before I wipe my H-P Spectre Ultrabook SSD, I use “ksnapshot”. The back-ups are ported to a USB drive. Obviously, “rsnapshot” has a few differences / advantages.

    Recently, I have been thinking of buying a back-up 128Gb SSD to use in case of disaster. Basically, I want to copy EVERYTHING to this new SSD, and use it to completely restore my system.

    Do you have an app preference to do this, and make my new SSD BOOTABLE?

    TIA for your response.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.