Freebsd – Can a user-defined “destroy-after” property be set on a ZFS snapshot

freebsdsnapshotzfs

I know that (almost) arbitrary user-created properties can be added to a ZFS dataset on FreeBSD. But if I take snapshots of a dataset (or pool), can I set a user-defined property on an individual snapshot?

Use-case: I want to tag snapshots with some arbitrary value when they are created, and it would be easiest to have this as a snapshot property because then it's not separable from (and replicates with) the snapshot it refers to. An example of such a field might be "Created by", "Destroy date" or "Reason for snapshot".

I know I can prepend this into the snapshot's name but that gets clumsy if there are multiple properties. Is there a way to create a property for the snapshot?

If there isn't, what is the most elegant way to associate such data with snapshots, and to automatically destroy snapshots as they expire, if running an "aging scheme" for snapshot lifetimes (such as "1/4 hourly for 12 hours, hourly for 48 hours, then daily for 2 weeks and weekly kept for 2 years")

Best Answer

Yes, you can.

# mark snapshot to destroy after 1 hour (3600 seconds)
zfs set :destroy-after=3600 tank@mysnap

# result of get operation will be just the value 3600
zfs get -Hpo value :destroy-after tank@mysnap