A snapshot is a read-only copy of a file system or volume. Snapshots can be created almost instantly, and they initially consume no additional disk space within the pool. However, as data within the active dataset changes, the snapshot consumes disk space by continuing to reference the old data, thus preventing the disk space from being freed.
A clone is a writable volume or file system whose initial contents are the same as the dataset from which it was created. Clones can be created only from a snapshot.
ZFS snapshots include the following features:
They persist across system reboots.
The theoretical maximum number of snapshots is 264.
Snapshots use no separate backing store. Snapshots consume disk space directly from the same storage pool as the file system or volume from which they were created.
Recursive snapshots are created quickly as one atomic operation. The snapshots are created together (all at once) or not created at all. The benefit of atomic snapshot operations is that the snapshot data is always taken at one consistent time, even across descendant file systems.
Snapshots of volumes cannot be accessed directly, but they can be cloned, backed up, rolled back to, and so on. For information about backing up a ZFS snapshot, see Saving, Sending, and Receiving ZFS Data.
This section covers the following topics:
You create snapshots 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 uses one of the following conventions:
filesystem@snapname
volume@snapname
The snapshot name must satisfy the naming requirements in Naming ZFS Components.
The following example creates a snapshot of system1/home/cindy that is named friday.
# zfs snapshot system1/home/cindy@friday
To create snapshots for all descendant file systems, use the –r option. For example:
# zfs snapshot -r system1/home@snap1 # zfs list -t snapshot -r system1/home NAME USED AVAIL REFER MOUNTPOINT system1/home@snap1 0 - 2.11G - system1/home/cindy@snap1 0 - 115M - system1/home/lori@snap1 0 - 2.00G - system1/home/mark@snap1 0 - 2.00G - system1/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 system1/home/cindy@friday cannot set property for 'system1/home/cindy@friday': this property can not be modified for snapshots
To destroy snapshots, use the zfs destroy command. For example:
# zfs destroy system1/home/cindy@friday
You cannot destroy a dataset if snapshots of the dataset exist. For example:
# zfs destroy system1/home/cindy cannot destroy 'system1/home/cindy': filesystem has children use '-r' to destroy the following datasets: system1/home/cindy@tuesday system1/home/cindy@wednesday system1/home/cindy@thursday
In addition, if clones have been created from a snapshot, then you must destroy them before you can destroy the snapshot.
For more information about the destroy subcommand, see How to Destroy a ZFS File System.
Older snapshots are sometimes inadvertently destroyed due to different automatic snapshot or data retention policies. 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, you could destroy a snapshot only 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 system1/home/cindy/snap@1:
# zfs hold keep system1/home/cindy@snap1
To recursively hold the snapshots of all descendant file systems, use the –r option. For example:
# zfs snapshot -r system1/home@now # zfs hold -r keep system1/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 system1/home/cindy@snap1 cannot destroy 'system1/home/cindy@snap1': dataset is busy
To destroy a held snapshot, use the –d option. For example:
# zfs destroy -d system1/home/cindy@snap1
To display a list of held snapshots, use the zfs holds command. For example:
# zfs holds system1/home@now NAME TAG TIMESTAMP system1/home@now keep Fri Aug 3 15:15:53 2012
# zfs holds -r system1/home@now NAME TAG TIMESTAMP system1/home/cindy@now keep Fri Aug 3 15:15:53 2012 system1/home/lori@now keep Fri Aug 3 15:15:53 2012 system1/home/mark@now keep Fri Aug 3 15:15:53 2012 system1/home/tim@now keep Fri Aug 3 15:15:53 2012 system1/home@now keep Fri Aug 3 15:15:53 2012
To release a hold on a snapshot or set of snapshots, use the zfs release command. For example:
# zfs release -r keep system1/home@now
If the snapshot is released, the snapshot can be destroyed by using the zfs destroy command. For example:
# zfs destroy -r system1/home@now
Two properties identify snapshot hold information.
The defer_destroy property is set to on if the snapshot has been marked for deferred destruction by using the zfs destroy –d command. Otherwise, the property is set to off.
The userrefs property is set to the number of holds on this snapshot.
You can rename snapshots, but only within the same pool and dataset from which they were created. For example:
# zfs rename system1/home/cindy@snap1 system1/home/cindy@today
You can also use the following shortcut syntax:
# zfs rename system1/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 system1/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 -
By default, snapshots no longer appear in the zfs list output. You must use the zfs list –t snapshot command to display snapshot information. You can also enable the listsnapshots pool property instead. For example:
# zpool get listsnapshots system1 NAME PROPERTY VALUE SOURCE system1 listsnapshots off default # zpool set listsnapshots=on system1 # zpool get listsnapshots system1 NAME PROPERTY VALUE SOURCE system1 listsnapshots on local
Snapshots of file systems are placed in the .zfs/snapshot directory within the root of the file system. For example, if system1/home/cindy is mounted on /home/cindy, then the system1/home/cindy@thursday snapshot data is accessible in the /home/cindy/.zfs/snapshot/thursday directory.
# ls /system1/home/cindy/.zfs/snapshot thursday tuesday wednesday
The following examples shows how to list snapshots.
# zfs list -t snapshot -r system1/home NAME USED AVAIL REFER MOUNTPOINT system1/home/cindy@tuesday 45K - 2.11G - system1/home/cindy@wednesday 45K - 2.11G - system1/home/cindy@thursday 0 - 2.17G -
The following example shows how to list snapshots that were created for a particular file system.
# zfs list -r -t snapshot -o name,creation system1/home NAME CREATION system1/home/cindy@tuesday Fri Aug 3 15:18 2012 system1/home/cindy@wednesday Fri Aug 3 15:19 2012 system1/home/cindy@thursday Fri Aug 3 15:19 2012 system1/home/lori@today Fri Aug 3 15:24 2012 system1/home/mark@today Fri Aug 3 15:24 2012
When you create a snapshot, its disk space is initially shared between the snapshot and the file system, and possibly with previous snapshots. As the file system changes, disk space that was previously shared becomes unique to the snapshot, and thus is counted in the snapshot's used property. Additionally, deleting snapshots can increase the amount of disk space unique to (and thus used by) other snapshots.
A snapshot's space referenced property value is the same as the file system's value was when the snapshot was created.
You can identify additional information about how the values of the used property are consumed. New read-only file system properties describe disk space usage for clones, file systems, and volumes. For example:
$ zfs list -o space -r rpool NAME AVAIL USED USEDSNAP USEDDS USEDREFRESERV USEDCHILD rpool 124G 9.57G 0 302K 0 9.57G rpool/ROOT 124G 3.38G 0 31K 0 3.38G rpool/ROOT/solaris 124G 20.5K 0 0 0 20.5K rpool/ROOT/solaris/var 124G 20.5K 0 20.5K 0 0 rpool/ROOT/solaris-1 124G 3.38G 66.3M 3.14G 0 184M rpool/ROOT/solaris-1/var 124G 184M 49.9M 134M 0 0 rpool/VARSHARE 124G 39.5K 0 39.5K 0 0 rpool/dump 124G 4.12G 0 4.00G 129M 0 rpool/export 124G 63K 0 32K 0 31K rpool/export/home 124G 31K 0 31K 0 0 rpool/swap 124G 2.06G 0 2.00G 64.7M 0
For a description of these properties, see the used properties in the zfs(1M) man page.
You can to discard all changes made to a file system since a specific snapshot was created by using the zfs rollback command. The file system reverts to its state at the time the snapshot was taken. By default, the command cannot roll back to a snapshot other than the most recent snapshot.
To roll back to an earlier snapshot, you must destroy all intermediate snapshots by specifying the –r option.
If clones of any intermediate snapshots exist, use the –R option to destroy the clones as well.
In the following example, the system1/home/cindy file system is rolled back to the tuesday snapshot.
# zfs rollback system1/home/cindy@tuesday cannot rollback to 'system1/home/cindy@tuesday': more recent snapshots exist use '-r' to force deletion of the following snapshots: system1/home/cindy@wednesday system1/home/cindy@thursday # zfs rollback -r system1/home/cindy@tuesday
In the following example, the wednesday and thursday snapshots are destroyed because the file system is rolled back to the earlier tuesday snapshot.
# zfs list -r -t snapshot -o name,creation system1/home/cindy NAME CREATION system1/home/cindy@tuesday Fri Aug 3 15:18 2012
You can determine ZFS snapshot differences by using the zfs diff command.
For example, assume that the following two snapshots are created:
$ ls /system1/home/tim fileA $ zfs snapshot system1/home/tim@snap1 $ ls /system1/home/tim fileA fileB $ zfs snapshot system1/home/tim@snap2
To identify the differences between the two snapshots, you would use syntax similar to the following example:
$ zfs diff system1/home/tim@snap1 system1/home/tim@snap2 M /system1/home/tim/ + /system1/home/tim/fileB
In the output, the M indicates that the directory has been modified. The + indicates that fileB exists in the later snapshot.
The R in the following output indicates that a file in a snapshot has been renamed.
$ mv /system1/cindy/fileB /system1/cindy/fileC $ zfs snapshot system1/cindy@snap2 $ zfs diff system1/cindy@snap1 system1/cindy@snap2 M /system1/cindy/ R /system1/cindy/fileB -> /system1/cindy/fileC
The following table summarizes the file or directory changes that are identified by the zfs diff command.
|
For more information, see the zfs(1M) man page.
If you compare different snapshots by using thezfs diff command, the high level differences are displayed such as a new file system or directory. For example, the sales file system has 2 descendant file systems, data and logs with files within each descendant file system.
# zfs list -r sales NAME USED AVAIL REFER MOUNTPOINT sales 1.75M 66.9G 33K /sales sales/data 806K 66.9G 806K /sales/data sales/logs 806K 66.9G 806K /sales/logs
The high-level differences can be displayed between sales@snap1 and sales@snap2, where the primary difference is addition of the sales/logs file system.
# zfs diff sales@snap1 sales@snap2 M /sales/ + /sales/logs
You can recursively identify snapshot differences including file names by using syntax similar to the following:
# zfs diff -r -E sales@snap1 D /sales/ (sales) + /sales/data D /sales/data/ (sales/data) + /sales/data/dfile.1 + /sales/data/dfile.2 + /sales/data/dfile.3 # zfs diff -r -E sales@snap2 D /sales/ (sales) + /sales/data + /sales/logs D /sales/logs/ (sales/logs) + /sales/logs/lfile.1 + /sales/logs/lfile.2 + /sales/logs/lfile.3 D /sales/data/ (sales/data) + /sales/data/dfile.1 + /sales/data/dfile.2 + /sales/data/dfile.3
In the output, the lines that begin with D and end with (name) indicate a file system (dataset) and mount point.