If you have different automatic snapshot policies such that older snapshots are being inadvertently destroyed by zfs receive because they no longer exist on the sending side, you might consider using the snapshots hold feature.
Holding a snapshot prevents it from being destroyed. In addition, this feature allows a snapshot with clones to be deleted pending the removal of the last clone by using the zfs destroy -d command. Each snapshot has an associated user-reference count, which is initialized to zero. This count increases by one whenever a hold is put on a snapshot and decreases by one whenever a hold is released.
In the previous Solaris release, a snapshot could only be destroyed by using the zfs destroy command if it had no clones. In this Solaris release, the snapshot must also have a zero user-reference count.
You can hold a snapshot or set of snapshots. For example, the following syntax puts a hold tag, keep, on tank/home/cindys/snap@1.
# zfs hold keep tank/home/cindys@snap1 |
You can use the -r option to recursively hold the snapshots of all descendent file systems. For example:
# zfs snapshot -r tank/home@now # zfs hold -r keep tank/home@now |
This syntax adds a single reference, keep, to the given snapshot or set of snapshots. Each snapshot has its own tag namespace and hold tags must be unique within that space. If a hold exists on a snapshot, attempts to destroy that held snapshot by using the zfs destroy command will fail. For example:
# zfs destroy tank/home/cindys@snap1 cannot destroy 'tank/home/cindys@snap1': dataset is busy |
If you want to destroy a held snapshot, use the -d option. For example:
# zfs destroy -d tank/home/cindys@snap1 |
Use the zfs holds command to display a list of held snapshots. For example:
# zfs holds tank/home@now NAME TAG TIMESTAMP tank/home@now keep Thu Jul 15 11:25:39 2010 |
# zfs holds -r tank/home@now NAME TAG TIMESTAMP tank/home/cindys@now keep Thu Jul 15 11:25:39 2010 tank/home/mark@now keep Thu Jul 15 11:25:39 2010 tank/home@now keep Thu Jul 15 11:25:39 2010 |
You can use the zfs release command to release a hold on a snapshot or set of snapshots. For example:
# zfs release -r keep tank/home@now |
If the snapshot is released, the snapshot can be destroyed by using the zfs destroy command. For example:
# zfs destroy -r tank/home@now |
Two new properties identify snapshot hold information:
The defer_destroy property is on if the snapshot has been marked for deferred destruction by using the zfs destroy -d command. Otherwise, the property is off.
The userrefs property is set to the number of holds on this snapshot, also referred to as the user-reference count.