Automated snapshots?

All your general support questions for OpenZFS on OS X.

Automated snapshots?

Postby Sharko » Wed Sep 07, 2016 12:09 pm

So, is anyone doing automated snapshots? Care to share your technique or wizardry? Allan Jude's ZFS book mentions a FreeBSD package called "zfstools," which is apparently a collection of cron-based scripts in Ruby ( I haven't used Ruby before, and the scripts would probably need to be modified to work with launchd instead of cron. Has anyone done this? The scripts are quite elegant, and make use of ZFS properties to control how they work.

I also came across some scripts written in Bash shell: . These look a little more universal, a little more primitive, but definitely portable to OS X. Has anyone worked with this one, either?

If no one has done it, I'll probably work with the Bash scripts to implement something eventually.


Posts: 73
Joined: Thu May 12, 2016 12:19 pm

Re: Automated snapshots?

Postby stumble » Wed Sep 07, 2016 3:04 pm

I use this:

Code: Select all

# original code:
# 07/17/2011 - ertug: made it compatible with zfs-fuse which doesn't have .zfs directories

# Path to ZFS executable:
# Parse arguments:
# Function to display usage:
usage() {
    scriptname=`/usr/bin/basename $0`
    echo "$scriptname: Take and rotate snapshots on a ZFS file system"
    echo "  Usage:"
    echo "  $scriptname target snap_name count"
    echo "  target:    ZFS file system to act on"
    echo "  snap_name: Base name for snapshots, to be followed by a '.' and"
    echo "             an integer indicating relative age of the snapshot"
    echo "  count:     Number of snapshots in the snap_name.number format to"
    echo "             keep at one time.  Newest snapshot ends in '.0'."
# Basic argument checks:
if [ -z $COUNT ] ; then
if [ ! -z $4 ] ; then
# Snapshots are numbered starting at 0; $max_snap is the highest numbered
# snapshot that will be kept.
max_snap=$(($COUNT -1))
# Clean up oldest snapshot:
$ZFS list -t snapshot | grep -q ^${TARGET}@${SNAP}\.${max_snap}
if [ $? -eq 0 ] ; then
    $ZFS destroy -r ${TARGET}@${SNAP}.${max_snap}
# Rename existing snapshots:
while [ $dest -gt 0 ] ; do
    src=$(($dest - 1))
    $ZFS list -t snapshot | grep -q ^${TARGET}@${SNAP}\.${src}
    if [ $? -eq 0 ] ; then
    $ZFS rename -r ${TARGET}@${SNAP}.${src} ${TARGET}@${SNAP}.${dest}
    dest=$(($dest - 1))
# Create new snapshot:
$ZFS snapshot -r ${TARGET}@${SNAP}.0
Posts: 37
Joined: Thu May 15, 2014 7:05 pm

Re: Automated snapshots?

Postby Brendon » Wed Sep 07, 2016 5:00 pm

I use znapzend. Its available in brew (

- Brendon
Posts: 285
Joined: Thu Mar 06, 2014 12:51 pm

Re: Automated snapshots?

Postby Sharko » Wed Sep 07, 2016 7:33 pm

Thank you both for your suggestions!
Posts: 73
Joined: Thu May 12, 2016 12:19 pm

Re: Automated snapshots?

Postby haer22 » Thu Sep 08, 2016 1:48 am

For the snapshots I use

Here are som lines from my crontab:
Code: Select all
# ZFS snappies
0,30 * * * *    $ZF snapshot -v -r -z -a 5d zeus
1,31 0 * * *    $ZF snapshot -v -r -z -a 5w zeus
2,32 0 * * Mon  $ZF snapshot -v -r -z -a 3m zeus
3,33 0 1 * *    $ZF snapshot -v -r -z -a 3y zeus

The above lines gives me twice hourly snapshot that are saved for 5d, dailies are saved for 5w, etc.

The cleanup part is done by:
Code: Select all
25,55 * * * * $ZF destroy -vr zeus

zeus is my alive pool which I copy to my backup pool (gaia) by using zxfer:
Code: Select all
#  ZFS mirroring
# we run it after the new snapshots, and after the cleanup of old snapshots
5,35 * * * *    $ZX -V -dFy -R zeus gaia

zxfer will add and remove snapshots so gaia is always a copy of the current zeus.

Used them for 2-3 years, i.e. since I started using ZFS.
Posts: 118
Joined: Sun Mar 23, 2014 2:13 am

Re: Automated snapshots?

Postby tim.rohrer » Thu Sep 06, 2018 9:51 am


I know this post is almost two years old, but I was curious as to which zxfer you were/are using? I found the version on GitHub that Allan Jude took over. However, I'm having trouble finding explanations for some of the options you're using.

-F is shown as an option in the man page, but I have not yet found an explanation of what it does. However, in your example am I correct in assuming that is being passed "forced, yes" as an option for deleting snapshots on the destination?

-V is not shown at all.

I assume -R is recursive?
Posts: 28
Joined: Tue Jul 24, 2018 6:49 pm

Return to General Help

Who is online

Users browsing this forum: No registered users and 1 guest