≡ Menu

How To Backup Local Unix Host Using rsnapshot rsync Utility

Backup and Restore Linux Local Host Using rsnapshotrsnapshot is an awesome free Linux backup utility to perform rsync backup of both local and remote file system.

This is a series of two articles. In this article, let us review how to install and configure rsnapshot utility to take rsync backup of local file system. In next article, let us review how to setup rsnapshot utility to take rsync backup of remote file system.

rsnapshot uses the combination of rsync and hard links to maintain full-backup and incremental backups. Once you’ve setup and configured rsnapshot, there is absolutely no maintenance involved in it. rsnapshot will automatically take care of deleting and rotating the old backups.

It also takes very less disk space. The first full backup will take the same size as your original files and directories. Subsequent rsnapshot full backups takes only less space, as it takes backup of only the modified files from the previous full backup.

1. Download rsnapshot Linux Backup Utility

Download the rsnapshot utility from rsnapshot.org as shown below.

# cd /usr/src
# wget http://www.rsnapshot.org/downloads/rsnapshot-1.3.1.tar.gz

# tar xvfz rsnapshot-1.3.1.tar.gz
# cd rsnapshot-1.3.1

2. Install rsnapshot to backup Linux direcotires

Install rsnapshot Linux backup utility using ./configure and make install as shown below.

# ./configure --sysconfdir=/etc

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
config.status: creating t/rsync.t
config.status: creating t/gnu_cp.t
config.status: creating t/relative_delete_bugfix.t
Type "make install" to install the program.
After rsnapshot is installed, don't forget to copy
/etc/rsnapshot.conf.default to /etc/rsnapshot.conf

# make install

/usr/bin/pod2man -c '' -n 'rsnapshot' -r '' rsnapshot > rsnapshot.1
/usr/bin/pod2man -c '' -n 'rsnapshot-diff' -r '' rsnapshot-diff > rsnapshot-diff.1
make[1]: Entering directory `/usr/src/rsnapshot-1.3.1'
test -z "/usr/local/bin" || mkdir -p -- "/usr/local/bin"
/usr/bin/install -c 'rsnapshot' '/usr/local/bin/rsnapshot'
/usr/bin/install -c 'rsnapshot-diff' '/usr/local/bin/rsnapshot-diff'
test -z "/etc" || mkdir -p -- "/etc"
/usr/bin/install -c -m 644 'rsnapshot.conf.default' '/etc/rsnapshot.conf.default'
test -z "/usr/local/man/man1" || mkdir -p -- "/usr/local/man/man1"
/usr/bin/install -c -m 644 './rsnapshot.1' '/usr/local/man/man1/rsnapshot.1'
/usr/bin/install -c -m 644 './rsnapshot-diff.1' '/usr/local/man/man1/rsnapshot-diff.1'
make[1]: Leaving directory `/usr/src/rsnapshot-1.3.1'

Now, create a new rsnapshot.conf based on the default configuration file that comes with the rsnapshot linux backup utility.

# cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf

3. Configure rsnapshot and Specify Backup Source Directory

Open the /etc/rsnapshot.conf and uncomment the following lines.

# vi /etc/rsnapshot.conf

cmd_cp          /bin/cp
cmd_ssh /usr/bin/ssh
cmd_du          /usr/bin/du
cmd_rsnapshot_diff      /usr/local/bin/rsnapshot-diff
logfile /var/log/rsnapshot

Define your destination backup directories in /etc/rsnapshot.conf as shown below. In this example,

  • /etc – source directory that should be backed-up
  • localhost/ – destination directory where the backup will be stored. Please note that this directory will be created under /.snapshots/{internal.n}/ directory as shown in the last step.
# vi /etc/rsnapshot.conf

backup  /etc/           localhost/

Note: Change /etc/ to the appropriate directory that you would like to backup.

4. Test rsnapshot Configuration

Perform configuration test to make sure rsnapshot is setup properly and ready to perform linux rsync backup.

# rsnapshot configtest
Syntax OK

5. Verify rsnapshot Hourly Backup Configuration

You can backup linux directories or files at various intervals. By default, the hourly and daily backups are configured.

Verify the hourly backup configuration.

# rsnapshot -t hourly
echo 6490 > /var/run/rsnapshot.pid
mkdir -m 0700 -p /.snapshots/
mkdir -m 0755 -p /.snapshots/hourly.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded /home \
mkdir -m 0755 -p /.snapshots/hourly.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded /etc \
mkdir -m 0755 -p /.snapshots/hourly.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
/usr/local /.snapshots/hourly.0/localhost/
touch /.snapshots/hourly.0/

6. Verify rsnapshot Daily Backup Configuration

Verify the daily rsnapshot cwrsync backup process is configured properly.

# rsnapshot -t daily
echo 6493 > /var/run/rsnapshot.pid
mkdir -m 0700 -p /.snapshots/
/.snapshots/hourly.5 not present (yet), nothing to copy

7. Invalid rsnapshot Backup Interval

There is no monthly backup interval. So, if you try to verify monthly backup configuraiton, you may get this message as shown below — ERROR: Interval “monthly” unknown, check /etc/rsnapshot.conf

# rsnapshot -t weekly
echo 6495 > /var/run/rsnapshot.pid
mkdir -m 0700 -p /.snapshots/
/.snapshots/daily.6 not present (yet), nothing to copy

# rsnapshot -t monthly
echo 6496 > /var/run/rsnapshot.pid
mkdir -m 0700 -p /.snapshots/
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot -t monthly
ERROR: Interval "monthly" unknown, check /etc/rsnapshot.conf

8. Add Crontab Entry for rsnapshot

Once you’ve verified that the rsync hourly and daily backup configurations are setup properly in the rsnapshot cwrsync utility, it is time to set this puppy up in the crontab as shown below.

# crontab -e
0 */4 * * * /usr/local/bin/rsnapshot hourly
30 23 * * * /usr/local/bin/rsnapshot daily

Check out Unix crontab examples article to understand how to setup and configure crontab.

9. Verify the rsnapshot Job Manually (One time check-up)

For the first time, you may want to execute the rsnapshot backup manually to make sure it is working as expected.

By default all the rsync backup taken by rnspashot utility will be stored under /.snapshots directory.

Since rsnapshot was never executed, this directory may not exist as shown below.

# ls -al /.snapshots/
ls: /.snapshots/: No such file or directory

Execute the rsnapshot backup utility manually for hourly configuration as shown below.

# /usr/local/bin/rsnapshot hourly

Since we’ve executed the hourly backup, rsnapshot linux backup utility would’ve created the following /.snapshots directory with the hourly.0 directory

Browse through the /.snapshots/hourly.0/ directoy to make sure the files and directories that you’ve configured in step #3 are backed up accordingly.

# ls -al /.snapshots/
total 16
drwx------  3 root root 4096 Jul 13 05:07 .s
drwxr-xr-x 25 root root 4096 Jul 13 05:07 ..
drwxr-xr-x  3 root root 4096 Jul 13 05:07 hourly.0

# ls -al /.snapshots/hourly.0/localhost/etc/
total 2516
drwxr-xr-x 93 root root   12288 Jul 13 05:05 .
drwxr-xr-x  3 root root    4096 Jul 13 05:07 ..
-rw-r--r--  1 root root   15288 Mar 13  2008 a2ps.cfg
-rw-r--r--  1 root root    2562 Mar 13  2008 a2ps-site.cfg
drwxr-xr-x  4 root root    4096 Oct 31  2008 acpi
-rw-r--r--  1 root root      44 Jan 16 10:43 adjtime
drwxr-xr-x  4 root root    4096 Jan 16 10:36 alchemist
-rw-r--r--  1 root root    2155 Mar 19 08:22 aliases
-rw-r-----  1 root smmsp  12288 Mar 19 08:22 aliases.db

In our next article, let us review how to backup multiple remote hosts using rsnapshot utility.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Mahesh August 31, 2009, 12:49 pm

    Maybe I did not see the difference, why cant all this be done with rsync?

  • Ruben September 1, 2009, 2:41 am

    Great Article except for 1 thing: You forget the all-important restore procedure!
    If someone doesn’t know (in a crash situation) how to restore, all is still lost…

  • louic September 5, 2009, 7:49 am

    I second the thoughts about restore. To have a good backup, it is even necessary to actually test if the restore works as expected.

    Personally, I use rdiff-backup. It works similarly to rsync, but keeps reverse-dependencies. The advantage (imho) is that the backup is an exact mirror of the original, and older versions are available as well.

  • Ramesh Natarajan September 10, 2009, 11:51 pm


    The advantage is that you don’t need to write any rsync commands or shell scripts to group multiple directory backups, remote backups etc. You just need to modify only the /etc/rsnapshot.conf file and rest will be handled by the rnspashot utility.

    If you’ve written lot of shell scripts to backup both local and remote hosts, you would definitely appreciate the easy configuration aspect of the rsnapshot.

    @Ruben, @Louic,

    I agree with you. I’ve added it in my to-do list to write a quick FAQ about ‘How to restore rsnapshot backup’. Thanks for bringing it to my attention.

  • Steve January 4, 2010, 6:07 am

    How about a restore from rsnapshot howto?

  • Shimmy September 9, 2010, 6:05 am

    Hi there, i am browsing the web for hours, and really cant find the answer to my questions!

    I mean is it possible that there is no text about restoring linux backup??
    I am a noob for Linux, but i like it a lot, i have problem, because i like exploring File system, and when i break something i cant change that back, and i have to reinstall my Ubuntu for about 15th time…

    I would like you to make complete newbie tutorial, for backing up and RESTORING!!! whole OS, the simplest way.

    First thing that i run in to, is the lack of information of which folders from file system should be included to backup, and which should be excluded…

    i tried to run “backintime”, gui program for backup, but when i tried to restore, my grub loader got broken on restart, lost my setting and all again…

    sorry for such a long post, but i am so tired of reinstalling my Ubuntu.

  • Redb April 3, 2012, 5:02 am

    A tutorial for restore would be welcome
    Many thanks for your job

  • Mr.What January 13, 2014, 5:30 pm

    Restore is not a reasonable thing to do with a snapshot backup, like rsnapshot. The big deal with rsnapshot is that it retains DELETED files for X weeks or months. It also has a time-history of file alterations available to do forensics.

    Excellent tutorial…

    One question… I assume we should add weekly (and monthly) lines to the crontab entries if we want hourly/daily/weekly[/monthly] snapshots…?

  • Mr.Why October 23, 2014, 3:22 pm

    Mr. What isn’t wrong but some clarification would help those stumbling across this howto.

    Suppose you setup rsnapshot to do hourly, daily, weekly and mothly snapshots. Yes, stale data would reside in the rsnapshot destination subdirectories of the eldest places… The younger the daily folder the younger the snapshot. As rsnapshot runs it cascades what is in the existing folder to be snapshotted. If one deleted a file a week and a half ago, the rsnapshot weekly folder might have the file but the dailies wouldn’t.