Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Solaris ZFS Administration Guide
Previous Next

Overview of ZFS Snapshots

A snapshot is a read-only copy of a file system or volume. Snapshots can be created almost instantly, and 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 and so prevents the space from being freed.

ZFS snapshots include the following features:

  • Persist across system reboots.

  • The theoretical maximum number of snapshots is 264.

  • Use no separate backing store. Snapshots consume disk space directly from the same storage pool as the file system 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 snapshots operations is that the snapshot data is always taken at one consistent time, even across descendent 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 and Restoring ZFS Data.

Creating and Destroying ZFS Snapshots

Snapshots are created by using the zfs snapshot command, which takes as its only argument the name of the snapshot to create. The snapshot name is specified as follows:

[email protected]
[email protected]

The snapshot name must satisfy the naming conventions defined in ZFS Component Naming Requirements.

In the following example, a snapshot of tank/home/ahrens that is named friday is created.

# zfs snapshot tank/home/[email protected]

You can create snapshots for all descendent file systems by using the -r option. For example:

# zfs snapshot -r tank/[email protected]
# zfs list -t snapshot
NAME                   USED  AVAIL  REFER  MOUNTPOINT
tank/[email protected]             0      -  29.5K  -
tank/home/[email protected]      0      -  2.15M  -
tank/home/[email protected]        0      -  1.89M  -
tank/home/[email protected]         0      -  1.89M  -
tank/home/[email protected]      0      -  2.15M  -

Snapshots have no modifiable properties. Nor can dataset properties be applied to a snapshot.

# zfs set compression=on tank/home/[email protected]
cannot set compression property for 'tank/home/[email protected]': snapshot
properties cannot be modified

Snapshots are destroyed by using the zfs destroy command. For example:

# zfs destroy tank/home/[email protected]

A dataset cannot be destroyed if snapshots of the dataset exist. For example:

# zfs destroy tank/home/ahrens
cannot destroy 'tank/home/ahrens': filesystem has children
use '-r' to destroy the following datasets:
tank/home/[email protected]
tank/home/[email protected]
tank/home/[email protected]

In addition, if clones have been created from a snapshot, then they must be destroyed before the snapshot can be destroyed.

For more information about the destroy subcommand, see Destroying a ZFS File System.

Renaming ZFS Snapshots

You can rename snapshots but they must be renamed within the pool and dataset from which they were created. For example:

# zfs rename tank/home/[email protected] tank/home/[email protected]

In addition, the following shortcut syntax provides equivalent snapshot renaming syntax as the example above.

# zfs rename tank/home/[email protected] 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/[email protected] pool/home/[email protected]
cannot rename to 'pool/home/[email protected]': snapshots must be part of same 
dataset

You can recursively rename snapshots with the zfs rename -r command. For example:

# zfs list
NAME                         USED  AVAIL  REFER  MOUNTPOINT
users                        270K  16.5G    22K  /users
users/home                    76K  16.5G    22K  /users/home
users/[email protected]            0      -    22K  -
users/home/markm              18K  16.5G    18K  /users/home/markm
users/home/[email protected]      0      -    18K  -
users/home/marks              18K  16.5G    18K  /users/home/marks
users/home/[email protected]      0      -    18K  -
users/home/neil               18K  16.5G    18K  /users/home/neil
users/home/[email protected]       0      -    18K  -
# zfs rename -r users/[email protected] @2daysago
# zfs list -r users/home
NAME                        USED  AVAIL  REFER  MOUNTPOINT
users/home                   76K  16.5G    22K  /users/home
users/[email protected]            0      -    22K  -
users/home/markm             18K  16.5G    18K  /users/home/markm
users/home/[email protected]      0      -    18K  -
users/home/marks             18K  16.5G    18K  /users/home/marks
users/home/[email protected]      0      -    18K  -
users/home/neil              18K  16.5G    18K  /users/home/neil
users/home/[email protected]       0      -    18K  -

Displaying and Accessing ZFS Snapshots

Snapshots of file systems are accessible in the .zfs/snapshot directory within the root of the containing file system. For example, if tank/home/ahrens is mounted on /home/ahrens, then the tank/home/[email protected] snapshot data is accessible in the /home/ahrens/.zfs/snapshot/thursday directory.

# ls /tank/home/ahrens/.zfs/snapshot
tuesday wednesday thursday

You can list snapshots as follows:

# zfs list -t snapshot
NAME                        USED  AVAIL  REFER  MOUNTPOINT
pool/home/[email protected]          0      -   780K  -
pool/home/[email protected]           0      -  1.01M  -
tank/home/[email protected]   8.50K      -   780K  -
tank/home/[email protected] 8.50K      -  1.01M  -
tank/home/[email protected]      0      -  1.77M  -
tank/home/[email protected]     8.50K      -   524K  -

You can list snapshots that were created for a particular file system as follows:

# zfs list -r -t snapshot -o name,creation tank/home
NAME                       CREATION
tank/[email protected]               Wed Aug 30 10:53 2006
tank/home/[email protected]    Wed Aug 30 10:53 2006
tank/home/[email protected]  Wed Aug 30 10:54 2006
tank/home/[email protected]   Wed Aug 30 10:53 2006
tank/home/[email protected]        Wed Aug 30 10:57 2006
Snapshot Space Accounting

When a snapshot is created, its space is initially shared between the snapshot and the file system, and possibly with previous snapshots. As the file system changes, 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 space unique to (and thus used by) other snapshots.

A snapshot's space referenced property is the same as the file system's was when the snapshot was created.

Rolling Back to a ZFS Snapshot

The zfs rollback command can be used to discard all changes made since a specific snapshot. 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, all intermediate snapshots must be destroyed. You can destroy earlier snapshots by specifying the -r option.

If clones of any intermediate snapshots exist, the -R option must be specified to destroy the clones as well.


Note - The file system that you want to roll back must be unmounted and remounted, if it is currently mounted. If the file system cannot be unmounted, the rollback fails. The -f option forces the file system to be unmounted, if necessary.


In the following example, the tank/home/ahrens file system is rolled back to the tuesday snapshot:

# zfs rollback tank/home/[email protected]
cannot rollback to 'tank/home/[email protected]': more recent snapshots exist
use '-r' to force deletion of the following snapshots:
tank/home/[email protected]
tank/home/[email protected]
# zfs rollback -r tank/home/[email protected]

In the above example, the wednesday and thursday snapshots are removed because you rolled back to the previous tuesday snapshot.

# zfs list -r -t snapshot -o name,creation tank/home/ahrens
NAME                      CREATION
tank/home/[email protected]  Wed Aug 30 10:53 2006
Previous Next

 
 
  Published under the terms fo the Public Documentation License Version 1.01. Design by Interspire