Scheduled Snapshots

All your general support questions for OpenZFS on OS X.

Scheduled Snapshots

Postby zisper » Sun Aug 07, 2016 6:31 pm

Hi;

Just wondering if anybody has something scripted to automatically take snapshots, and purge the older ones - keeping only larger time steps as the snapshots "age". I've seen a couple of scripts for this on the web, but no mention of anybody running them on OS X. I don't mind tinkering myself, but I thought if somebody had a system that's already working well for them then I could save myself some time by just copying it.
zisper
 
Posts: 16
Joined: Wed Jul 20, 2016 2:48 am

Re: Scheduled Snapshots

Postby stumble » Sun Aug 07, 2016 9:15 pm

This works well for me on MacOS:

http://bunny.xeny.net/temp/zfs-auto-snap
stumble
 
Posts: 37
Joined: Thu May 15, 2014 7:05 pm

Re: Scheduled Snapshots

Postby stumble » Sun Aug 07, 2016 9:17 pm

In fact, that script I just linked to is so short I may as well post the whole thing inline:

Code: Select all
#!/bin/bash

##
# original code: http://andyleonard.com/2010/04/07/automatic-zfs-snapshot-rotation-on-freebsd/
# 07/17/2011 - ertug: made it compatible with zfs-fuse which doesn't have .zfs directories
##

# Path to ZFS executable:
ZFS=/usr/sbin/zfs
 
# Parse arguments:
TARGET=$1
SNAP=$2
COUNT=$3
 
# Function to display usage:
usage() {
    scriptname=`/usr/bin/basename $0`
    echo "$scriptname: Take and rotate snapshots on a ZFS file system"
    echo
    echo "  Usage:"
    echo "  $scriptname target snap_name count"
    echo
    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'."
    echo
    exit
}
 
# Basic argument checks:
if [ -z $COUNT ] ; then
    usage
fi
 
if [ ! -z $4 ] ; then
    usage
fi
 
# 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}
fi
 
# Rename existing snapshots:
dest=$max_snap
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}
    fi
    dest=$(($dest - 1))
done
 
# Create new snapshot:
$ZFS snapshot -r ${TARGET}@${SNAP}.0
stumble
 
Posts: 37
Joined: Thu May 15, 2014 7:05 pm

Re: Scheduled Snapshots

Postby Brendon » Sun Aug 07, 2016 9:34 pm

http://www.znapzend.org/ supposedly works on O3X/OSX.
Brendon
 
Posts: 286
Joined: Thu Mar 06, 2014 12:51 pm


Return to General Help

Who is online

Users browsing this forum: No registered users and 129 guests