The Rdiff-backup tool is a simple yet powerful backup tool that can be used to back up data either locally or remotely. It's a cross-platform tool written in python that works on both Linux, macOS and even FreeBSD. Rdiff-backup, just like rsync, is mostly a reverse incremental backup tool that updates the differences from the previous backup to the next one and ensures that you get the latest backup. Additionally, you can easily restore the backup and access your files. In this guide, you will learn how to install Rdiff-backup - A local and remote backup tool for Linux.
The Rdiff-backup tool uses the SSH protocol to back up directories over the network. This provides a secure safe and secure transfer of data thanks to the SSH protocol. The remote system ends up with a replica of the source directory and subsequent backups are synced incrementally. Without much further ado, let's dive in and see how the tool is used.
How to install Rdiff-backup tool
You can install the rdiff-backup tool in various Linux distributions using their respective package managers. The latest release is Version 2.x. But before we install it, you need some dependencies on your Linux system.
The latest Rdiff-backup tool requires that you have the following prerequisites:
- Python 3.6 and later versions
- librsync 1.0.0 and later
- pylibacl (This is optional but comes in handy in supporting ACLs)
- Pyxattr (For extended attribute support)
- Passwordless SSH configured to the target system ( For remote
On Ubuntu 20.04 or Debian Buster
For Ubuntu 20.04 and The latest Debian versions, install the latest Rdiff-backup tool using the command.
$ sudo apt install rdiff-backup
This installs rdiff-backup tool alongside all the dependencies.
To verify the version of rdiff installed, invoke the command:
$ rdiff-backup -V
Older versions of Ubuntu/Debian
For older versions, use Ubuntu backports
$ sudo apt install software-properties-common $ sudo add-apt-repository ppa:rdiff-backup/rdiff-backup-backports
The update the system packages and install Ridff-backup tool as shown
$ sudo apt update $ sudo apt install rdiff-backup
On CentOS 8/RHEL 8
For CentOS 8 RHEL 8, first, enable the COPR repository. Short for Cool Other Package Repo, COPR is a Fedora project that aims at providing an easy way of building and managing third-party repositories.
$ sudo dnf install yum-plugin-copr epel-release $ sudo dnf copr enable frankcrawford/rdiff-backup
Once you have added the repository, install the Rdiff-backup tool as shown:
$ sudo dnf --enablerepo=PowerTools install rdiff-backup
On CentOS 7/RHEL 7
Similarly, on CentOS 7 / RHEL you need to enable the COPR repository before installing the Rdiff-backup tool.
$ sudo yum install yum-plugin-copr epel-release $ sudo yum copr enable frankcrawford/rdiff-backup $ sudo yum install rdiff-backup $ sudo yum install py3libacl pyxattr => This is optional
On Fedora 32 and later
$ sudo dnf install rdiff-backup
For older versions of Fedora invoke the commands below:
$ sudo dnf install python3-pip python3-setuptools py3libacl python3-pyxattr $ sudo pip3 install rdiff-backup
Other Linux distributions
For Linux distros, you can install Rdiff-backup tool using the pip3 package manager from the PyPI (Python Package Index) repository as shown:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py $ sudo python3 get-pip.py $ sudo pip3 install rdiff-backup
How to Use Rdiff-backup tool
As mentioned earlier, the rdiff-backup command-line tool relies on the SSH service to connect and backup directories on remote targets. However, as you know, the default authentication for SSH is the username/password method. This requires direct user input. For rdiff-backup, this is not the desired authentication type. To automate backups and enjoy a smoother and seamless experience, you need to configure SSH Passwordless Login. This enables login using SSH keys which is a safer and more convenient way of file synchronization or transfer between Linux systems.
Making a local backup
The simplest and basic use of the rdiff-backup command is to create a local backup of a directory. You can back up a directory to a different path on the same system as shown.
$ sudo rdiff-backup foo bar
foo is the folder to be backed up and
bar is the backup directory.
Let's take an example. I have a directory called
reports containing text files as shown.
I have created a backup directory
/opt/backup where the files will be backed up.
$ sudo mkdir -p /opt/backup
To back up the
reports folder to the
/opt/backup directory, run the command:
$ sudo rdiff-backup reports /opt/backup
Take note of the
rdiff-backup-data directory that has been generated in the process. This directory contains crucial files pertaining to the backup process such as backup logs.
Restoring data from a local backup
We have seen how you can backup a directory locally on your local system. But let's assume we have accidentally deleted the reports directory or that it has been corrupted. to restore the directory from the backup directory in the
/opt/backup path, run the command:
$ sudo cp -a /opt/backup reports
Backing up a directory to a remote Linux system
To back up a directory to a remote server, first, ensure that rdiff-backup is installed on both systems and that the two versions of rdiff-backup are the same. . As discussed, you can cross-check the version of rdiff-backup using the command:
$ rdiff-backup -V
We have 2 Ubuntu 20.04 LTS servers as shown:
Ubuntu remote server - 220.127.116.11 Ubuntu backup server - 18.104.22.168
The backup is done from the backup server. In this example, we will back up the log files from the remote server located at
/var/log path. To achieve this, we need to first log in to the backup server.
$ ssh firstname.lastname@example.org
Then we will execute the command below:
$ rdiff-backup email@example.com::/var/log/ /opt/logs_backup/
Exclude a directory from being backed up
To exclude a directory from being backed up, use the
--exclude flag as shown:
$ rdiff-backup --exclude /etc/apt firstname.lastname@example.org::/var/log/ /opt/logs_backup/
Unlike rsync, rdiff-backup doesn't read the entire file on the target which significantly creates less disk i/o on the target which helps improve backup speed.
Rsync checks metadata of each file (timestamp, size of the files) on both source and target to determine which files needs to be updated. Where rdiff-backup keeps a metadata file on target which keeps track of the sha1 checksum of every file.
We have come to the end of this tutorial. In this guide, you have learned how to install and use rdiff-backup - A local and remote backup tool for Linux systems. Have a great time backing up your directories and files.