From 4591fe27ea178eb0a9223d5e3ca4afc2f4823414 Mon Sep 17 00:00:00 2001 From: Tim Foster Date: Tue, 2 Sep 2008 14:01:59 +0100 Subject: [PATCH] If no snapshots were ever taken for this schedule, take one via check_missed_snapshot() on startup. --- src/lib/svc/method/zfs-auto-snapshot | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib/svc/method/zfs-auto-snapshot b/src/lib/svc/method/zfs-auto-snapshot index 21421d7..0234a7d 100755 --- a/src/lib/svc/method/zfs-auto-snapshot +++ b/src/lib/svc/method/zfs-auto-snapshot @@ -301,7 +301,6 @@ function unschedule_snapshots { # if the last snapshot was taken more than ago, # and if that's the case, takes a snapshot immediatedly. function check_missed_snapshots { # $INTERVAL $PERIOD $FMRI - set -x typeset INTERVAL=$1 typeset PERIOD=$2 @@ -351,13 +350,19 @@ function check_missed_snapshots { # $INTERVAL $PERIOD $FMRI LAST_SNAPSHOT=$(zfs list -H -o name -r -t snapshot ${fs[0]} \ | grep "${fs[0]}@${PREFIX}${LABEL}" | tail -1) - # if we've never taken a snapshot, do nothing + # if we've never taken a snapshot, then we probably should + # arrange to have one taken now. Fake the LAST_SNAP_TIME variable if [ -z "$LAST_SNAPSHOT" ] ; then - return 0 + LAST_SNAP_TIME=0 + LAST_SNAP_TIME_HUMAN="[ no snapshot taken yet ]" fi - LAST_SNAP_TIME=$(zfs get -H -p -o value creation $LAST_SNAPSHOT) - LAST_SNAP_TIME_HUMAN=$(zfs get -H -o value creation $LAST_SNAPSHOT) + + # if we have taken a snapshot, find out when it was + if [ -n "$LAST_SNAPSHOT" ] ; then + LAST_SNAP_TIME=$(zfs get -H -p -o value creation $LAST_SNAPSHOT) + LAST_SNAP_TIME_HUMAN=$(zfs get -H -o value creation $LAST_SNAPSHOT) + fi NOW=$(perl -e 'print time;') # slightly incorrect time accounting here, but good enough.