Your Linux Data Center Experts

Last night I installed Fedora 14, since the final release is imminent… I did a full re-install, partly to clean up junk but mostly to try out btrfs. As I've mentioned before, my stress testing of btrfs has impressed me, so I decided to try it… But now that I have lightweight snapshots, I want to be creating and expiring them. So this afternoon I wrote a program I call “btrsnap”. Kind of like logrotate, it helps you keep copies and expire old ones after some period of time. Read on for more information on btrsnap and my impressions on btrfs.

I've put a tar file and RPM up at ftp://ftp.tummy.com/pub/tummy/btrsnap/, so check it out there if you want to try it. I'll probably try to get it packaged for inclusion in Fedora and Debian once I get some more experience with it and some feedback.

It's a helper that is meant to be used from cron to cause snapshots to be taken regularly, and expired after some period of time. It's kind of meant to be like the Apple “time machine” or very lightweight backups, say taken every 5 minutes… And it came in very handy already. I had my browser lose all of the tabs I had open. This happens about once or twice a month, so I started to pull the copy from last night's backup when I remembered I had a much more recent copy of my browser directory… Score!

Note that there is a down-side… If you have snapshots being kept for 2 hours, removing files probably won't result in “df” showing free space until those snapshots expire. If you fill up your disc accidentally, you'll probably have to go in and nuke your snapshots as well, to free up space.

As I said, it's a helper. It's not a daemon or anything, it's meant to be run from cron, so once you install it you will need to create cron entries, for example I put this in my “/etc/crontab”:

0 * * * * root /usr/local/sbin/btrsnap 1h 24 / /.snapshots
5-55/5 * * * * root /usr/local/sbin/btrsnap 5m 22 / /.snapshots

One runs every hour and the other runs every 5 minutes (except on the hour). The “1h” or “5m” is just a label, here I differentiate the ones I take hourly from the ones I take every 5 minutes. Then I say how many I want to keep (24 hourly ones, and 22 5-minute ones, giving me 2 hours of 5m history and a day of 1h).

I'm snapshotting “/” and saving the snapshots into “/.snapshots”. So, for example my /.snapshots currently looks like:

guin:btrsnap$ ls -1 /.snapshots
1h-20101101-170001/
1h-20101101-180001/
1h-20101101-190001/
5m-20101101-173001/
5m-20101101-173501/
[...]
5m-20101101-192001/
5m-20101101-192501/
guin:btrsnap$

As you can see, I haven't built up my maximum history for the 1h snapshots.

I don't often need backups, but I really am looking forward to having this safety net in addition to my regular backups. Probably 95% of the recoveries I have to do are pulling my browser data because it loses my tab information (I keep lots of tabs open with things I want to look at later, some of them follow me around for a month or more). Usually, yesterday's backup is good, but being able to go back 5m or 20m will be great.

So, if you're running btrfs, give btrsnap a shot and let me know what you think.

comments powered by Disqus

Join our other satisfied clients. Contact us today.