From ae57266595cf96f5364327c9b23c4d486c787b9f Mon Sep 17 00:00:00 2001 From: Tim Foster Date: Thu, 31 Jul 2008 10:48:56 +0100 Subject: [PATCH] Adding the 'none' interval, and having the Makefile generate PSTAMPS --- Makefile | 1 + README.zfs-auto-snapshot.txt | 6 +++- src/lib/svc/method/zfs-auto-snapshot | 50 ++++++++++++++++++++-------- src/pkginfo | 2 +- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 581f16a..1462281 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ pkg: clean mkdir -p proto + cat `pwd`/src/pkginfo.s | sed -e s/~PSTAMP~/`uname -n``date +%Y%m%d%H%M%S`/g > `pwd`/src/pkginfo pkgmk -f `pwd`/src/prototype -d `pwd`/proto -r `pwd`/src clean: diff --git a/README.zfs-auto-snapshot.txt b/README.zfs-auto-snapshot.txt index 4415fd0..a077efa 100644 --- a/README.zfs-auto-snapshot.txt +++ b/README.zfs-auto-snapshot.txt @@ -67,7 +67,11 @@ The properties each instance needs are: determine which filesystems to snapshot - property inheritance is not respected. - zfs/interval [ hours | days | months ] + zfs/interval [ hours | days | months | none] + When set to none, we don't take automatic snapshots, but + leave an SMF instance available for users to manually + fire the method script whenever they want - useful for + snapshotting on system events. zfs/keep How many snapshots to retain. "all" keeps all snapshots. diff --git a/src/lib/svc/method/zfs-auto-snapshot b/src/lib/svc/method/zfs-auto-snapshot index ce5182f..385e53c 100755 --- a/src/lib/svc/method/zfs-auto-snapshot +++ b/src/lib/svc/method/zfs-auto-snapshot @@ -77,21 +77,31 @@ LOG="" HAS_RECURSIVE=$(zfs snapshot 2>&1 | fgrep -e '-r') +function get_pair { + NAME=$1 + shift 2 + echo "${NAME}=\"$@\"" + echo "export ${NAME}" +} + # A function to pull in the variables from the FMRI given # as the first argument. function zfs_smf_props { - SMF_PROPS=$(svcprop -p zfs $1 | \ - sed -e 's#^zfs/fs-name#zfs/fs_name#g' \ - -e 's#^zfs/backup-lock#zfs/backup_lock#g' \ - -e 's#^zfs/snapshot-children#zfs/snapshot_children#g' \ - -e 's#^zfs/backup-save-cmd#zfs/backup_save_cmd#g' \ - -e 's#zfs/##g' |\ - awk '{printf("%s=%s ",$1,$3)}') - - for pair in $SMF_PROPS ; do - export "$pair" - done +IFS=" +" +SMF_PROPS="$(svcprop -t -p zfs $1 |\ + sed -e 's#zfs/fs-name#zfs/fs_name#g' \ + -e 's#zfs/backup-lock#zfs/backup_lock#g' \ + -e 's#zfs/snapshot-children#zfs/snapshot_children#g' \ + -e 's#zfs/backup-save-cmd#zfs/backup_save_cmd#g' \ + -e 's#zfs/##g' -e 's/$/,/g')" +IFS=, +for line in $SMF_PROPS ; do + IFS=' +' + eval $(get_pair $line) +done } @@ -186,6 +196,10 @@ function add_cron_job { # $INTERVAL $PERIOD $OFFSET $FMRI TIMES=$(get_divisor 1 12 $PERIOD) ENTRY="0 0 1 $TIMES *" ;; + + 'none') + return 0 + ;; esac # Since we may have multiple instances all trying to start at @@ -231,6 +245,12 @@ function add_cron_job { # $INTERVAL $PERIOD $OFFSET $FMRI function unschedule_snapshots { typeset FMRI=$1 + typeset INTERVAL=$interval + + # interval set to 'none' means we don't want cron jobs + if [ "$INTERVAL" == "none" ]; then + return 0 + fi # See notes on $LOCK_OWNED variable in function add_cron_job LOCK_OWNED="false" @@ -269,6 +289,7 @@ function take_snapshot { FMRI=$1 zfs_smf_props $FMRI + export LOG=$log typeset DATE=$(date +%F-%H${SEP}%M${SEP}%S) typeset FILESYS=$fs_name typeset KEEP=$keep @@ -649,13 +670,14 @@ function is_scrubbing { # POOL SCRUBLIST # created above, where the argument is the FMRI containing properties we can # consult to in order to actually take the snapshot. -zfs_smf_props $SMF_FMRI -export LOG=$(svcprop -p restarter/logfile $SMF_FMRI) +if [ -n "${SMF_FMRI}" ] ; then + zfs_smf_props $SMF_FRI + export LOG=${log} +fi # $1 start | stop | an FMRI that we want to take snapshots of. case "$1" in 'start') - schedule_snapshots $SMF_FMRI if [ $? -eq 0 ] ; then result=$SMF_EXIT_OK diff --git a/src/pkginfo b/src/pkginfo index bb66cfa..91588b8 100644 --- a/src/pkginfo +++ b/src/pkginfo @@ -13,7 +13,7 @@ VERSION=0.11 MAXINST=1 CATEGORY=application DESC=Takes automatic snapshots of ZFS filesystems on a periodic basis. -PSTAMP=haiiro20080122113401 +PSTAMP=haiiro20080730110036 VENDOR=Sun Microsystems, Inc. HOTLINE=Please contact your local service provider EMAIL=tim.foster@sun.com