In my experiments with FreeNAS and ZFS I came across a need to obtain the name of the latest snapshot of a given dataset. For some odd reason this information is not readily available (that I could find, anyway.) After much googling I finally constructed an answer to my own question, “How do I get the name of the latest ZFS snapshot?”
The answer is via the zfs list command, using the -t, -o, and -r options, and then piping the output to tail to grab the last result.
zfs list -t snapshot -o name -s creation -r storage/Documents | tail -1
- -t type of ZFS item you want information for
- -o list of properties of the type above you want to return
- -s sort by
- -r specific volume
- -1 (from tail): only return one line (the last one)
The example above returns the name of the latest snapshot taken from my Documents dataset, which is on my storage volume.