ZFS - Deleting Redundant Snapshots
I have written a cron job to automatically create snapshots of ZFS dataset on an hourly basis for critical files that benefit from active tracking.
The drawback of this is that these hourly snapshots create many redundant entries where no changes were made in the files or folders under the dataset.
I was wondering if its safe to assume that if the USEDSNAP property (usedbysnapshots) is equal to 0 then the snapshot contains no changes and can be deleted without loosing history.
Solution 1:
If the snapshots are indeed empty, why bother deleting them in the first place?
Note that you cannot assume that if the snapshot size is listed as 0 that you won't lose any data. The size of the snapshot is the amount of data you can reclaim by deleting it. If data is added, then the snapshot removal will remove nothing, and snapshot size will be listed as 0. You will have to look at zfs diff output to establish whether anything has changed.
And finally, as Michael mentioned in the comment, you should seriously look at sanoid because it sounds like you are struggling with reinventing a wheel.