ZFS snapshots

File system snapshots have made their way into pretty much all of the major file systems (e.g., UFS, VxFS, WAFL, ZFS, etc.), and allow storage administrators to create point-in-time consistent copies (it’s not a block-by-block copy, since snapshots typically only grow when a block is changed) of a file system. Since snapshots contain a consistent point-in-time copy of the data in a file system, they are ideal for backups, instantaneous data recovery, and can assist with disaster recovery. Snapshot support is available with the Zetabyte File System (ZFS), and can be accessed with the zfs utilities “snapshot” option:

$ zfs snapshot snaptest@Thursday

In this example, a snapshot of the file system named “snaptest” will be created with the name “Thursday.” To view the list of snapshots that have been created, the zfs “list” option can be used:

$ zfs list

NAME                   USED  AVAIL  REFER  MOUNTPOINT
snaptest              18.0G  32.1G  18.0G  /snaptest
snaptest@Thursday         0      -  18.0G  -

Once a snapshot is created, you can access the snapshots contents by changing to the .zfs directory in the filesystem that was snapshoted:

$ cd /snaptest/.zfs/snapshot/Thursday

$ ls -l
total 37786139
-rw——T 1 root root 1073741824 Mar 31 20:57 file1
-rw——T 1 root root 1073741824 Mar 31 21:00 file2
-rw——T 1 root root 1073741824 Mar 31 21:01 file3
-rw——T 1 root root 1073741824 Mar 31 21:01 file4

To recover a file from a snapshot, you can change to the subdirectory under the .zfs directory you want to recover a file from, and invoke your favorite file-level utility to salvage the file:

$ cd /snaptest/.zfs/snapshot/Thursday

$ cp file1 /tmp

Once you are finished using the contents of a snapshot, you can use the zfs utilities “destroy” option to remove the snapshot:

$ zfs destroy snaptest@Thursday

$ zfs list

NAME                   USED  AVAIL  REFER  MOUNTPOINT
snaptest              1.50G  48.6G  1.50G  /snaptest

Snapshots have been around for quite some time (I first used snapshots on NetApp filers), and it’s cool to see that ZFS supports them.