source: src-sh/lpreserver/backend/runsnap.sh @ ac48c86

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since ac48c86 was ac48c86, checked in by Kris Moore <kris@…>, 16 months ago

Change e-mail subject, so we can at a glance see result of snapshot / replication

  • Property mode set to 100755
File size: 2.0 KB
Line 
1#!/bin/sh
2# Do the cron snapshot
3######################################################################
4
5# Set our vars
6PROGDIR="/usr/local/share/lpreserver"
7
8# Source our functions
9. /usr/local/share/pcbsd/scripts/functions.sh
10. ${PROGDIR}/backend/functions.sh
11
12DATASET="${1}"
13KEEP="${2}"
14snapStat=0
15
16if [ -z "${DATASET}" ]; then
17  exit_err "No dataset specified!"
18fi
19
20# Create the snapshot now with the "auto-" tag
21echo_log "Creating snapshot on ${DATASET}"
22mkZFSSnap "${DATASET}" "auto-"
23if [ $? -ne 0 ] ; then
24  echo_log "ERROR: Failed creating snapshot on ${DATASET}"
25  queue_msg "Snapshot ERROR" "ERROR: Failed creating snapshot on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
26  snapStat=1
27else
28  queue_msg "Success creating snapshot on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
29fi
30
31# Get our list of snaps
32snaps=$(snaplist "${DATASET}")
33
34# Reverse the list
35for tmp in $snaps
36do
37   rSnaps="$tmp $rSnaps"
38done
39
40# Do any pruning
41num=0
42for snap in $rSnaps
43do
44   # Only remove snapshots which are auto-created, so we don't delete one the user
45   # made specifically
46   cur="`echo $snap | cut -d '-' -f 1`" 
47   if [ "$cur" != "auto" ] ; then
48     continue;
49   fi
50
51   num=`expr $num + 1`
52   if [ $num -gt $KEEP ] ; then
53      echo_log "Pruning old snapshot: $snap"
54      rmZFSSnap "${DATASET}" "$snap"
55      if [ $? -ne 0 ] ; then
56        echo_log "ERROR: Failed pruning snapshot $snap on ${DATASET}"
57        queue_msg "Snapshot ERROR" "ERROR: Failed pruning snapshot $snap on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
58        snapStat=1
59      else
60        queue_msg "Success pruning snapshot $snap on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
61      fi
62    fi
63done
64
65# If we failed at any point, sent out a notice
66if [ $snapStat -ne 0 ] ; then
67   email_msg "FAILED - Automated Snapshot" "`echo_queue_msg`"
68fi
69
70# If we are successful and user wants all notifications, send out a message
71if [ $snapStat -eq 0 -a "$EMAILMODE" = "ALL" ] ; then
72   email_msg "Success - Automated Snapshot" "`echo_queue_msg`"
73fi
74
75# Check if we need to run a replication task for this dataset
76${PROGDIR}/backend/runrep.sh ${DATASET} sync
Note: See TracBrowser for help on using the repository browser.