OmniOS: Automatic Snapshots with Znapzend

Automatic generation and deletion of snapshots

This article is part of a series focused on the building and setup of a home-NAS based on ZFS and OmniOS. The index is located here: An OmniOS ZFS Fileserver.

I like to have snapshots to be able to go back in time in case I make a mistake or in case a file gets for any reason corrupted. For my Mac I use Time Machine (where the location of the backup is the OmniOS server), but the data that I access on the server via AFP (that means most of my data) is not protected this way.

Initially I had some scripts I worte myself, but there was no automatic cleanup of old ones, so I decided to use Znapzend for the task (by the way Znapzend's main developer is also the author of the The Not So Short Introduction to LATEX2ε! what a nice guide).

Znapzend requires Perl to run, but I didn't want to rely on the system-wide Perl install, rarely updated, and also I didn't want to dirty it with additional modules, so I installed the most recent version somewhere else (see also The OmniOS Approach to Software Distribution). I downloaded Perl from the website and I installed it on /opt/perl.

Then I went on with Znapzend:

$ git clone https://github.com/oetiker/znapzend.git
$ cd znapzend

$ PERL=/opt/perl/bin/perl ./configure --prefix=/opt/znapzend --enable-svcinstall=/var/svc/manifest/site
$ pfexec /usr/bin/gmake install

For most datasets I don't need any particular snapshot strategy, so I keep them for a fixed period of time:

$ pfexec /opt/znapzend/bin/znapzendzetup create --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '6m=>1w' tank/Backups
$ pfexec /opt/znapzend/bin/znapzendzetup create --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '6m=>1w' tank/Software
$ pfexec /opt/znapzend/bin/znapzendzetup create --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '3m=>1d' tank/Temporary
$ pfexec /opt/znapzend/bin/znapzendzetup create --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '3m=>1d' tank/VM
$ pfexec /opt/znapzend/bin/znapzendzetup create --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '6m=>1w' tank/eBooks
$ pfexec /opt/znapzend/bin/znapzendzetup create --recursive --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '6m=>1w' tank/media
$ pfexec /opt/znapzend/bin/znapzendzetup create --recursive --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '6m=>1w' rpool/ROOT
$ pfexec /opt/znapzend/bin/znapzendzetup create --recursive --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '6m=>1w' rpool/export
$ pfexec /opt/znapzend/bin/znapzendzetup create --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '6m=>1d' tank/home/httpi

For my home I want hourly snapshots for two weeks, daily snapshots for three months, and weekly snapshots forever.

$ pfexec /opt/znapzend/bin/znapzendzetup create --recursive --tsformat='znapzend-%Y-%m-%d-%H%M%S' SRC '2w=>1h,3m=>1d,10y=>1w' tank/home/olaf

Then I checked the configuration:

$ pfexec /opt/znapzend/bin/znapzendzetup list
$ pfexec /opt/znapzend/bin/znapzend --noaction --debug --runonce=tank/Backups

and at the end I installed the service:

$ svccfg validate /var/svc/manifest/site/znapzend.xml
$ pfexec svccfg import /var/svc/manifest/site/znapzend.xml
$ pfexec svcadm enable oep/znapzend
$ svcs -xv oep/znapzend

After over one months, it seems it is working very fine. I cleaned up manually one last time the old snapshots, leaving weekly ones, and I disabled my custom cron jobs.

Author: Olaf Marzocchi

First revision: 2015-02-02.
Last revision: 2016-11-06.