Published by nick on 20 Jun 2008 at 04:06 pm
Howto - Simple backups for Linux using rsnapshot
Backups are something you must master to be a great system administrator.
You’e probably found this because you were looking for a simple backup solution. Yes, you’ve seen Amanda. And Bacula, but they aren’t simple. Amanda and Bacula are great products if you need all of their features — and if you are like me, I don’t want to spend time with my backups, I just want something that works.
My choice — rsnapshot. rsnapshot is a perl script that wraps around rsync. It’s most beautiful feature: it uses hard-links when it can, so if you are backing up the same file more than once, it just creates a link. This means backups only take up more space if the files change. I’ve heard that this is how Apple’s Time Machine works. I’m now using rsnapshot in multiple production environments. Here’s a quick how-to guide for how to set up reliable, robust, efficient, self-rotating backups in just a few minutes with rsnapshot.
- Install rsnapshot, either by downloading/compiling the source code, or using this RPM for linux
- Edit
/etc/rsnapshot.conffor your settings. Warning: The config file makes a distinction between tabs and spaces. Make sure you use tabs! Pay special attention to these settings:snapshot_root— this is where your backups will be stored.- The
backupsection will define which directories you want backed up.
backup /etc/ localhost/
backup /root/ localhost/
backup /home/ localhost/
- rsnapshot handles the rotation of backups for you! The
intervalsection will define how many daily, weekly, etc. backups are kept. Example:
interval hourly 6
interval daily 7
interval weekly 4
interval monthly 3
- As a test, you can run:
rsnapshot -v -t hourlyand this will parse the config file, and show you the commands it will run when it runs hourly. - After you are done tweaking the config file, it’s time to add the crontab entries for the various backups. Scheduling is a bit tricky. Here’s mine as an example:
# There is a pid file that will preven two from running at the same time.
# This is why hourly starts after the others. Hourly should be skipped when daily/weekly/monthly is running.
19 */3 * * * nice rsnapshot -v hourly
18 1 * * * rsnapshot -v daily
17 2 * * 0 rsnapshot -v weekly
16 3 1 * * rsnapshot -v monthly
That’s it! You’re ready to go. Your backups will be stored in rsnapshot_root.