Rsnapshot is a Perl script that uses rsync to create incremental backups. You can download it from http://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:
*/not_this
not_this
not_this/
home/not_this
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:
./not_this: ASCII text.
./homes/not_this: directory
./homes/this/not_this: directory
./not_this: ASCII text
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.
Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

| Views for this page | ||||
|---|---|---|---|---|
| Today | This Week | This Month | This Year | Overall |
| 7 | 9 | 65 | 1,738 | 6,161 |
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
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. We appreciate comments and article submissions.

Fri Feb 18 21:16:27 2005: Subject: test anonymous
test
Tue Aug 12 14:19:59 2008: Subject: just what i was looking for wilson
Thanks
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.
Add your comments