|45 Drives Knowledge Base
||KB450120 - Creating ZFS snapshots
You can use the zfs snapshot command to create a snapshot, which takes as its only argument the name of the snapshot that you want to create. In the example below, you are creating a snapshot of datapool/home/user that is named friday.
# zfs snapshot datapool/home/user@friday
To destroy a ZFS snapshot, use the zfs destroy command followed by the snapshot name. In the example below, you are destroying the snapshot named datapool/home/user@friday.
# zfs destroy datapool/home/user@friday
There are several things that you must keep in mind when attempting to destroy a ZFS snapshot.
You can rename a snapshot by using the zfs rename command followed by the snapshot name. In the example below, the snapshot datapool/home/user@friday resides in hrpool/home is renamed to datapool/home/user@today.
# zfs rename datapool/home/user@friday datapool/home/user@today
To recursively rename snapshots, use zfs rename –r followed by the snapshot name. In the example in the slide, only those snapshots that are named @yesterday are renamed to @2daysago.
# zfs rename -r users/home@yesterday @2daysago
You can use the zfs list -t snapshot command to display snapshots as shown in this example.
# zfs list -t snapshot NAME USED AVAIL REFER MOUNTPOINT rpool/ROOT/solaris@install 55.0M - 2.67G - rpool/ROOT/solaris/var@install 2.51M - 220M - rpool/export/home@friday 0 - 32K -
You can enable or disable the display of snapshot listings in the zfs list output by using the listsnapshots pool property. This property is disabled by default. To enable this property, use zpool set listsnapshots=on, followed by the pool name. For example :
# zpool set listsnapshots=on rpool
To list the snapshots created for a specific file system, enter zfs list -r -t snapshot followed by the file system name.
# zfs list -r -t snapshot rpool/export/home NAME USED AVAIL REFER MOUNTPOINT rpool/export/home@friday 0 - 32K - rpool/export/home/geek@2days 0 - 34K -
In the example above, the snapshots created for the file system rpool/export/home are listed. This information is displayed by using the name and creation properties.
The snapshots of file systems are accessible in the .zfs/snapshot directory within the root of the file system. For example, if rpool/export/home is mounted on /export/home, the rpool/export/home@friday snapshot data is accessible in the /export/home/.zfs/snapshot/friday directory, as shown in the example below.
# ls /export/home/.zfs/snapshot friday
You can use the zfs rollback command followed by the snapshot name to discard all the changes made since a specific snapshot. The zfs rollback command causes the file system to revert to its state at the time the snapshot was taken. In the example below, the datapool/home/user file system is rolled back to the thursday snapshot.
# zfs rollback datapool/home/user@thursday
By default, the zfs rollback 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. To do this, you must specify the -r option with the zfs rollback command followed by the snapshot name, as shown in the example below.
# zfs rollback -r datapool/home/user@tuesday
Here, the datapool/home/user file system is rolled back to the tuesday snapshot. For this operation to take place, the wednesday and thursday snapshots must be destroyed.