4

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")

4

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
  • Am I right that this doesn't automate the snapshot destruction, it just sets a flag and date that I would periodically check with cron and decide via a script whether to destroy it yet? If so, can I set an arbitrary text value as well, using the same syntax? – Stilez Oct 9 '17 at 12:26
  • 1
    @Stilez Yes, this just adds a property and value to an existing snapshot (first part of your question), which you can use (or ignore). Yes, text is possible (use double quotes if the value contains spaces). Cron would be a possibility, yes. If you just want to destroy after a fixed time, you could encode the "death date" and just compare it with the current date - otherwise you would need creation date and lifetime, for example if this should be reconfigured later on. But yes, you are on your own here. – user121391 Oct 9 '17 at 14:55
  • That's fine, thank you for the valuable help! – Stilez Oct 9 '17 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.