APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Using Rsnapshot

© February 2005 Tony Lawrence
February 2005

Rsnapshot is a Perl script that uses rsync to create incremental backups. You can download it from https://www.rsnapshot.org/.

The first thing to decide is where you will keep your backups. By default, the configuration file points them at /.snapshots. Although the script is smart enough to avoid containing its own directory in backups (because it would lead to recursion), I'd still rather have this directory somewhere off the backup set if possible. In my case, I use this for backup of a remote webserver, so /.snapshots is fine. This, and everything else, is set in the configuration file (/etc/rsnapshot.conf by default). All elements have to be tab separated.

If backup is to mounted media, you may also want to set no_create_root:

snapshot_root	/mnt/.snapshots/
no_create_root	1

By not allowing rsnapshot to create the snapshoot_root directory, it will then fail if media is not mounted (you would have to create the .snapshots directory on the media manually).

The next step is to specify what will be backed up and how. You'll need to uncomment ssh if backing up from a remote site:

cmd_ssh	/usr/bin/ssh

Next, you specify intervals:

interval	daily	3
interval	weekly	2
interval	monthly	2

That's actually bad terminology: these are really labels for backup sets, and will end up as directories under your snapshot_root directory. The labels themselves control nothing; you need a cron job to run rsnapshot, or you need to run it manually. When you run it, you''ll be telling it what interval you are using:

rsnapshot daily

Just realize that the "daily" label really has no meaning unless you run "rsnapshot daily" on a daily basis. If you ran it hourly, rsnapshot would still use the "daily" label - it's just a label for your convenience. You could call it "fred" for all rsnapshot cares.

The "3" in "interval daily 3" means that we'll end up with three directories - daily.0, daily.1, daily.2. The daily.0 will always be the most current set. So, if you begin by running "rsnapshot daily", that will create /.snapshots/daily.0 and backup to there. If you run the same command ten minutes later, you'll have daily.0 and daily.1, and daily.0 will have the most current set. At that point, daily.1 will have what was in the daily.0 set. Run it once more, and you'll add daily.2, which of course will have what daily.0 originally had at the beginning.

The files in the directories are hard links if nothing has changed. So, if you were backing up /usr/fred, and no files had changed, the files in daily.0 and daily.1 would just be links to the files in daily.2 and wouldn't consume any disk space beyond their directory slots. This is a simple scheme, but it works well. the disk space used for multiple sets might only be a little more that one backup set. That's especially apt to be so if the thing being backed up has a lot of small files rather than a few very large files - so it's probably better for a web server than a big database app.

However, if your data does lend itself to this, it makes it very easy to go back in time exactly where you want to be without any guesswork. An interesting side effect is that you can tell whether or not a file has changed simply by examining the number of links in an ls -l listing.

Of course we haven't yet specified what we're backing up. That comes a bit later in the configuration file, but before that we get to specify include and exclude options. These are passed directly to rsync, and can be a little confusing, so I'll cover that in more depth later. For the moment, let's just tell rsnapshot that we have an excludes file:<./p>

exclude_file	/Users/apl/bin/excludes

Next are the things to backup (I have skipped over settings that should be obvious or are well explained in the file itself). You can specify multiple lines, each with a source, a tab, and the directory under your interval directories to store it under. For example, you might have:

backup	foo@foobar.com:/usr/local/www/vhosts/		mywebsite/
backup	ralph@othersite.com:/usr/ralph		ralph/
backup	/home/		localhomedirs/

You can also specify a backup script. This might be used for dumping databases, running lynx -dump, etc. It needs to create files which rsnapshot then backs up.

All of this is easy enough, but we often want to exclude files, and that can be a little confusing. Let's look at an example exclude file:


These are all slightly different ways of excluding, and each will have slightly different meaning as to what actually will be excluded. I tested this on a directory containing these files and directories:

$ find testrsnap -name not_this -exec file {} \;
testrsnap/home/not_this: directory
testrsnap/home/not_this/home/b/not_this: empty
testrsnap/homes/not_this: directory
testrsnap/homes/this/not_this: directory
testrsnap/not_this: ASCII text

The config has:

backup	/Users/tony/testrsnap	mydocs

The first backup was done with nothing in the excludes file. The results of a find in the snap directory are (as expected) no different from the source files:

$ cd ~/snapshots/daily.0/mydocs/Users/apl/testrsnap 
$ find . -name not_this -exec file {} \;
./home/not_this: directory
./home/not_this/home/b/not_this: empty
./homes/not_this: directory
./homes/this/not_this: directory
./not_this: ASCII text

I then tested with each exclude parameter. The results were:

If this doesn't make sense immediately, experiment with a small set of files until you see how it works. I've found the excludes confusing, which may be because of how rsync looks at --exclude. Rsnapshot provides easily understood incremental backups.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Using Rsnapshot


Inexpensive and informative Apple related e-books:

Take Control of Pages

Take Control of Apple Mail, Third Edition

Are Your Bits Flipped?

iOS 10: A Take Control Crash Course

Take Control of iCloud

More Articles by © Tony Lawrence

Fri Feb 18 21:16:27 2005: 39   anonymous


Tue Aug 12 14:19:59 2008: 4484   wilson

I was looking for a quick clear explanation about excludes and this is it!
Also, the comments about the hourly, daily labels was informative too. I was a little confused about that.

Sat Jul 11 07:28:55 2009: 6630   LargerMon

Thanks for the tip!

Tue Nov 3 18:50:06 2009: 7421   BrianStPierre

Thanks for this tutorial.

A warning on excludes: if you specify exclude rules as rules in the conf file (and not externally), do not put quotation marks around the pattern. Rsnapshot will pass the quotation marks to rsync and it will treat them as part of the pattern.

Tue Nov 3 21:55:24 2009: 7422   TonyLawrence

Thanks! I probably will forget that by the time I have need to use a question mark, but I'll only have myself to blame :-)

Mon Feb 14 01:46:55 2011: 9310   OscarGonzalez


This is a great writeup about rsnapshot. Very clear and much more relatable than the man page.


Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

Software and cathedrals are much the same – first we build them, then we pray. (Sam Redwine)

Linux posts

Troubleshooting posts

This post tagged:



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode