October 23rd, 2014


Quick tip: Figuring out which ZFS snapshot is older (of the same dataset)

Task at hand: You have two snapshots, say mypool/myfs@omgwtf and mypool/myfs@kthxbye, and you need to know which one predates the other.  A common trick is to compare their creation property, which is essentially their timestamp.

Problem: creation property isn't reliable, because system clock (from which its value is captured) may go back in time, especially when NTP “steps” system clock instead of slewing it.

Solution: ZFS does keep the snapshots fully ordered, i.e. they are sequential, and the ordering between two snapshots may be determined by dry-running incremental send:

zfs send -n -i @omgwtf mypool/myfs@kthxbye
zfs send -n -i @kthxbye mypool/myfs@omgwtf

One of these commands will succeed (zero exit code) with nothing printed out; the other will fail (nonzero exit code) saying that the incremental source (the one after -i) is newer than the target.  Take the one that succeeds: Its incremental source comes before the other.