From f367c43649d3f156675a0dadb9deb83f48ab91cf Mon Sep 17 00:00:00 2001 From: Dave Lane Date: Thu, 8 Feb 2018 17:08:17 +1300 Subject: [PATCH] initial attempt at delete_old function --- dbbackup-docker-compose | 62 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/dbbackup-docker-compose b/dbbackup-docker-compose index 9e58541..2bf97fe 100755 --- a/dbbackup-docker-compose +++ b/dbbackup-docker-compose @@ -104,31 +104,29 @@ verbose() { # delete old backups delete_old() { # - if test -n $BU_FROOT && test -n $BU_TO_KEEP ; then - # pattern to search for to build the list... - PATTERN="$BU_DIR/$BU_FROOT-*.*" - # build the list, with the suffix... - PRUNEABLES=`$PRUNEABLES_CMD $PATTERN` - if test "$?" -eq "0" ; then - message "pruning older files based on $PATTERN.$BU_SUFFIX" - message "keeping last $BU_TO_KEEP backups" - # - # set counter - NUM=0 - # go through the list of files and remove those we don't want - for PRUNEABLE in $PRUNEABLES - do - NUM=$(($NUM + 1)) - if test $NUM -gt $BU_TO_KEEP ; then - message "deleting $PRUNEABLE" - rm $PRUNEABLE 2>&1 > /dev/null - else - message "keeping $PRUNEABLE" - fi - done - fi - else - message "keeping older backups, missing backup_root_filename..." + verbose "deleting old files based on $1" + # pattern to search for to build the list... + PATTERN="$BU_DIR/$1-*.*" + # build the list, with the suffix... + PRUNEABLES=`$PRUNEABLES_CMD $PATTERN` + if test "$?" -eq "0" ; then + message "pruning older files based on $PATTERN" + BU_TO_KEEP=$BU_TO_KEEP_${!2} + message "keeping last $BU_TO_KEEP backups" + # + # set counter + NUM=0 + # go through the list of files and remove those we don't want + for PRUNEABLE in $PRUNEABLES + do + NUM=$(($NUM + 1)) + if test $NUM -gt $BU_TO_KEEP ; then + message "deleting $PRUNEABLE" + #rm $PRUNEABLE 2>&1 > /dev/null + else + message "keeping $PRUNEABLE" + fi + done fi } # @@ -199,22 +197,22 @@ verbose "going to $DC_DIR" OLD_DIR=`pwd` cd $DC_DIR # -# run the backup... -# # a timestamp for logging purposes STAMP=`date '+%Y-%m-%d_%H-%M-%S'` -# delete stale backups -# -# delete_old # # generate the filename INC="BU_FROOT_$TASK" -FILENAME=$BU_FROOT-${!INC}-$STAMP.sql +FILEPART=$BU_FROOT-${!INC} +FILENAME=$FILEPART-$STAMP.sql FILEPATH=$BU_DIR/$FILENAME +# +# delete stale backups +delete_old $FILEPART +# message "backing up all the databases into $FILEPATH" # dump the data into the file # -do_backup $FILEPATH +do_backup $FILEPATH $TASK # message "completed backup" # compress the backup