Any way to tell if snapshot is from send/receive vs local snapshot?

I am developing software to monitor zfs snapshots on host and send/receive to host. On locally created snapshots, the latest snapshot might normally be taken every five minutes. On the receive end of hourly send/receive replication between nodes the latest snapshot could be an hour old, then suddenly look like we have five minute snapshots backdated through the past hour.

I have naming conventions for PRIMARY/COPY volumes on my system to apply the proper age thresholds, but I’m trying to make the check tool generic. I can read pyznap setup files, but there’s probably a half dozen different snapshot/replicate tools in use.

I’m hoping there might be something in the zfs properties of the volume or snapshot related to the origin, but I’m not seeing it. I could have the user manually add some property to the backup volumes, but I’m trying to automate as much as possible. Any suggestions are welcome.

I can’t think of anything off the top of my head. Pick any given snapshot and zfs get all pool/set@snap, then scroll slowly through the output and see if you can find a property that does what you want–that’s all the properties, so either it’s there or it isn’t. :slight_smile:

1 Like

I did pool and snapshot before posting. Nothing I recognize tells me what I want. I was hoping there was more magic behind some of these fields than a muggle could guess from reading the names. I suspect I’m off to write some heuristics.

root@nas1 [~] Red Hat Enterprise Linux 9.5 (Plow) 09:59:31 Sun Feb 09
# zfs get all ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly
NAME                                                      PROPERTY              VALUE                  SOURCE
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  type                  snapshot               -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  creation              Sun Feb  9  7:00 2025  -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  used                  0B                     -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  referenced            255G                   -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  compressratio         1.11x                  -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  devices               on                     default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  exec                  on                     default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  setuid                on                     default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  createtxg             62298053               -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  xattr                 on                     default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  version               5                      -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  utf8only              off                    -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  normalization         none                   -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  casesensitivity       sensitive              -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  nbmand                off                    default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  guid                  13560627357842945247   -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  primarycache          all                    default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  secondarycache        all                    default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  defer_destroy         off                    -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  userrefs              0                      -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  objsetid              38514                  -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  mlslabel              none                   default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  refcompressratio      1.11x                  -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  written               0                      -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  logicalreferenced     282G                   -
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  acltype               off                    default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  context               none                   default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  fscontext             none                   default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  defcontext            none                   default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  rootcontext           none                   default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  encryption            off                    default
ZRaid/COPIES/NAS0/ISOS@pyznap_2025-02-09_07:00:06_hourly  prefetch              all                    default

Try “zfs get -s received”. This will only be useful if the send stream had properties, such as when using “zfs send -R”. Also, it is only useful if you have actually set properties on the send side rather than just getting inherited properties.

box1# zfs create rpool/fs
box1# zfs set me:fromhost=box1 rpool/fs
box1# zfs snapshot rpool/fs@1
box1# zfs send --raw -R rpool/fs@1 | ssh box2 zfs recv backup/fs
box2# zfs get -s received all backup/fs
NAME       PROPERTY              VALUE                     SOURCE
backup/fs  me:fromhost           box1                      received
1 Like

I hadn’t thought of that. I don’t see any property now with a received status on the first COPY volume or snapshot I checked. I can add a property at one or both ends per your example, but at that point I should probably just check for the value of the property itself.

zfs set santa:copyflag=on ZRaid/COPIES
# zfs get santa:copyflag ZRaid/COPIES -r -t filesystem
NAME                              PROPERTY        VALUE           SOURCE
ZRaid/COPIES                      santa:copyflag  on              local
ZRaid/COPIES/KYLO                 santa:copyflag  on              inherited from ZRaid/COPIES
ZRaid/COPIES/KYLO/LIBVIRT_IMAGES  santa:copyflag  on              inherited from ZRaid/COPIES
ZRaid/COPIES/KYLO/LIBVIRT_QEMU    santa:copyflag  on              inherited from ZRaid/COPIES
ZRaid/COPIES/NAS0                 santa:copyflag  on              inherited from ZRaid/COPIES
ZRaid/COPIES/NAS0/ISOS            santa:copyflag  on              inherited from ZRaid/COPIES
...

1 Like

The flag above is redundant to the naming convention I use now, but a user is more likely to add a flag to use my tool than rework their naming conventions.