The University of Arizona

Resources

ZFS Snapshots

Introduction

The SunFire X4500 fileserver zuni has a special facility that allows users to restore files that were accidentally deleted or modified. As part of Sun's ZFS filesytem structure, the fileserver periodically takes 'snapshots' of all its filesystems. Users can recover files from these snapshots without any assistance from the Lab staff. The snapshot feature is not a general undelete facility. The fileserver takes snapshots on a fixed schedule, and files that aren't captured in a snapshot cannot be recovered this way.

The snapshot schedule

There are multiple levels of snapshots. The current schedule is as follows. Daily snapshots are taken each morning at midnight. The snapshots taken on Sunday mornings are retained for five weeks. The daily snapshots taken on the other days (Monday through Saturday) are retained for one week. Snapshots are also taken each day at four hour intervals -- at 4 am, 8 am, 12 noon, 4 pm, and 8 pm. These four-hour-interval snapshots are retained for two days.

Each snapshot is named based on the date and time that it was created in the form of 'MM-DD-hh:mm' (e.g., 02-25-17:13 would represent a snapshot created on February 25th at 17:13 hours).

At present, the snapshot scheme involves 21 copies covering a period of roughly five weeks.

Recovering files from snapshots

The fileserver automatically creates a .zfs/snapshot subdirectory for every filesystem.

For each /home/username directory, there is a link .snapshot that points to the .zfs/snapshot subdirectory for that username.

To access these snapshots from lectura or other department Linux machines:

  $ cd ~/.snapshot

  $ ls
  06-15-00:10  07-06-00:10  07-11-00:10  07-13-12:10  07-14-00:10  07-14-12:10  07-15-00:10
  06-22-00:10  07-09-00:10  07-12-00:10  07-13-16:10  07-14-04:10  07-14-16:10  07-15-04:10
  06-29-00:10  07-10-00:10  07-13-00:10  07-13-20:10  07-14-08:10  07-14-20:10  07-15-08:10

Note these are directories with names that correspond to the date and time the snapshot was created.

To access the most recent snapshot (per this example):

  $ cd 07-15-08:10/username


To find a particular file in a snapshot, you would then use standard Unix commands to navigate through a snapshot directory (the file structure is the same as your /home directory). Once you have located the version of the file you are interested in, you can copy it to another location (e.g., your home directory) which will, in effect, restore it.



Similarly, there is a link .snapshot for each 'top-level' directory under /cs/contrib and /cs/projects.

Example:

  $ cd /cs/projects/solar/.snapshot (or cd /cs/solar/.snapshot)

  $ ls
  06-15-00:10  07-06-00:10  07-11-00:10  07-13-12:10  07-14-00:10  07-14-12:10  07-15-00:10
  06-22-00:10  07-09-00:10  07-12-00:10  07-13-16:10  07-14-04:10  07-14-16:10  07-15-04:10
  06-29-00:10  07-10-00:10  07-13-00:10  07-13-20:10  07-14-08:10  07-14-20:10  07-15-08:10

  $ cd 07-15-08:10/solar


Note that snapshots are read-only. You cannot edit files within the snapshot area -- you must copy them elsewhere and then edit from that location. Also, you cannot delete directories or files within the snapshot area.

Be aware of file permissions -- especially on sensitive files. If you set a file to be world-readable and it is captured in a snapshot, you won't be able to remove the world-read permission on the snapshot file.

How do snapshots work?

Basically, Sun Microsystems ZFS implements snapshots simply by cloning the root inode of the filesystem, without copying any disk blocks. Then a copy-on-write technique is used to populate the snapshot as files are modified or deleted.


Last updated Tuesday, 15-Jul-2008 14:33:04 MST, by Phil Kaslo
Send questions about this page to