Managing ZFS snapshots

ZFS provides the ability to create snapshots of a file system at a point in time. The typical use is to restore/recover the accidentally deleted file or directory (it is stored inside of a snapshot).

To enable snapshots in Ubunbu, install the package zfs-auto-snapshot by running:

sudo apt-get install zfs-auto-snapshot

This will install the necessary bash scripts (zfs-auto-snapshot) and add them to cron. To install ZFS on a Ubuntu server, follow this tutorial.

Cron configuration files responsible for the frequency of snapshots are:

/etc/cron.d/zfs-auto-snapshot
/etc/cron.hourly/zfs-auto-snapshot
/etc/cron.weekly/zfs-auto-snapshot
/etc/cron.monthly/zfs-auto-snapshot

To list all snapshots:

zfs list -t snapshot

To disable autosnapshots on a filesystem:

zfs set com.sun:auto-snapshot=false [filesystem name, e.g. u/documents]

To mount a snapshot (to /mnt/snapshot):

mount -t zfs u/documents@zfs-auto-snap_frequent-2013-09-04-1545 /mnt/snapshot

To restore files/directories from a snapshot (to a temporary directory):

zfs clone [snapshot name, e.g. u/backup@today] /temp/directory

To remove all snapshots:

zfs list -H -o name -t snapshot | xargs -n1 zfs destroy

Advertisements

One thought on “Managing ZFS snapshots

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s