Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
By jeremy at 2007-07-30 12:58
Backups 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 Amanda.)
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...
... 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.