Even a rudimentary repository system is better than none. Learn how to create local and remote filesystem snapshots with rsnapshot.
The December 2004 “Tech Support” column, “Quick and Dirty Backups,” combined tar and rsync to make light work of backup regimens. The notion was that an easy to implement backup solution would encourage you to perform backups and archive more often. To this day, however, most home and small-business users still ignore backups- and do so at great risk.
Even a rudimentary repository system is better than none, so let’s look at another simple solution based on rsync. (A future “Tech Support” column will cover a more robust, scalable, and open source solution, such as Zmanda.)
rsnapshot is a Perl- based utility for saving snapshots of local and remote filesystems. It uses rsync and hard links to create multiple, full filesystem backups, yet only requires slightly more disk space than a single snapshot plus incremental archives. rsnapshot is licensed under the GNU Public License (GPL) and is hosted at http://www.rsnapshot.org/.
rsnapshot is simple to configure and can allow an end-user to restore his or her files without administrator intervention. Further, rsnapshot can keep an arbitrary number of hourly, daily, weekly, and monthly backups for any number of hosts. Pair rsnapshot with ssh to securely backup any remote machine in the same manner as a local machine would be backed up. You also can run scripts both before and after backup, which is handy for preparation, such as dumping a database to the filesystem for subsequent archival.
After you’ve download and unpacked the rsnapshot tarball, run the familiar ./configure command:
$ ./configure --sysconfdir=/etc
From there, simply run make install, short circuiting the normal make procedure, to install the resultant binary as /usr/local/bin/rsnapshot.
Next, create the configuration file. It’s easiest to copy the included rsnapshot.conf.default to /etc/rsnapshot.conf and use it as a foundation. (As backup needs vary greatly, configuration is beyond the scope of this article, but the configuration file provided as a sample is very well documented.) One facet you should give considerable thought to is backup intervals. This setting controls how often snapshots are taken and how long each is kept for archive.
Now decide what filesystems you want to snapshot. This is done using the parameter named backup. This parameter has two arguments: the directory or network path you’d like to backup, and the path, relative to snapshot_root, where the snapshot will be stored. For example, to backup the local /home directory, you might write:
backup /home/ localhost/
Backing up remote systems is almost as easy as local ones:
backup email@example.com:/home/ foo.com/
Keep in mind that if you want this to work automatically, you must configure ssh key-based logins.
In addition to the backup parameter, you can use backup_script to run an arbitrary script as part of your backup regimen. This is extremely powerful, and can be used to dump remote databases, send notification messages, restart processes, or anything else you may need to do in your particular environment.
Once you’re done editing the configuration file, run rsnapshot configtest to ensure you don’t have any syntax errors. Next, run a test snapshot with rsnapshot –t interval, where interval is one of hourly, daily, weekly, or monthly and is configured lowest in your interval options (hourly by default). The -t option shows the work rsnapshot plans to perform, but doesn’t create any backups.
After you’ve verified all of your settings, add the appropriate settings to root’s crontab. For example, you might add…
0 */4 * * * /usr/local/bin/rsnapshot hourly
30 23 * * * /usr/local/bin/rsnapshot daily
… to perform an hourly and daily backup, respectively, adhering to the rotation policy you’ve specified. You should now have rsnapshot configured to do automated multiple versioned backups. To restore, simply copy the files you need out of the appropriate snapshot directory.
rsnapshot has many advanced features, too. The manual walks you though secure NFS- mounted multiple user restores, filename filters, and removable media.
For many simple setups, rsnapshot is all you need to maintain a reliable backup solution. Keep in mind, though, that rsnapshot is a disk-based backup solution. While there are no tapes to change, it does have drawbacks, especially in some long-term archival situations.
Whatever route you choose, make sure you have some regular backup regimen in place. Also, don’t forget to test a restore before it’s critical to use it. A word to the wise: If you’re running a business, seriously evaluate your backup paradigm and ensure what you’re doing meets your actual needs.