source: src-sh/lpreserver/backend/functions.sh @ a3560cd

releng/10.0.1releng/10.0.2
Last change on this file since a3560cd was a3560cd, checked in by Kris Moore <kris@…>, 6 months ago

Add hourly/30min/10min options to life-preserver replication frequency

  • Property mode set to 100755
File size: 18.3 KB
Line 
1#!/bin/sh
2# Functions / variables for lpreserver
3######################################################################
4# DO NOT EDIT
5
6# Source external functions
7. /usr/local/share/pcbsd/scripts/functions.sh
8
9# Installation directory
10PROGDIR="/usr/local/share/lpreserver"
11
12# Location of settings
13DBDIR="/var/db/lpreserver"
14if [ ! -d "$DBDIR" ] ; then mkdir -p ${DBDIR} ; fi
15
16CMDLOG="${DBDIR}/lp-lastcmdout"
17CMDLOG2="${DBDIR}/lp-lastcmdout2"
18REPCONF="${DBDIR}/replication"
19LOGDIR="/var/log/lpreserver"
20REPLOGSEND="${LOGDIR}/lastrep-send-log"
21REPLOGRECV="${LOGDIR}/lastrep-recv-log"
22MSGQUEUE="${DBDIR}/.lpreserver.msg.$$"
23export DBDIR LOGDIR PROGDIR CMDLOG REPCONF REPLOGSEND REPLOGRECV MSGQUEUE
24
25# Create the logdir
26if [ ! -d "$LOGDIR" ] ; then mkdir -p ${LOGDIR} ; fi
27
28#Set our Options
29setOpts() {
30  if [ -e "${DBDIR}/recursive-off" ] ; then
31    export RECURMODE="OFF"
32  else
33    export RECURMODE="ON"
34  fi
35
36  if [ -e "${DBDIR}/emaillevel" ] ; then
37    export EMAILMODE="`cat ${DBDIR}/emaillevel`"
38  fi
39
40  if [ -e "${DBDIR}/duwarn" ] ; then
41    export DUWARN="`cat ${DBDIR}/duwarn`"
42  else
43    export DUWARN=85
44  fi
45
46  case $EMAILMODE in
47      ALL|WARN|ERROR) ;;
48        *) export EMAILMODE="WARN";;
49  esac
50
51  if [ -e "${DBDIR}/emails" ] ; then
52    export EMAILADDY="`cat ${DBDIR}/emails`"
53  fi
54
55}
56setOpts
57
58
59# Check if a directory is mounted
60isDirMounted() {
61  mount | grep -q "on $1 ("
62  return $?
63}
64
65mkZFSSnap() {
66  if [ "$RECURMODE" = "ON" ] ; then
67     flags="-r"
68  else
69     flags="-r"
70  fi
71  zdate=`date +%Y-%m-%d-%H-%M-%S`
72  zfs snapshot $flags ${1}@$2${zdate} >${CMDLOG} 2>${CMDLOG}
73  return $?
74}
75
76listZFSSnap() {
77  zfs list -t snapshot | grep -e "^${1}@" | awk '{print $1}'
78}
79
80rmZFSSnap() {
81  `zfs list -t snapshot | grep -q "^$1@$2 "` || exit_err "No such snapshot!"
82  if [ "$RECURMODE" = "ON" ] ; then
83     flags="-r"
84  else
85     flags="-r"
86  fi
87  zfs destroy -r ${1}@${2} >${CMDLOG} 2>${CMDLOG}
88  return $?
89}
90
91revertZFSSnap() {
92  # Make sure this is a valid snapshot
93  `zfs list -t snapshot | grep -q "^$1@$2 "` || exit_err "No such snapshot!"
94
95  # Rollback the snapshot
96  zfs rollback -R -f ${1}@$2
97}
98
99enable_cron()
100{
101   cronscript="${PROGDIR}/backend/runsnap.sh"
102
103   # Make sure we remove any old entries for this dataset
104   cat /etc/crontab | grep -v " $cronscript $1" > /etc/crontab.new
105   mv /etc/crontab.new /etc/crontab
106   if [ "$2" = "OFF" ] ; then
107      return
108   fi
109
110   case $2 in
111       daily) cLine="0       $4      *       *       *" ;;
112      hourly) cLine="0       *       *       *       *" ;;
113       30min) cLine="0,30    *       *       *       *" ;;
114       10min) cLine="*/10    *       *       *       *" ;;
115   5min|auto) cLine="*/5     *       *       *       *" ;;
116           *) exit_err "Invalid time specified" ;;
117   esac
118
119   echo -e "$cLine\troot    ${cronscript} $1 $3" >> /etc/crontab
120}
121
122enable_watcher()
123{
124   cronscript="${PROGDIR}/backend/zfsmon.sh"
125
126   # Check if the zfs monitor is already enabled
127   grep -q " $cronscript" /etc/crontab
128   if [ $? -eq 0 ] ; then return; fi
129
130   cLine="*/30    *       *       *       *"
131
132   echo -e "$cLine\troot    ${cronscript}" >> /etc/crontab
133}
134
135snaplist() {
136  zfs list -t snapshot | grep "^${1}@" | cut -d '@' -f 2 | awk '{print $1}'
137}
138
139echo_log() {
140   echo "`date`: $@" >> ${LOGDIR}/lpreserver.log
141}
142
143# E-Mail a message to the set addresses
144# 1 = subject tag
145# 2 = Message
146email_msg() {
147   if [ -z "$EMAILADDY" ] ; then return ; fi
148   echo -e "$2"  | mail -s "$1 - `hostname`" $EMAILADDY
149}
150
151queue_msg() {
152  echo -e "$1" >> ${MSGQUEUE}
153  if [ -n "$2" ] ; then
154    cat $2 >> ${MSGQUEUE}
155  fi
156}
157
158echo_queue_msg() {
159  if [ ! -e "$MSGQUEUE" ] ; then return ; fi
160  cat ${MSGQUEUE}
161  rm ${MSGQUEUE}
162}
163
164add_rep_task() {
165  # add freenas.8343 backupuser 22 tank1/usr/home/kris tankbackup/backups sync
166  HOST=$1
167  USER=$2
168  PORT=$3
169  LDATA=$4
170  RDATA=$5
171  TIME=$6
172
173  case $TIME in
174     [0-9][0-9]|sync|hour|30min|10min) ;;
175     *) exit_err "Invalid time: $TIME"
176  esac
177 
178  echo "Adding replication task for local dataset $LDATA"
179  echo "----------------------------------------------------------"
180  echo "   Remote Host: $HOST" 
181  echo "   Remote User: $USER" 
182  echo "   Remote Port: $PORT" 
183  echo "Remote Dataset: $RDATA" 
184  echo "          Time: $TIME" 
185  echo "----------------------------------------------------------"
186  echo "Don't forget to ensure that this user / dataset exists on the remote host"
187  echo "with the correct permissions!"
188
189  rem_rep_task "$LDATA"
190  echo "$LDATA:$TIME:$HOST:$USER:$PORT:$RDATA" >> ${REPCONF}
191
192  if [ "$TIME" != "sync" ] ; then
193    case $TIME in
194        hour) cTime="0     *" ;;
195       30min) cTime="*/30     *" ;;
196       10min) cTime="*/10     *" ;;
197           *) cTime="0     *" ;;
198    esac
199    cronscript="${PROGDIR}/backend/runrep.sh"
200    cLine="$cTime       *       *       *"
201    echo -e "$cLine\troot    ${cronscript} ${LDATA}" >> /etc/crontab
202  fi
203}
204
205rem_rep_task() {
206  if [ ! -e "$REPCONF" ] ; then return ; fi
207  cat ${REPCONF} | grep -v "^${1}:" > ${REPCONF}.tmp
208  mv ${REPCONF}.tmp ${REPCONF}
209
210  # Make sure we remove any old replication entries for this dataset
211  cronscript="${PROGDIR}/backend/runrep.sh"
212  cat /etc/crontab | grep -v " $cronscript $1" > /etc/crontab.new
213  mv /etc/crontab.new /etc/crontab
214}
215
216list_rep_task() {
217  if [ ! -e "$REPCONF" ] ; then return ; fi
218
219  echo "Scheduled replications:"
220  echo "---------------------------------"
221
222  while read line
223  do
224     LDATA=`echo $line | cut -d ':' -f 1`
225     TIME=`echo $line | cut -d ':' -f 2`
226     HOST=`echo $line | cut -d ':' -f 3`
227     USER=`echo $line | cut -d ':' -f 4`
228     PORT=`echo $line | cut -d ':' -f 5`
229     RDATA=`echo $line | cut -d ':' -f 6`
230
231     echo "$LDATA -> $USER@$HOST[$PORT]:$RDATA Time: $TIME"
232
233  done < ${REPCONF}
234}
235
236check_rep_task() {
237  export DIDREP=0
238  if [ ! -e "$REPCONF" ] ; then return 0; fi
239
240  repLine=`cat ${REPCONF} | grep "^${1}:"`
241  if [ -z "$repLine" ] ; then return 0; fi
242
243  # We have a replication task for this dataset, lets check if we need to do it now
244  LDATA="$1"
245  REPTIME=`echo $repLine | cut -d ':' -f 2`
246
247  # Export the replication variables we will be using
248  export REPHOST=`echo $repLine | cut -d ':' -f 3`
249  export REPUSER=`echo $repLine | cut -d ':' -f 4`
250  export REPPORT=`echo $repLine | cut -d ':' -f 5`
251  export REPRDATA=`echo $repLine | cut -d ':' -f 6`
252
253  if [ "$2" = "force" ] ; then
254     # Ready to do a forced replication
255     export DIDREP=1
256     echo_log "Starting replication MANUAL task on ${DATASET}: ${REPLOGSEND}"
257     queue_msg "`date`: Starting replication MANUAL task on ${DATASET}\n"
258     start_rep_task "$LDATA"
259     return $?
260  fi
261
262  # If we are checking for a sync task, and the rep isn't marked as sync we can return
263  if [ "$2" = "sync" -a "$REPTIME" != "sync" ] ; then return 0; fi
264
265  # Doing a replication task, check if one is in progress
266  export pidFile="${DBDIR}/.reptask-`echo ${LDATA} | sed 's|/|-|g'`"
267  if [ -e "${pidFile}" ] ; then
268     pgrep -F ${pidFile} >/dev/null 2>/dev/null
269     if [ $? -eq 0 ] ; then
270        echo_log "Skipped replication on $LDATA, previous replication is still running."
271        return 0
272     else
273        rm ${pidFile}
274     fi
275  fi
276
277  # Save this PID
278  echo "$$" > ${pidFile}
279
280  # Is this a sync-task we do at the time of a snapshot?
281  if [ "$2" = "sync" -a "$REPTIME" = "sync" ] ; then
282     export DIDREP=1
283     echo_log "Starting replication SYNC task on ${DATASET}: ${REPLOGSEND}"
284     queue_msg "`date`: Starting replication SYNC task on ${DATASET}\n"
285     start_rep_task "$LDATA"
286     return $?
287  else
288     # Ready to do a scheduled replication
289     export DIDREP=1
290     echo_log "Starting replication SCHEDULED task on ${DATASET}: ${REPLOGSEND}"
291     queue_msg "`date`: Starting replication SCHEDULED task on ${DATASET}\n"
292     start_rep_task "$LDATA"
293     return $?
294  fi
295}
296
297start_rep_task() {
298  LDATA="$1"
299  hName=`hostname`
300
301  # Check for the last snapshot marked as replicated already
302  lastSEND=`zfs get -r backup:lpreserver ${LDATA} | grep LATEST | awk '{$1=$1}1' OFS=" " | tail -1 | cut -d '@' -f 2 | cut -d ' ' -f 1`
303
304  # Lets get the last snapshot for this dataset
305  lastSNAP=`zfs list -t snapshot -d 1 -H ${LDATA} | tail -1 | awk '{$1=$1}1' OFS=" " | cut -d '@' -f 2 | cut -d ' ' -f 1`
306 
307  if [ "$lastSEND" = "$lastSNAP" ] ; then
308     queue_msg "`date`: Last snapshot $lastSNAP is already marked as replicated!"
309     rm ${pidFile}
310     return 1
311  fi
312
313  # Starting replication, first lets check if we can do an incremental send
314  if [ -n "$lastSEND" ] ; then
315     zFLAGS="-Rv -I $lastSEND $LDATA@$lastSNAP"
316  else
317     zFLAGS="-Rv $LDATA@$lastSNAP"
318
319     # This is a first-time replication, lets create the new target dataset
320     ssh -p ${REPPORT} ${REPUSER}@${REPHOST} zfs create ${REPRDATA}/${hName} >${CMDLOG} 2>${CMDLOG}
321  fi
322
323  zSEND="zfs send $zFLAGS"
324  zRCV="ssh -p ${REPPORT} ${REPUSER}@${REPHOST} zfs receive -dvuF ${REPRDATA}/${hName}"
325
326  queue_msg "Using ZFS send command:\n$zSEND | $zRCV\n\n"
327
328  # Start up our process
329  $zSEND 2>${REPLOGSEND} | $zRCV >${REPLOGRECV} 2>${REPLOGRECV}
330  zStatus=$?
331  queue_msg "ZFS SEND LOG:\n--------------\n" "${REPLOGSEND}"
332  queue_msg "ZFS RCV LOG:\n--------------\n" "${REPLOGRECV}"
333
334  if [ $zStatus -eq 0 ] ; then
335     # SUCCESS!
336     # Lets mark our new latest snapshot and unmark the last one
337     if [ -n "$lastSEND" ] ; then
338       zfs set backup:lpreserver=' ' ${LDATA}@$lastSEND
339     fi
340     zfs set backup:lpreserver=LATEST ${LDATA}@$lastSNAP
341     echo_log "Finished replication task on ${DATASET}"
342     save_rep_props
343     zStatus=$?
344  else
345     # FAILED :-(
346     # Lets save the output for us to look at later
347     FLOG=${LOGDIR}/lpreserver_failed.log
348     echo "Failed with command:\n$zSEND | $zRCV\n" > ${FLOG}
349     echo "\nSending log:\n" >> ${FLOG}
350     cat ${REPLOGSEND} >> ${FLOG}
351     echo "\nRecv log:\n" >> ${FLOG}
352     cat ${REPLOGRECV} >> ${FLOG}
353     echo_log "FAILED replication task on ${DATASET}: LOGFILE: $FLOG"
354  fi
355
356  rm ${pidFile}
357  return $zStatus
358}
359
360save_rep_props() {
361  # If we are not doing a recursive backup / complete dataset we can skip this
362  if [ "$RECURMODE" != "ON" ] ; then return 0; fi
363  if [ "`basename $DATASET`" != "$DATASET" ] ; then return 0; fi
364  hName="`hostname`"
365
366  echo_log "Saving dataset properties for: ${DATASET}"
367  queue_msg "`date`: Saving dataset properties for: ${DATASET}\n"
368
369  # Lets start by building a list of props to keep
370  rProp=".lp-props-`echo ${REPRDATA}/${hName} | sed 's|/|#|g'`"
371
372  zfs get -r all $DATASET | grep ' local$' | awk '{$1=$1}1' OFS=" " | sed 's| local$||g' \
373        | ssh -p ${REPPORT} ${REPUSER}@${REPHOST} "cat > \"$rProp\""
374  if [ $? -eq 0 ] ; then
375    echo_log "Successful save of dataset properties for: ${DATASET}"
376    queue_msg "`date`: Successful save of dataset properties for: ${DATASET}\n"
377    return 0
378  else
379    echo_log "Failed saving dataset properties for: ${DATASET}"
380    queue_msg "`date`: Failed saving dataset properties for: ${DATASET}\n"
381    return 1
382  fi
383}
384
385listStatus() {
386
387  for i in `grep "${PROGDIR}/backend/runsnap.sh" /etc/crontab | awk '{print $8}'`
388  do
389    echo -e "DATASET - SNAPSHOT - REPLICATION"
390    echo "------------------------------------------"
391
392    lastSEND=`zfs get -r backup:lpreserver ${i} | grep LATEST | awk '{$1=$1}1' OFS=" " | tail -1 | cut -d '@' -f 2 | cut -d ' ' -f 1`
393    lastSNAP=`zfs list -t snapshot -d 1 -H ${i} | tail -1 | awk '{$1=$1}1' OFS=" " | cut -d '@' -f 2 | cut -d ' ' -f 1`
394
395    if [ -z "$lastSEND" ] ; then lastSEND="NONE"; fi
396    if [ -z "$lastSNAP" ] ; then lastSNAP="NONE"; fi
397
398    echo "$i - $lastSNAP - $lastSEND"
399  done
400}
401
402add_zpool_disk() {
403   pool="$1"
404   disk="$2"
405   disk="`echo $disk | sed 's|/dev/||g'`"
406
407   if [ -z "$pool" ] ; then
408      exit_err "No pool specified"
409      exit 0
410   fi
411
412   if [ -z "$disk" ] ; then
413      exit_err "No disk specified"
414      exit 0
415   fi
416
417   if [ ! -e "/dev/$disk" ] ; then
418      exit_err "No such device: $disk"
419      exit 0
420   fi
421
422   zpool list -H -v | awk '{print $1}' | grep -q "^$disk"
423   if [ $? -eq 0 ] ; then
424      exit_err "Error: This disk is already apart of a zpool!"
425   fi
426
427   # Check if pool exists
428   zpool status $pool >/dev/null 2>/dev/null
429   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi
430
431   # Cleanup the target disk
432   echo "Deleting all partitions on: $disk"
433   rc_nohalt "gpart destroy -F $disk" >/dev/null 2>/dev/null
434   rc_nohalt "dd if=/dev/zero of=/dev/${disk} bs=1m count=1" >/dev/null 2>/dev/null
435   rc_nohalt "dd if=/dev/zero of=/dev/${disk} bs=1m oseek=`diskinfo /dev/${disk} | awk '{print int($3 / (1024*1024)) - 4;}'`" >/dev/null 2>/dev/null
436
437   # Grab the first disk in the pool
438   mDisk=`zpool list -H -v | grep -v "^$pool" | awk '{print $1}' | grep -v "^mirror" | grep -v "^raidz" | head -n 1`
439
440   # Is this MBR or GPT?
441   echo $mDisk | grep -q 's[0-4][a-z]$'
442   if [ $? -eq 0 ] ; then
443      # MBR
444      type="MBR"
445      # Strip off the "a-z"
446      rDiskDev=`echo $mDisk | rev | cut -c 2- | rev`
447   else
448      # GPT
449      type="GPT"
450      # Strip off the "p[1-9]"
451      rDiskDev=`echo $mDisk | rev | cut -c 3- | rev`
452   fi
453
454   # Make sure this disk has a layout we can read
455   gpart show $rDiskDev >/dev/null 2>/dev/null
456   if [ $? -ne 0 ] ; then
457      exit_err "failed to get disk device layout $rDiskDev"
458   fi
459
460   # Get the size of "freebsd-zfs & freebsd-swap"
461   sSize=`gpart show ${rDiskDev} | grep freebsd-swap | cut -d "(" -f 2 | cut -d ")" -f 1`
462   zSize=`gpart show ${rDiskDev} | grep freebsd-zfs | cut -d "(" -f 2 | cut -d ")" -f 1`
463   
464   echo "Creating new partitions on $disk"
465   if [ "$type" = "MBR" ] ; then
466      # Create the new MBR layout
467      rc_halt_s "gpart create -s MBR -f active $disk"
468      rc_halt_s "gpart add -a 4k -t freebsd $disk"     
469      rc_halt_s "gpart set -a active -i 1 $disk"
470      rc_halt_s "gpart create -s BSD ${disk}s1"
471      rc_halt_s "gpart add -t freebsd-zfs -s $zSize ${disk}s1"
472      if [ -n "$sSize" ] ; then
473        rc_halt_s "gpart add -t freebsd-swap -s $sSize ${disk}s1"
474      fi
475      aDev="${disk}s1a"
476   else
477      # Creating a GPT disk
478      rc_halt_s "gpart create -s GPT $disk"
479      rc_halt_s "gpart add -b 34 -s 1M -t bios-boot $disk"
480      rc_halt_s "gpart add -t freebsd-zfs -s $zSize ${disk}"
481      if [ -n "$sSize" ] ; then
482        rc_halt_s "gpart add -t freebsd-swap -s $sSize ${disk}"
483      fi
484      aDev="${disk}p2"
485   fi
486
487   # Now we can insert the target disk
488   echo "Attaching to zpool: $aDev"
489   rc_halt_s "zpool attach $pool $mDisk $aDev"
490
491   # Lastly we need to stamp GRUB
492   echo "Stamping GRUB on: $disk"
493   rc_halt_s "grub-install --force /dev/${disk}"
494
495   echo "Added $disk ($aDev) to zpool $pool. Resilver will begin automatically."
496   exit 0
497}
498
499list_zpool_disks() {
500   pool="$1"
501
502   if [ -z "$pool" ] ; then
503      exit_err "No pool specified"
504      exit 0
505   fi
506
507   # Check if pool exists
508   zpool status $pool >/dev/null 2>/dev/null
509   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi
510
511   zpool list -H -v $pool
512}
513
514rem_zpool_disk() {
515   pool="$1"
516   disk="$2"
517
518   if [ -z "$pool" ] ; then
519      exit_err "No pool specified"
520      exit 0
521   fi
522
523   if [ -z "$disk" ] ; then
524      exit_err "No disk specified"
525      exit 0
526   fi
527
528   # Check if pool exists
529   zpool status $pool >/dev/null 2>/dev/null
530   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi
531
532   zpool detach $pool $disk
533   if [ $? -ne 0 ] ; then
534      exit_err "Failed detaching $disk"
535   fi
536   echo "$disk was detached successfully!"
537   exit 0
538}
539
540offline_zpool_disk() {
541   pool="$1"
542   disk="$2"
543
544   if [ -z "$pool" ] ; then
545      exit_err "No pool specified"
546      exit 0
547   fi
548
549   if [ -z "$disk" ] ; then
550      exit_err "No disk specified"
551      exit 0
552   fi
553
554   # Check if pool exists
555   zpool status $pool >/dev/null 2>/dev/null
556   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi
557
558   zpool offline $pool $disk
559   exit $?
560}
561
562online_zpool_disk() {
563   pool="$1"
564   disk="$2"
565
566   if [ -z "$pool" ] ; then
567      exit_err "No pool specified"
568      exit 0
569   fi
570
571   if [ -z "$disk" ] ; then
572      exit_err "No disk specified"
573      exit 0
574   fi
575
576   # Check if pool exists
577   zpool status $pool >/dev/null 2>/dev/null
578   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi
579
580   zpool online $pool $disk
581   exit $?
582}
583
584init_rep_task() {
585
586  LDATA="$1"
587
588  repLine=`cat ${REPCONF} | grep "^${LDATA}:"`
589  if [ -z "$repLine" ] ; then return 0; fi
590 
591  # We have a replication task for this set, get some vars
592  hName=`hostname`
593  REPHOST=`echo $repLine | cut -d ':' -f 3`
594  REPUSER=`echo $repLine | cut -d ':' -f 4`
595  REPPORT=`echo $repLine | cut -d ':' -f 5`
596  REPRDATA=`echo $repLine | cut -d ':' -f 6`
597
598  # First check if we even have a dataset on the remote
599  ssh -p ${REPPORT} ${REPUSER}@${REPHOST} zfs list ${REPRDATA}/${hName} 2>/dev/null >/dev/null
600  if [ $? -eq 0 ] ; then
601     # Lets cleanup the remote side
602     echo "Removing remote dataset: ${REPRDATA}/${hName}"
603     ssh -p ${REPPORT} ${REPUSER}@${REPHOST} zfs destroy -r ${REPRDATA}/${hName}
604     if [ $? -ne 0 ] ; then
605        echo "Warning: Could not delete remote dataset ${REPRDATA}/${hName}"
606     fi
607  fi
608
609  # Now lets mark none of our datasets as replicated
610  lastSEND=`zfs get -r backup:lpreserver ${LDATA} | grep LATEST | awk '{$1=$1}1' OFS=" " | tail -1 | cut -d '@' -f 2 | cut -d ' ' -f 1`
611  if [ -n "$lastSEND" ] ; then
612     zfs set backup:lpreserver=' ' ${LDATA}@$lastSEND
613  fi
614
615}
616
617## Function to remove the oldest life-preserver snapshot on the target
618## zpool, used by zfsmon.sh when the disk space gets low
619do_pool_cleanup()
620{
621  # Is this zpool managed by life-preserver?
622  grep -q "${PROGDIR}/backend/runsnap.sh ${1} " /etc/crontab
623  if [ $? -ne 0 ] ; then return ; fi
624
625  # Before we start pruning, check if any replication is running
626  local pidFile="${DBDIR}/.reptask-`echo ${1} | sed 's|/|-|g'`"
627  if [ -e "${pidFile}" ] ; then
628     pgrep -F ${pidFile} >/dev/null 2>/dev/null
629     if [ $? -eq 0 ] ; then return; fi
630  fi
631
632  # Get the list of snapshots for this zpool
633  snapList=$(snaplist "${1}")
634
635  # Do any pruning
636  for snap in $snapList
637  do
638     # Only remove snapshots which are auto-created by life-preserver
639     cur="`echo $snap | cut -d '-' -f 1`"
640     if [ "$cur" != "auto" ] ; then continue; fi
641
642     echo_log "Pruning old snapshot: $snap"
643     rmZFSSnap "${1}" "$snap"
644     if [ $? -ne 0 ] ; then
645       haveMsg=1
646       echo_log "ERROR: (Low Disk Space) Failed pruning snapshot $snap on ${1}"
647       queue_msg "ERROR: (Low Disk Space) Failed pruning snapshot $snap on ${1} @ `date` \n\r`cat $CMDLOG`"
648     else
649       queue_msg "(Low Disk Space) Auto-pruned snapshot: $snap on ${1} @ `date`\n\r`cat $CMDLOG`"
650       haveMsg=1
651     fi
652
653     # We only prune a single snapshot at this time, so lets end
654     break
655  done
656
657  return 0
658}
Note: See TracBrowser for help on using the repository browser.