From 794ca288a5d7b23d1c50753da606200cff403342 Mon Sep 17 00:00:00 2001 From: Dave lane Date: Thu, 8 Feb 2018 17:29:05 +1300 Subject: [PATCH] working backup script, with old backup removal and cron template --- dbbackup-cron | 18 ++++++++++++++++++ dbbackup-docker-compose | 16 +++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 dbbackup-cron diff --git a/dbbackup-cron b/dbbackup-cron new file mode 100644 index 0000000..f8dae27 --- /dev/null +++ b/dbbackup-cron @@ -0,0 +1,18 @@ +# +# run system backups +# +# hourly - at 5 minutes past mon-sat +05 * * * * root /etc/dbbackup/dbbackup-docker-compose --hourly +# +# daily - at 7:30 pm, mon-sat +30 19 * * * root /etc/dbbackup/dbbackup-docker-compose --daily +# +# weekly - at 7:30 pm, sun +30 19 * * sun root /etc/dbbackup/dbbackup-docker-compose --weekly +# +# monthly - at 8:30 pm, on the first of the last of the month +30 20 1 * * root /etc/dbbackup/dbbackup-docker-compose --monthly +# +# yearly - at 8:30 pm, on the first of January. +30 20 1 1 * root /etc/dbbackup/dbbackup-docker-compose --yearly + diff --git a/dbbackup-docker-compose b/dbbackup-docker-compose index 9efc33e..3368463 100755 --- a/dbbackup-docker-compose +++ b/dbbackup-docker-compose @@ -25,7 +25,7 @@ BU_FROOT_YEARLY=yearly # this can be overridden at invocation BU_CONF=default-docker-compose.conf # # output for debugging... -VERBOSE=1 +VERBOSE=0 # # Stuff that should be universal for this install... # where we can find this app... @@ -111,8 +111,7 @@ delete_old() { PRUNEABLES=`$PRUNEABLES_CMD $PATTERN` if test "$?" -eq "0" ; then message "pruning older files based on $PATTERN" - - BU_TO_KEEP=$BU_TO_KEEP_${!2} + BU_TO_KEEP=$2 message "keeping last $BU_TO_KEEP backups" # # set counter @@ -123,11 +122,13 @@ delete_old() { NUM=$(($NUM + 1)) if test $NUM -gt $BU_TO_KEEP ; then message "deleting $PRUNEABLE" - #rm $PRUNEABLE 2>&1 > /dev/null + rm $PRUNEABLE 2>&1 > /dev/null else message "keeping $PRUNEABLE" fi done + else + message "No files with $PATTERN to delete" fi } # @@ -180,7 +181,7 @@ done # # # create the blank email report -#create_tmp_email +create_tmp_email # if test -f $BU_CONF ; then verbose "Reading default in $BU_CONF" @@ -208,7 +209,8 @@ FILENAME=$FILEPART-$STAMP.sql FILEPATH=$BU_DIR/$FILENAME # # delete stale backups -delete_old $FILEPART $TASK +TO_KEEP="BU_TO_KEEP_$TASK" +delete_old $FILEPART ${!TO_KEEP} # message "backing up all the databases into $FILEPATH" # dump the data into the file @@ -224,5 +226,5 @@ cd $OLD_DIR # # sent resulting email report # -#send_email_report +send_email_report exit 0