dirvishmakeitexpire

#*********************************************************
#* Manually set dirvish vaults to expire.                *
#*                                                       *
#* Requires image format be set to use %Y-%m-%d          *
#* Set vault expire time to expire 'last year'           *
#* (Will not expire backups on the first day of month)   *
#* Created 2005-12-23 - RichardG                         *
#*********************************************************

#*********************************************************
# Make sure there is a paramater
#*********************************************************

if [ "$1" = "" ] ; then
    echo "Oops, I need a parameter.  What do you want to expire"
    echo "example:  $0 \*          #Expire all dirvish backups"
    echo "          $0 2005-10*  #Expire only October 2005 backups"
    exit
fi

    #*********************************************************
    # Check to make sure that we are IN a vault directory
    #*********************************************************
 
    if [ ! -f dirvish/default.conf ] ; then
        echo "I can't seem to find images.  This does not appear"
        echo "to be a dirvish vault. Please run this from inside"
        echo "a vault directory."
        exit
    fi

#*********************************************************
# Begin cycling through all of the directories given in
# the parameter on the command line in search of summary
# files.
#*********************************************************

for CYCLE in $@ ; do

 
    #*********************************************************
    # Cut bytes 9 and 10 out of the CYCLE string and assign
    # them to string CYCLEDATE. (NOTE: this needs to be
    # changed so that the directory date is evaluated, not the
    # directory (image) name)
    # Change the cut bytes below if you don't use image
    # format %Y-%m-%d
    #*********************************************************

    CYCLEDATE=`echo $CYCLE | cut -b 9-10`

    #*********************************************************
    # If the CYCLE evaluated is the first of a month. end this
    # CYCLE.
    #*********************************************************
    if [ "$CYCLEDATE" = "01" ] ; then
        echo "Skipping $CYCLE because it's a monthly"
        continue     #Skip to the next instance of CYCLE
    fi


    #*********************************************************
    # If the current CYCLE has a summary file, evaluate it
    # and pull out the current expire year
    #*********************************************************

    if [ -f $CYCLE/summary ] ; then
     
        #*********************************************************
        # Grab the current expire year, calculate new expire year
        #*********************************************************
        ORGYEAR=`grep Expire $CYCLE/summary | cut -f5 -d\ |cut -b 1-4`
        NEWYEAR=$ORGYEAR
        NEWYEAR=$[ NEWYEAR = $NEWYEAR - 1 ]
     
        #*********************************************************
        # Replace the ORGYEAR with NEWYEAR in the summary file
        #*********************************************************
        sed s/\=\=\ $ORGYEAR/\=\=\ $NEWYEAR/g < $CYCLE/summary > \
     $CYCLE/summary.new
        mv $CYCLE/summary.new $CYCLE/summary
        echo "$CYCLE has been set to expire."
    fi

done

dirvishmakeitexpire (last edited 2011-01-24 03:51:14 by KeithLofstrom)