initial attempt at delete_old function
This commit is contained in:
parent
ba60880621
commit
f367c43649
1 changed files with 30 additions and 32 deletions
|
@ -104,31 +104,29 @@ verbose() {
|
||||||
# delete old backups
|
# delete old backups
|
||||||
delete_old() {
|
delete_old() {
|
||||||
#
|
#
|
||||||
if test -n $BU_FROOT && test -n $BU_TO_KEEP ; then
|
verbose "deleting old files based on $1"
|
||||||
# pattern to search for to build the list...
|
# pattern to search for to build the list...
|
||||||
PATTERN="$BU_DIR/$BU_FROOT-*.*"
|
PATTERN="$BU_DIR/$1-*.*"
|
||||||
# build the list, with the suffix...
|
# build the list, with the suffix...
|
||||||
PRUNEABLES=`$PRUNEABLES_CMD $PATTERN`
|
PRUNEABLES=`$PRUNEABLES_CMD $PATTERN`
|
||||||
if test "$?" -eq "0" ; then
|
if test "$?" -eq "0" ; then
|
||||||
message "pruning older files based on $PATTERN.$BU_SUFFIX"
|
message "pruning older files based on $PATTERN"
|
||||||
message "keeping last $BU_TO_KEEP backups"
|
BU_TO_KEEP=$BU_TO_KEEP_${!2}
|
||||||
#
|
message "keeping last $BU_TO_KEEP backups"
|
||||||
# set counter
|
#
|
||||||
NUM=0
|
# set counter
|
||||||
# go through the list of files and remove those we don't want
|
NUM=0
|
||||||
for PRUNEABLE in $PRUNEABLES
|
# go through the list of files and remove those we don't want
|
||||||
do
|
for PRUNEABLE in $PRUNEABLES
|
||||||
NUM=$(($NUM + 1))
|
do
|
||||||
if test $NUM -gt $BU_TO_KEEP ; then
|
NUM=$(($NUM + 1))
|
||||||
message "deleting $PRUNEABLE"
|
if test $NUM -gt $BU_TO_KEEP ; then
|
||||||
rm $PRUNEABLE 2>&1 > /dev/null
|
message "deleting $PRUNEABLE"
|
||||||
else
|
#rm $PRUNEABLE 2>&1 > /dev/null
|
||||||
message "keeping $PRUNEABLE"
|
else
|
||||||
fi
|
message "keeping $PRUNEABLE"
|
||||||
done
|
fi
|
||||||
fi
|
done
|
||||||
else
|
|
||||||
message "keeping older backups, missing backup_root_filename..."
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#
|
#
|
||||||
|
@ -199,22 +197,22 @@ verbose "going to $DC_DIR"
|
||||||
OLD_DIR=`pwd`
|
OLD_DIR=`pwd`
|
||||||
cd $DC_DIR
|
cd $DC_DIR
|
||||||
#
|
#
|
||||||
# run the backup...
|
|
||||||
#
|
|
||||||
# a timestamp for logging purposes
|
# a timestamp for logging purposes
|
||||||
STAMP=`date '+%Y-%m-%d_%H-%M-%S'`
|
STAMP=`date '+%Y-%m-%d_%H-%M-%S'`
|
||||||
# delete stale backups
|
|
||||||
#
|
|
||||||
# delete_old
|
|
||||||
#
|
#
|
||||||
# generate the filename
|
# generate the filename
|
||||||
INC="BU_FROOT_$TASK"
|
INC="BU_FROOT_$TASK"
|
||||||
FILENAME=$BU_FROOT-${!INC}-$STAMP.sql
|
FILEPART=$BU_FROOT-${!INC}
|
||||||
|
FILENAME=$FILEPART-$STAMP.sql
|
||||||
FILEPATH=$BU_DIR/$FILENAME
|
FILEPATH=$BU_DIR/$FILENAME
|
||||||
|
#
|
||||||
|
# delete stale backups
|
||||||
|
delete_old $FILEPART
|
||||||
|
#
|
||||||
message "backing up all the databases into $FILEPATH"
|
message "backing up all the databases into $FILEPATH"
|
||||||
# dump the data into the file
|
# dump the data into the file
|
||||||
#
|
#
|
||||||
do_backup $FILEPATH
|
do_backup $FILEPATH $TASK
|
||||||
#
|
#
|
||||||
message "completed backup"
|
message "completed backup"
|
||||||
# compress the backup
|
# compress the backup
|
||||||
|
|
Loading…
Reference in a new issue