Backups using rdiff-backup and rsnapshot


Performing a Restore

Restoring a data version from the last backup using the current mirror is really easy. The best option is to use the cp command with the archive option:

# cp -a /mnt/backup/shadow /etc/shadow

However, its strength's only become evident if older versions of files need to be restored. This requires regular backups and an associated increment at the desired time. The following example restores the /etc/hosts file, exactly as it used to be when the backup was performed March 19, 2015 (at 20:15:46 hours, see --list-increments:

# rdiff-backup /mnt/backup/rdiff-backup-data/increments/hosts.\
  2015-03-19T20\:15\:46+01\:00.diff.gz /tmp/hosts

You can also use the timestamp when restoring and do without increments:

# rdiff-backup -r 7D /mnt/backup/hosts /tmp/hosts

This means you receive the file in the state it was in seven days ago. If you don't have a backup from this time, rdiff-backup selects the previous increment (e.g., the one eight days ago). You can find more information about this on the man page for rdiff-backup in the TIME FORMATS and RESTORING sections.

The rdiff-backup-fs command is a useful alternative for backing up files. It mounts a backup directory and provides the user with individual increments as a directory. Listing 2 shows that each backup performed appears as a separate directory.

Listing 2


# TZ='+1' rdiff-backup-fs /mnt/fuse /mnt/backup/
# ls /mnt/fuse/
2015-03-15T09:15:19 2015-03-15T09:50:34 2015-03-19T20:15:46
2015-03-21T09:45:05 2015-03-15T09:28:48 2015-03-15T10:44:06

Make sure the TZ variable is set; otherwise, the directory names won't agree with the backup times. For practical purposes, you will see immediately from the directories the state of the data at a specific time. To restore a file, simply go to a directory and copy it to the desired location.

Removing Backups

The idea of time periods comes up again when you start removing old backups. You can't delete a special increment, but you can delete all those older than five days, for example:

# rdiff-backup --remove-older-than 5D /mnt/backup

A warning is output if the time period selected would remove multiple increments. If you're sure that the increments to be deleted are correct, you can delete them using the --force option.


Backups in the production environment with statistics other than data volumes and changes makes dimensioning backup servers easier and provides information about data growth. Rdiff-backup logs more than 15 values for each backup process and writes them to separate files or session statistics. It is possible to display the value either directly by calling --print-statistics, by analyzing the rdiff-backup-data/session_statistics files, or using the rdiff-backup-statistics program.

You can display the values directly by calling --print-statistics, analyze the data with rdiff-backup-data/session_statistics files, or use the rdiff-backup-statistics program.

Say you unwittingly back up a new file and want to find out which one. The statistics file first tells you what data volume has changed in the mirror:

# grep TotalDestinationSizeChange /mnt/backup/rdiff-backup-data/\
TotalDestinationSizeChange 41943106 (40.0 MB)

Another view of the file statistics lists which file effected the change:

# gunzip -c /mnt/backup/rdiff-backup-data/file_statistics.\
  2015-03-15T10\:44\:06+01\ | awk '$2==1{print}' | sort -k3nr,3
dump/data-dump 1 41943040 NA 0
dump 1 0 0 NA
samba 1 0 0 NA
samba/dhcp.conf 1 0 0 66

The columns for the file statistics are divided into FileName, Changed, SourceSize, MirrorSize, and IncrementSize. Because dump/data-dump is a new file, Changed is 1, MirrorSize is NA (file hasn't been mirrored yet), and IncrementSize also is  . SourceSize is almost the whole TotalDestinationSizeChange, so the file occupies the storage space in the backup.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Using rsync for Backups

    Although commercial Linux backup tools are available, many people prefer open source to better understand and control the backup process. One open source tool that can do both full and incremental backups is rsync.

  • Encrypted backup with Duplicity
    The free Duplicity backup program consistently encrypts all backups, which means that backups can even be stored in an insecure cloud.
  • Redo Backup
    Redo Backup backs up complete hard drives locally or over a network. The focus is on simple operation and high reliability in a variety of deployment scenarios.
  • How to back up in the cloud
    In cloud computing practice, backups are important in several ways: Customers want to secure their data, and vendors want to secure the essential details of their platforms. Rescue yourself, if you can.
  • Cloud protection with Windows Azure Backup
    Microsoft offers the Windows Azure Backup service, which lets you back up data from servers in the cloud. This removes the need for your own infrastructure, and the service alleviates privacy concerns by using continuous encryption.
comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs

Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>


		<div class=