Changeset 44bdd65


Ignore:
Timestamp:
02/20/14 10:36:15 (10 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, releng/10.0.1, releng/10.0.2, releng/10.0.3, releng/10.1
Children:
4f9718b
Parents:
e07f550
Message:

Add new functionality to Life-Preserver, now when the ZFS monitor runs,
check if disk-space is getting low on the Life-Preserver managed zpools.

If it is getting low, auto-prune the oldest snapshot to free up some additional
space.

Location:
src-sh/lpreserver/backend
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src-sh/lpreserver/backend/functions.sh

    r59f014c4 r44bdd65  
    608608 
    609609} 
     610 
     611## Function to remove the oldest life-preserver snapshot on the target 
     612## zpool, used by zfsmon.sh when the disk space gets low 
     613do_pool_cleanup() 
     614{ 
     615  # Is this zpool managed by life-preserver? 
     616  grep -q "${PROGDIR}/backend/runsnap.sh ${1} " /etc/crontab 
     617  if [ $? -ne 0 ] ; then return ; fi 
     618 
     619  # Before we start pruning, check if any replication is running 
     620  local pidFile="${DBDIR}/.reptask-`echo ${1} | sed 's|/|-|g'`" 
     621  if [ -e "${pidFile}" ] ; then 
     622     pgrep -F ${pidFile} >/dev/null 2>/dev/null 
     623     if [ $? -eq 0 ] ; then return; fi 
     624  fi 
     625 
     626  # Get the list of snapshots for this zpool 
     627  snapList=$(snaplist "${1}") 
     628 
     629  # Do any pruning 
     630  for snap in $snapList 
     631  do 
     632     # Only remove snapshots which are auto-created by life-preserver 
     633     cur="`echo $snap | cut -d '-' -f 1`" 
     634     if [ "$cur" != "auto" ] ; then continue; fi 
     635 
     636     echo_log "Pruning old snapshot: $snap" 
     637     rmZFSSnap "${1}" "$snap" 
     638     if [ $? -ne 0 ] ; then 
     639       haveMsg=1 
     640       echo_log "ERROR: (Low Disk Space) Failed pruning snapshot $snap on ${1}" 
     641       queue_msg "ERROR: (Low Disk Space) Failed pruning snapshot $snap on ${1} @ `date` \n\r`cat $CMDLOG`" 
     642     else 
     643       queue_msg "(Low Disk Space) Auto-pruned snapshot: $snap on ${1} @ `date`\n\r`cat $CMDLOG`" 
     644       haveMsg=1 
     645     fi 
     646 
     647     # We only prune a single snapshot at this time, so lets end 
     648     break 
     649  done 
     650 
     651  return 0 
     652} 
  • src-sh/lpreserver/backend/zfsmon.sh

    r4c15f05 r44bdd65  
    2727if [ -e "${DBDIR}/zpool-alert-du" ] ; then rm ${DBDIR}/zpool-alert-du ; fi 
    2828 
    29 zpool list  | grep -v "^NAME" > /tmp/.lPreserver-df.$$ 
    30 while read line 
     29# Do the disk-space check 
     30for zpool in `zpool list -H | awk '{print $1}'` 
    3131do 
    32    cap=`echo $line | awk '{print $5}' | cut -d '%' -f 1` 
    33    zpool=`echo $line | awk '{print $1}'` 
    34    if [ $(is_num "$cap") ] ; then 
    35       if [ $cap -gt $DUWARN ] ; then 
    36          queue_msg "Warning! ${zpool} is currently at ${cap}% capacity!"         
    37          echo "$cap" > $DBDIR/zpool-alert-du 
    38          haveMsg=1 
    39       fi 
    40    fi 
    41 done< /tmp/.lPreserver-df.$$ 
    42 rm /tmp/.lPreserver-df.$$ 
     32  poolCap="`zpool list -H -o capacity $zpool | cut -d '%' -f 1`" 
     33 
     34  if [ $poolCap -gt $DUWARN ] ; then 
     35     queue_msg "Warning! ${zpool} is currently at ${poolCap}% capacity!" 
     36     echo "$poolCap" > $DBDIR/zpool-alert-du 
     37     haveMsg=1 
     38  fi 
     39 
     40  # See if we can do any auto-cleanup of this pool 
     41  if [ $poolCap -gt 85 ] ; then do_pool_cleanup "$zpool"; fi 
     42 
     43done 
    4344 
    4445# Lets check free disk space on the pools 
Note: See TracChangeset for help on using the changeset viewer.