A while ago, I started doing ZFS backups of some of my remote servers. That is daily rsyncs to a ZFS fs followed by a snapshot creation for that day. After collecting these snapshots for a while, I decided it was time to do some housekeeping and attempted to find a script that would fit my need of keeping everything tidy. In short, I found a few but none were doing things quite the way that I wanted. So I wrote my own in typical sysadmin fashion.
The above link is the script. It may fit your needs. Basically, I wanted to keep X number of daily snapshots, Y number of weekly snapshots and Z number of monthly snapshots. I even through in another slot for yearly backups, just in case. It will evaluate all your snapshots for configured (at the top of the script) filesystems and determine which ones should be kept and which ones should be destroyed. I could've gone ahead and gotten a bit more granular by going down to hourly but that's not how I'm keeping my snapshots now since once-a-day backups are good enough for me. All this script requires you to do is name your snapshots in the YYYYMMDD format, then configure which filesystems to prune and how many of each kind you want to keep.
As with any destructive script, use caution when running it. Running the script with no arguments will generate the help message and give you the possible switches. I highly suggest doing a dry run (-n) to be safe and verbose (-v) to understand what the script is doing, but you will be prompted before snapshot destruction if you run with no arguments. Filesystems and how many snapshots to keep are configured at the top of the script. I may throw in command-line options for that in the future.
Enjoy. Let me know if it works out for you.
UPDATE: darn, posted too soon. Still don't have it quite right. I'll keep working on it.
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
No feedback yet
Leave a comment
