ZFS Snapshot Utlity

ZFS Snapshots

Perhaps the best feature of the ZFS file system is low cost snapshots. You don't have to allocate space for them ahead of time(like Linux LVM snapshots) and they can be cloned, deleted, mounted and in other ways managed. Making ZFS snapshots was probably the main reason for me putting together a Solaris 11 NAS.

Auto snapshots

I don't want to have to create snapshots manually all the time so I thought I would create a script similar to that used on FreeNAS. That is presented here.


This class is simply a structure for data about filesets. For instance I have a fileset "raidpool/Documents" for which I generate snapshots hourly, daily, weekly and monthly. A fileset object only contains information of the path and whether or not snapshots are enabled for those four frequencies. Note that a fileset path doesn't start with a slash.


This class contains a representation of a snapshot that has been made at some earlier point in time. It contains the path of the fileset(like /raidpool/Documents), the time of the snapshot being made(a datetime object) and the lifetime(a timedelta object). It also contains a function is_expired(time) which returns "true" if the snapshot in question is expired relative to the argument "time". Otherwise it returns "false".


This file contains the majority of the code. It has a class Snapshot_handler which contains configuration and fileset information along with the functions that actually creates snapshots and destroys them. One starts the program like this: python snapshots.py [ cleanup | hourly | daily | weekly | monthly ].

"cleanup" locates snapshots created with this program and destroys those that have expired. The other arguments simply creates snapshots for all datasets with the corresponding frequency set in a configuration file presented below.


This file contains data on the format:
raidpool/Documents | hourly daily weekly monthly
raidpool/Netstore | daily weekly monthly
raidpool/Software | weekly monthly

The data is turned into Snapshot objects as described above.


This file contains data on the format:
hourly 48h
daily 14d
weekly 4w
monthly 6m

These instructions are simply placed at the far end of the snapshot's name so that the cleanup-function can find and destroy old snapshots.