rsnap

rsnap is a backup and snapshot utility based on rsync.

rsnap is available from as a Bazaar branch from http://web.chad.org/projects/rsnap/

To check out the most recent release, $ bzr branch http://web.chad.org/projects/rsnap/

Usage

rsnap N source[s] dest [-- rsync_options]

Where N are the number of snapshots you want to keep, source the source directories (local or remote) and dest the destination directory.

rsnap 7 user@server.com:/home/user/ ./backup/

If you have more than one source, then you probably shouldn't have slashes on the end of any.

Run this command every day and you will have backups going back a week. The backup directory will look like this:

Note that the oldest directory is 0006 and not 0007, because we started counting at 0.

If you need to pass parameters to rsync, just append them after a single "--".

rsnap 7 user@server.com:/home/user/ ./backup/ -- --exclude \*.o --bwlimit=8

Why are snapshots useful?

Consider the following situation: You have set up a cronjob with rsync to create a backup of your website to your local computer. You run this cronjob every day to make sure you're not missing anything when you modify the website on the remote server. But what happens if someone breaks into your site, modifies it and you only notice that days, maybe weeks later? Or you rewrote big chunks of your website and feel this was a mistake but you can't go back because your backup already synchronized your changes and overwrote the old version?

Thats where snapshots are useful (snapshots are sometimes also referred to as "checkpoints"). rsnap will not only save the state of your files of the last backup, but it will also retain previous states - as many as you like. This is done in an efficient way, so that only files that have changed will occupy additional space. Even better, as rsnap is a thin wrapper around rsync which adds snapshot rotating and creation, the changes you need to make to your existing backup script are minimal.

If you are a developer, you might think of tools like CVS to be the answer to the problem mentioned above. Now while these tools are more powerful, they require you to learn a special syntax and they are generally more difficult to use. rsnap provides an ad-hoc, general-purpose, zero-headache backup and snapshotting tool which is extremely easy to use. Want to restore a backup from two days ago? Just copy it from the subfolder to your current folder using "cp". Want to see the differences between to snapshots? Just run a "diff" over these directories.

When to use rsnap and when not

rsnap is useful if you have lots of small files which change infrequently, like a website or maybe even source code. It is useful for Maildirs too, but rsnap won't recognize, if a file has moved from new/ to cur/, so sometimes you will be wasting space (ideas on how to optimize this behaviour are welcome).

If you have lots of big files that all change frequently, don't use rsnap. For example you have lots of images or word files you are editing. Or you are using mbox files. Every time the file changes (or even if only the file's permissions change (this information is stored in the inode)), rsnap will create a new copy of it. In such cases, you might consider using rdiff-backup, which creates efficient binary deltas.

Do not use rsnap to create backups of your MySQL data directory. MySQL data files tend to change frequently which leaves you with inconsistent (=unusable) files. This is a limitation of rsync itself, not rsnap. Use mysqldump instead.

The idea behind rsnap came from an article by Mike Rubel, which can be found at:

http://www.mikerubel.org/computers/rsync_snapshots/

The result of this article were probably thousands of tools, including this one, which none of them I liked (see section "Similar tools").

The basic idea of creating snapshots using rsync is to use hardlinks. rsync can do this automatically with the --link-dest option. For more details, read the article :)

Requirements

Installation

$ ./setup.py install --prefix=/usr/local

Similar tools

Tools that provide snapshots, but are not related to rsync:

Tools based around the documentation of Mike Rubel, using all rsync: