How to perform incremental backup using rdiff-backup

Perform simple incremental backup using rdiff-backup utility.

Required software

Install rdiff-backup utility.

$ sudo apt-get install rdiff-backup
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libjs-sphinxdoc libjs-underscore librsync1 python-pylibacl python-pyxattr
Suggested packages:
  python-pylibacl-dbg python-pyxattr-dbg
The following NEW packages will be installed:
  libjs-sphinxdoc libjs-underscore librsync1 python-pylibacl python-pyxattr rdiff-backup
0 upgraded, 6 newly installed, 0 to remove and 28 not upgraded.
Need to get 386 kB of archives.
After this operation, 1,500 kB of additional disk space will be used.
Do you want to continue? [Y/n]
[...]

Perform incremental backup on local machine

Perform incremental backup of the blog.sleeplessbeastie.eu directory to /srv/backup/blog.sleeplessbeastie.eu, but exlude _site directory with generated content.

$ rdiff-backup --exclude blog.sleeplessbeastie.eu/_site blog.sleeplessbeastie.eu /srv/backup/blog.sleeplessbeastie.eu

Perform incremental backup to remote location.

$ rdiff-backup --exclude blog.sleeplessbeastie.eu/_site blog.sleeplessbeastie.eu backup.example.org::/srv/backup/blog.sleeplessbeastie.eu

Perform incremental backup, display modified files and detailed statistics at the end.

$ rdiff-backup --exclude blog.sleeplessbeastie.eu/_site --verbosity 5 --print-statistics blog.sleeplessbeastie.eu /srv/backup/blog.sleeplessbeastie.eu
Using rdiff-backup version 1.2.8
POSIX ACLs not supported by filesystem at blog.sleeplessbeastie.eu
Unable to import win32security module. Windows ACLs
not supported by filesystem at blog.sleeplessbeastie.eu
escape_dos_devices not required by filesystem at blog.sleeplessbeastie.eu
-----------------------------------------------------------------
Detected abilities for source (read only) file system:
  Access control lists                         Off
  Extended attributes                          On
  Windows access control lists                 Off
  Case sensitivity                             On
  Escape DOS devices                           Off
  Escape trailing spaces                       Off
  Mac OS X style resource forks                Off
  Mac OS X Finder information                  Off
-----------------------------------------------------------------
POSIX ACLs not supported by filesystem at /srv/backup/blog.sleeplessbeastie.eu/rdiff-backup-data/rdiff-backup.tmp.0
Unable to import win32security module. Windows ACLs
not supported by filesystem at /srv/backup/blog.sleeplessbeastie.eu/rdiff-backup-data/rdiff-backup.tmp.0
escape_dos_devices not required by filesystem at /srv/backup/blog.sleeplessbeastie.eu/rdiff-backup-data/rdiff-backup.tmp.0
-----------------------------------------------------------------
Detected abilities for destination (read/write) file system:
  Ownership changing                           Off
  Hard linking                                 On
  fsync() directories                          On
  Directory inc permissions                    On
  High-bit permissions                         On
  Symlink permissions                          Off
  Extended filenames                           On
  Windows reserved filenames                   Off
  Access control lists                         Off
  Extended attributes                          On
  Windows access control lists                 Off
  Case sensitivity                             On
  Escape DOS devices                           Off
  Escape trailing spaces                       Off
  Mac OS X style resource forks                Off
  Mac OS X Finder information                  Off
-----------------------------------------------------------------
Backup: must_escape_dos_devices = 0
Starting increment operation blog.sleeplessbeastie.eu to /srv/backup/blog.sleeplessbeastie.eu
Processing changed file .
Incrementing mirror file /srv/backup/blog.sleeplessbeastie.eu
Processing changed file _posts
Incrementing mirror file /srv/backup/blog.sleeplessbeastie.eu/_posts
Processing changed file _posts/.2018-09-12-how-to-perform-incremental-backup-using-rdiff-backup.html.swp
Incrementing mirror file /srv/backup/blog.sleeplessbeastie.eu/_posts/.2018-09-12-how-to-perform-incremental-backup-using-rdiff-backup.html.swp
Processing changed file _posts/2018-09-12-how-to-perform-incremental-backup-using-rdiff-backup.html
Incrementing mirror file /srv/backup/blog.sleeplessbeastie.eu/_posts/2018-09-12-how-to-perform-incremental-backup-using-rdiff-backup.html
--------------[ Session statistics ]--------------
StartTime 1519208194.00 (Wed Feb 21 10:16:34 2018)
EndTime 1519208196.31 (Wed Feb 21 10:16:36 2018)
ElapsedTime 2.31 (2.31 seconds)
SourceFiles 4122
SourceFileSize 321298360 (306 MB)
MirrorFiles 4122
MirrorFileSize 321298180 (306 MB)
NewFiles 0
NewFileSize 0 (0 bytes)
DeletedFiles 0
DeletedFileSize 0 (0 bytes)
ChangedFiles 4
ChangedSourceSize 13850 (13.5 KB)
ChangedMirrorSize 13670 (13.3 KB)
IncrementFiles 4
IncrementFileSize 858 (858 bytes)
TotalDestinationSizeChange 1038 (1.01 KB)
Errors 0
--------------------------------------------------

Verify current data in repository.

$ rdiff-backup --verify-at-time now  /srv/backup/blog.sleeplessbeastie.eu
Every file verified successfully.

List incremental backups in repository.

$ rdiff-backup --list-increments /srv/backup/blog.sleeplessbeastie.eu
Found 2 increments:
    increments.2018-02-21T10:13:59Z.dir   Wed Feb 21 10:13:59 2018
    increments.2018-02-21T10:16:34Z.dir   Wed Feb 21 10:16:34 2018
Current mirror: Wed Feb 21 10:21:56 2018

List files in the most recent backup.

$ rdiff-backup  --list-at-time now /srv/backup/blog.sleeplessbeastie.eu
.
.git
.git/COMMIT_EDITMSG
.git/HEAD
.git/branches
.git/config
.git/description
.git/hooks
[...]
atom.xml
favicon.ico
favicon.png
feed.xml
humans.txt
index.html
robots.txt
search
search/data.js
search/data.json
search/index.html
search_words.sh
sitemap.xml
tags
tags/index.html
tracking
tracking/index.html

List files modified since given time.

$ rdiff-backup --list-changed-since "2018-02-21T10:13:59"  /srv/backup/blog.sleeplessbeastie.eu
changed _posts
changed _posts/.2018-09-12-how-to-perform-incremental-backup-using-rdiff-backup.html.swp
changed _posts/2018-09-12-how-to-perform-incremental-backup-using-rdiff-backup.html

Compare current state of the directory with a most recent backup.

$ rdiff-backup --exclude blog.sleeplessbeastie.eu/_site  --compare-at-time now blog.sleeplessbeastie.eu /srv/backup/blog.sleeplessbeastie.eu
changed: _posts
changed: _posts/.2018-09-12-how-to-perform-incremental-backup-using-rdiff-backup.html.swp
changed: _posts/2018-09-12-how-to-perform-incremental-backup-using-rdiff-backup.html

Restore backup from specific point in time.

$ rdiff-backup --restore "2018-02-21T10:13:59Z"  /srv/backup/blog.sleeplessbeastie.eu /home/milosz/blog.sleeplessbeastie.eu/

Force restore backup from specific point in time.

$ rdiff-backup --force --restore "2018-02-21T10:13:59Z"  /srv/backup/blog.sleeplessbeastie.eu /home/milosz/blog.sleeplessbeastie.eu/

Restore most recent backup.

$ rdiff-backup --restore now /srv/backup/blog.sleeplessbeastie.eu /home/milosz/blog.sleeplessbeastie.eu/

Restore specific file.

$ rdiff-backup --restore now /srv/backup/blog.sleeplessbeastie.eu/about/index.html index-about.html

Remove incremental backups that are older than 1 month.

$ rdiff-backup --remove-older-than 1M /srv/backup/blog.sleeplessbeastie.eu
$ cat << EOF | tee /etc/cron.d/blog-backup
10 04 * * * rdiff-backup --exclude blog.sleeplessbeastie.eu/_site blog.sleeplessbeastie.eu /srv/backup/blog.sleeplessbeastie.eu
30 03 * * * rdiff-backup --remove-older-than 1M /srv/backup/blog.sleeplessbeastie.eu
EOF

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.