rdiff-backup – A Remote Incremental Backup Tool for Linux

rdiff-backup is a powerful and easy-to-use Python script for local/remote incremental backup, which works on any POSIX operating system such as Linux, Mac OS X or Cygwin. It brings together the remarkable features of a mirror and an incremental backup.

Significantly, it preserves subdirectories, dev files, hard links, and critical file attributes such as permissions, uid/gid ownership, modification times, extended attributes, acls, and resource forks. It can work in a bandwidth-efficient mode over a pipe, in a similar way as the popular rsync backup tool.

rdiff-backup backs up a single directory to another over a network using SSH, implying that the data transfer is encrypted thus secure. The target directory (on the remote system) ends up an exact copy of the source directory, however extra reverse diffs are stored in a special subdirectory in the target directory, making it possible to recover files lost some time ago.


To use rdiff-backup in Linux, you’ll need the following packages installed on your system:

  • Python v2.2 or later
  • librsync v0.9.7 or later
  • pylibacl and pyxattr Python modules are optional but necessary for POSIX access control list(ACL) and extended attribute support respectively.
  • rdiff-backup-statistics requires Python v2.4 or later.

How to Install rdiff-backup in Linux

Important: If you are operating over a network, you’ll have to install rdiff-backup both systems, preferably both installations of rdiff-backup will have to be the exact same version.

The script is already present in the official repositories of the mainstream Linux distributions, simply run the command below to install rdiff-backup as well as its dependencies:

On Debian/Ubuntu

$ sudo apt-get update
$ sudo apt-get install librsync-dev rdiff-backup

On CentOS/RHEL 7

# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
# rpm -ivh epel-release-7-9.noarch.rpm
# yum install librsync rdiff-backup

On CentOS/RHEL 6

# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
# yum install librsync rdiff-backup

On Fedora

# yum install librsync rdiff-backup
# dnf install librsync rdiff-backup [Fedora 22+]

How to Use rdiff-backup in Linux

As I mentioned before, rdiff-backup uses SSH to connect to remote machines on your network, and the default authentication in SSH is the username/password method, which normally requires human interaction.

However, to automate tasks such as automatic backups with scripts and beyond, you will need to configure SSH Passwordless Login Using SSH keys, because SSH keys increases the trust between two Linux servers for easy file synchronization or transfer.

Once you have setup SSH Passwordless Login, you can start using the script with the following examples.

Backup Files to Different Partition

The example below will backup the /etc directory in a Backup directory on another partition:

$ sudo rdiff-backup /etc /media/aaronkilik/Data/Backup/mint_etc.backup
Backup Files to Different Partition

Backup Files to Different Partition

To exclude a particular directory as well as it’s subdirectories, you can use the --exclude option as follows:

$ sudo rdiff-backup --exclude /etc/cockpit --exclude /etc/bluetooth /media/aaronkilik/Data/Backup/mint_etc.backup

We can include all device files, fifo files, socket files, and symbolic links with the --include-special-files option as below:

$ sudo rdiff-backup --include-special-files --exclude /etc/cockpit /media/aaronkilik/Data/Backup/mint_etc.backup

There are two other important flags we can set for file selection; --max-file-size size which excludes files that are larger than the given size in bytes and --min-file-size size which excludes files that are smaller than the given size in bytes:

$ sudo rdiff-backup --max-file-size 5M --include-special-files --exclude /etc/cockpit /media/aaronkilik/Data/Backup/mint_etc.backup

Backup Remote Files on Local Linux Server

For the purpose of this section, we’ll use:

Remote Server (tecmint)	        : 
Local Backup Server (backup) 	:

As we stated before, you must install the same version of rdiff-backup on both machines, now try to check the version on both machines as follows:

$ rdiff-backup -V
Check rdiff Version on Servers

Check rdiff Version on Servers

On the backup server, create a directory which will store the backup files like so:

# mkdir -p /backups

Now from the backup server, run the following commands to make a backup of directories /var/log/ and /root from remote Linux server in /backups:

# rdiff-backup [email protected]::/var/log/ /backups/
# rdiff-backup [email protected]::/root/ /backups/

The screenshot below shows the root file on remote server and the backed up files on the back server

Backup Remote Directory on Local Server

Backup Remote Directory on Local Server

Take note of the rdiff-backup-data directory created in the backup directory as seen in the screenshot, it contains vital data concerning the backup process and incremental files.

rdiff-backup - Backup Process Files

rdiff-backup – Backup Process Files

Now, on the server, additional files have been added to the root directory as shown below:

Verify Backup Directory

Verify Backup Directory

Let’s run the backup command once more time to get the changed data, we can use the -v[0-9] (where the number specifies the verbosity level, default is 3 which is silent) option to set the verbosity feature:

# rdiff-backup -v4 [email protected]::/root/ /backups/ 
Incremental Backup with Summary

Incremental Backup with Summary

And to list the number and date of partial incremental backups contained in the /backups/ directory, we can run:

# rdiff-backup -l /backups/

Automating rdiff-back Backup Using Cron

We can print summary statistics after a successful backup with the --print-statistics. However, if we don’t set this option, the info will still be available from the session statistics file. Read more concerning this option in the STATISTICS section of the man page.

And the –remote-schema flag enables us to specify an alternative method of connecting to a remote computer.

Now, let’s start by creating a backup.sh script on the backup server as follows:

# cd ~/bin
# vi backup.sh

Add the following lines to the script file.


#This is a rdiff-backup utility backup script

#Backup command
rdiff-backup --print-statistics --remote-schema 'ssh -C %s "sudo /usr/bin/rdiff-backup --server --restrict-read-only  /"'  [email protected]::/var/logs  /backups/

#Checking rdiff-backup command success/error
if [ $status != 0 ]; then
        #append error message in ~/backup.log file
        echo "rdiff-backup exit Code: $status - Command Unsuccessful" >>~/backup.log;
        exit 1;

#Remove incremental backup files older than one month
rdiff-backup --force --remove-older-than 1M /backups/

Save the file and exit, then run the following command to add the script to the crontab on the backup server

# crontab -e

Add this line to run your backup script daily at midnight:

0   0  *  *  * /root/bin/backup.sh > /dev/null 2>&1

Save the crontab and close it, now we’ve successful automated the backup process. Ensure that it is working as expected.

Read through the rdiff-backup man page for additional info, exhaustive usage options and examples:

# man rdiff-backup

rdiff-backup Homepage: http://www.nongnu.org/rdiff-backup/

That’s it for now! In this tutorial, we showed you how to install and basically use rdiff-backup, an easy-to-use Python script for local/remote incremental backup in Linux. Do share your thoughts with us via the feedback section below.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

2 Responses

  1. Colin Tinker says:

    Great piece on rdiff, not used it for few years and it made life nice and easy for me.

Leave a Reply to Colin Tinker Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.