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

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

Update to lpreserver backend:

Added new "replicate init <dataset>" option, which will re-init the remote side of the replication server, cleaning up any corrupt datasets and preparing to sync fresh again.

Also added a check during replication, we won't try to kickoff a second replication task if a previous one is still running, to avoid collisions. In addition we will not delete any snapshots until the initial replication is finished, in order to prevent undercutting the active replication

  • Property mode set to 100755
File size: 2.7 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# Make sure this is a valid DATASET
21zfs list ${DATASET} >/dev/null 2>/dev/null
22if [ $? -ne 0 ] ; then
23   exit_err "Invalid dataset specified ${DATASET}"
24fi
25
26# Create the snapshot now with the "auto-" tag
27echo_log "Creating snapshot on ${DATASET}"
28mkZFSSnap "${DATASET}" "auto-"
29if [ $? -ne 0 ] ; then
30  echo_log "ERROR: Failed creating snapshot on ${DATASET}"
31  queue_msg "ERROR: Failed creating snapshot on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
32  snapStat=1
33else
34  queue_msg "Success creating snapshot on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
35fi
36
37# Get our list of snaps
38snaps=$(snaplist "${DATASET}")
39
40# Reverse the list
41for tmp in $snaps
42do
43   rSnaps="$tmp $rSnaps"
44done
45
46# Before we start pruning, check if any replication is running
47skipPrune=0
48export pidFile="${DBDIR}/.reptask-`echo ${DATASET} | sed 's|/|-|g'`"
49if [ -e "${pidFile}" ] ; then
50   pgrep -F ${pidFile} >/dev/null 2>/dev/null
51   if [ $? -eq 0 ] ; then skipPrune=1; fi
52fi
53
54if [ $skipPrune -eq 1 ] ; then
55  # No pruning since replication is currently running
56  echo_log "WARNING: Skipped pruning snapshots on ${DATASET} while replication is running."
57  queue_msg "WARNING: Skipped pruning snapshots on ${DATASET} while replication is running."
58
59else
60  # Do any pruning
61  num=0
62  for snap in $rSnaps
63  do
64     # Only remove snapshots which are auto-created, so we don't delete one the user
65     # made specifically
66     cur="`echo $snap | cut -d '-' -f 1`" 
67     if [ "$cur" != "auto" ] ; then
68       continue;
69     fi
70
71     num=`expr $num + 1`
72     if [ $num -gt $KEEP ] ; then
73        echo_log "Pruning old snapshot: $snap"
74        rmZFSSnap "${DATASET}" "$snap"
75        if [ $? -ne 0 ] ; then
76          echo_log "ERROR: Failed pruning snapshot $snap on ${DATASET}"
77          queue_msg "ERROR: Failed pruning snapshot $snap on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
78          snapStat=1
79        else
80          queue_msg "Success pruning snapshot $snap on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
81        fi
82      fi
83  done
84fi
85
86# If we failed at any point, sent out a notice
87if [ $snapStat -ne 0 ] ; then
88   email_msg "FAILED - Automated Snapshot" "`echo_queue_msg`"
89fi
90
91# If we are successful and user wants all notifications, send out a message
92if [ $snapStat -eq 0 -a "$EMAILMODE" = "ALL" ] ; then
93   email_msg "Success - Automated Snapshot" "`echo_queue_msg`"
94fi
95
96# Check if we need to run a replication task for this dataset
97${PROGDIR}/backend/runrep.sh ${DATASET} sync
Note: See TracBrowser for help on using the repository browser.