Snapshots are created by using the zfs snapshot or the zfs snap command, which takes as its only argument the name of the snapshot to create. The snapshot name is specified as follows:
The snapshot name must satisfy the naming requirements in ZFS Component Naming Requirements.
# zfs snapshot tank/home/cindy@friday
You can create snapshots for all descendent file systems by using the –r option. For example:
# zfs snapshot -r tank/home@snap1 # zfs list -t snapshot -r tank/home NAME USED AVAIL REFER MOUNTPOINT tank/home@snap1 0 - 2.11G - tank/home/cindy@snap1 0 - 115M - tank/home/lori@snap1 0 - 2.00G - tank/home/mark@snap1 0 - 2.00G - tank/home/tim@snap1 0 - 57.3M -
Snapshots have no modifiable properties. Nor can dataset properties be applied to a snapshot. For example:
# zfs set compression=on tank/home/cindy@friday cannot set property for 'tank/home/cindy@friday': this property can not be modified for snapshots
Snapshots are destroyed by using the zfs destroy command. For example:
# zfs destroy tank/home/cindy@friday
A dataset cannot be destroyed if snapshots of the dataset exist. For example:
# zfs destroy tank/home/cindy cannot destroy 'tank/home/cindy': filesystem has children use '-r' to destroy the following datasets: tank/home/cindy@tuesday tank/home/cindy@wednesday tank/home/cindy@thursday
For more information about the destroy subcommand, see Destroying a ZFS File System.
Different automatic snapshot or data retention policies might mean that older snapshots are inadvertently destroyed. If a removed snapshot is part of an ongoing zfs send and receive operation, then the operation might fail. To avoid this scenario, consider placing a hold on a snapshot.
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 1 whenever a hold is put on a snapshot and decreases by 1 whenever a hold is released.
In the previous Oracle Solaris release, a snapshot could only be destroyed by using the zfs destroy command if it had no clones. In this Oracle 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/cindy/snap@1:
# zfs hold keep tank/home/cindy@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/cindy@snap1 cannot destroy 'tank/home/cindy@snap1': dataset is busy
To destroy a held snapshot, use the –d option. For example:
# zfs destroy -d tank/home/cindy@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 Fri Aug 3 15:15:53 2012
# zfs holds -r tank/home@now NAME TAG TIMESTAMP tank/home/cindy@now keep Fri Aug 3 15:15:53 2012 tank/home/lori@now keep Fri Aug 3 15:15:53 2012 tank/home/mark@now keep Fri Aug 3 15:15:53 2012 tank/home/tim@now keep Fri Aug 3 15:15:53 2012 tank/home@now keep Fri Aug 3 15:15:53 2012
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.
You can rename snapshots, but they must be renamed within the same pool and dataset from which they were created. For example:
# zfs rename tank/home/cindy@snap1 tank/home/cindy@today
In addition, the following shortcut syntax is equivalent to the preceding syntax:
# zfs rename tank/home/cindy@snap1 today
The following snapshot rename operation is not supported because the target pool and file system name are different from the pool and file system where the snapshot was created:
# zfs rename tank/home/cindy@today pool/home/cindy@saturday cannot rename to 'pool/home/cindy@today': snapshots must be part of same dataset
You can recursively rename snapshots by using the zfs rename –r command. For example:
# zfs list -t snapshot -r users/home NAME USED AVAIL REFER MOUNTPOINT users/home@now 23.5K - 35.5K - users/home@yesterday 0 - 38K - users/home/lori@yesterday 0 - 2.00G - users/home/mark@yesterday 0 - 1.00G - users/home/neil@yesterday 0 - 2.00G - # zfs rename -r users/home@yesterday @2daysago # zfs list -t snapshot -r users/home NAME USED AVAIL REFER MOUNTPOINT users/home@now 23.5K - 35.5K - users/home@2daysago 0 - 38K - users/home/lori@2daysago 0 - 2.00G - users/home/mark@2daysago 0 - 1.00G - users/home/neil@2daysago 0 - 2.00G -