Changeset 8482df7


Ignore:
Timestamp:
May 6, 2014 12:10:40 PM (2 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, releng/10.0.2
Children:
eaea8ff
Parents:
8a72cd6
Message:

Add the auto-prune functionality when we create automatic BE's

This will keep a maximum of 5 BE's on a system, before pruning the oldest.

This ONLY applies to automatically created BE's by the pcbsd-utils,
user-created ones will be left alone

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-sh/libsh/functions.sh

    reee006a r8482df7  
    664664  # Check if we need to prune any BEs 
    665665  # TODO 
    666  
    667 } 
     666  snapList=`beadm list | grep ^beforeUpdate | awk '{print $1}'` 
     667  snapCount=`echo $snapList | wc -l | awk '{print $1}'` 
     668 
     669  if [ -z "$snapCount" ] ; then return ; fi 
     670  if [ $snapCount -lt 5 ] ; then return ; fi 
     671 
     672 
     673  # Reverse the list 
     674  for tmp in $snapList 
     675  do 
     676     rSnaps="$tmp $rSnaps" 
     677  done 
     678 
     679  # Do any pruning 
     680  KEEP="5" 
     681  num=0 
     682  for snap in $rSnaps 
     683  do 
     684     cur="`echo $snap | cut -d '-' -f 1`" 
     685     if [ "$cur" != "beforeUpdate" ] ; then continue; fi 
     686 
     687     num=`expr $num + 1` 
     688 
     689     # Make sure this BE isn't mounted or running 
     690     beadm list grep "^$snap " | grep -q -e " N " -e " NR "  -e " /" 
     691     if [ $? -eq 0 ] ; then continue ; fi 
     692 
     693     if [ $num -gt $KEEP ] ; then 
     694        # Remove this old BE 
     695        echo "Removing BE: $snap" 
     696        beadm destroy $snap >/dev/null 2>/dev/null 
     697     fi 
     698  done 
     699} 
Note: See TracChangeset for help on using the changeset viewer.