This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
/
runsnap.sh
executable file
·67 lines (56 loc) · 1.76 KB
/
runsnap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# Do the cron snapshot
######################################################################
# Set our vars
PROGDIR="/usr/local/share/lpreserver"
# Source our functions
. /usr/local/share/pcbsd/scripts/functions.sh
. ${PROGDIR}/backend/functions.sh
DATASET="${1}"
KEEP="${2}"
if [ -z "${DATASET}" ]; then
exit_err "No dataset specified!"
fi
# Create the snapshot now with the "auto-" tag
echo_log "Creating snapshot on ${DATASET}"
mkZFSSnap "${DATASET}" "auto-"
if [ $? -ne 0 ] ; then
echo_log "ERROR: Failed creating snapshot on ${DATASET}"
email_msg "Snapshot ERROR" "ERROR: Failed creating snapshot on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
else
queue_msg "Success creating snapshot on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
fi
# Get our list of snaps
snaps=$(snaplist "${DATASET}")
# Reverse the list
for tmp in $snaps
do
rSnaps="$tmp $rSnaps"
done
# Do any pruning
num=0
for snap in $rSnaps
do
# Only remove snapshots which are auto-created, so we don't delete one the user
# made specifically
cur="`echo $snap | cut -d '-' -f 1`"
if [ "$cur" != "auto" ] ; then
continue;
fi
num=`expr $num + 1`
if [ $num -gt $KEEP ] ; then
echo_log "Pruning old snapshot: $snap"
rmZFSSnap "${DATASET}" "$snap"
if [ $? -ne 0 ] ; then
echo_log "ERROR: Failed pruning snapshot $snap on ${DATASET}"
email_msg "Snapshot ERROR" "ERROR: Failed pruning snapshot $snap on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
else
queue_msg "Success pruning snapshot $snap on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
fi
fi
done
if [ "$EMAILMODE" = "ALL" ] ; then
email_msg "Automated Snapshot" "`echo_queue_msg`"
fi
# Check if we need to run a replication task for this dataset
${PROGDIR}/backend/runrep.sh ${DATASET} sync