From 8fc3322505923df36af226eb0fc7ec204dfca382 Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Thu, 15 Aug 2024 12:58:40 -0700 Subject: [PATCH] add bashup::set-existing_backups function --- sbin/bashup-backup-files.sh | 1 + sbin/bashup-list-backups.sh | 1 + sbin/bashup-restore-files.sh | 2 +- sbin/bashup-restore-mysql.sh | 2 +- sbin/bashup-restore-pdns.sh | 2 +- sbin/bashup.sh | 16 +++++++++------- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/sbin/bashup-backup-files.sh b/sbin/bashup-backup-files.sh index 0d7264b..e227c92 100755 --- a/sbin/bashup-backup-files.sh +++ b/sbin/bashup-backup-files.sh @@ -8,6 +8,7 @@ source $(dirname $0)/bashup.sh bashup::set-retention_array +bashup::set-existing_backups # create backup for today if [[ " ${retention_array[@]} " =~ " ${today} " ]]; then diff --git a/sbin/bashup-list-backups.sh b/sbin/bashup-list-backups.sh index 0672a8d..83fca88 100755 --- a/sbin/bashup-list-backups.sh +++ b/sbin/bashup-list-backups.sh @@ -92,6 +92,7 @@ if [ ! -z "$backup" ]; then fi else # output list of backups (dates) + bashup::set-existing_backups for existing_backup in "${existing_backups[@]}"; do echo $existing_backup done diff --git a/sbin/bashup-restore-files.sh b/sbin/bashup-restore-files.sh index 8022896..b93680a 100755 --- a/sbin/bashup-restore-files.sh +++ b/sbin/bashup-restore-files.sh @@ -52,7 +52,7 @@ while getopts "b:np:h" opt; do esac done -bashup::set_existing_backups +bashup::set-existing_backups # prompt if backup was not set on command line if [ -z "$backup" ] ; then diff --git a/sbin/bashup-restore-mysql.sh b/sbin/bashup-restore-mysql.sh index 1dfcc0e..ba4e483 100755 --- a/sbin/bashup-restore-mysql.sh +++ b/sbin/bashup-restore-mysql.sh @@ -52,7 +52,7 @@ while getopts "b:d:nh" opt; do esac done -bashup::set_existing_backups +bashup::set-existing_backups # prompt if backup was not set on command line if [ -z "$backup" ] ; then diff --git a/sbin/bashup-restore-pdns.sh b/sbin/bashup-restore-pdns.sh index 4d93855..8246331 100755 --- a/sbin/bashup-restore-pdns.sh +++ b/sbin/bashup-restore-pdns.sh @@ -52,7 +52,7 @@ while getopts "b:nz:h" opt; do esac done -bashup::set_existing_backups +bashup::set-existing_backups # prompt if backup was not set on command line if [ -z "$backup" ] ; then diff --git a/sbin/bashup.sh b/sbin/bashup.sh index ce18f36..36b0a23 100755 --- a/sbin/bashup.sh +++ b/sbin/bashup.sh @@ -106,14 +106,16 @@ fi # get todays date (backup dir name) today=$(date +%Y%m%d) -# set existing_backups array -existing_backups=($(ls $backup_storage_dir|grep -v lost+found)) -# if script is a *-backup-* script remove today from existing backups, if it exists. we do other checks avoid re-doing backups -if [[ "$0" == *"-backup-"* ]];then - if [[ " ${existing_backups[@]} " =~ " ${today} " ]]; then - unset 'existing_backups[-1]'; +function bashup::set-existing_backups () { + # set existing_backups array + existing_backups=($(ls $backup_storage_dir|grep -v lost+found)) + # if script is a *-backup-* script remove today from existing backups, if it exists. we do other checks avoid re-doing backups + if [[ "$0" == *"-backup-"* ]];then + if [[ " ${existing_backups[@]} " =~ " ${today} " ]]; then + unset 'existing_backups[-1]'; + fi fi -fi +} function bashup::set-retention_array () {