I'm currently snapshotting my ZFS-based NAS nightly and weekly, a process that has saved my ass a few times. However, while the creation of the snapshot is automatic (from cron), the deletion of old snapshots is still a manual task. Obviously there's a risk that if I get hit by a bus, or the manual task isn't carried out, the NAS will run out of disk space.
Does anyone have any good ways / scripts they use to manage the number of snapshots stored on their ZFS systems? Ideally, I'd like a script that iterates through all the snapshots for a given ZFS filesystem and deletes all but the last n snapshots for that filesystem.
E.g. I've got two filesystems, one called
tank and another called
sastank. Snapshots are named with the date on which they were created:
sastank@AutoD-2011-12-13 so a simple
sort command should list them in order. I'm looking to keep the last 2 week's worth of daily snapshots on
tank, but only the last two days worth of snapshots on