From 3442520e2efc0f0ff618bd68a0fb6ab1f8cb55a5 Mon Sep 17 00:00:00 2001 From: BallsOfSpaghetti <115404710+OpenSpaghettiSauce@users.noreply.github.com> Date: Thu, 1 Dec 2022 13:00:53 +0100 Subject: [PATCH] Fixed restore with NODATE Apparently I changed the problematic for loop on the VM, but I forgot to copy the script back to the git folder before committing. I put the for loop into the IF branches now. TESTING IS UNDERWAY - I will comment again once it is 100% verified working (for me, again, sorry.) --- helper-scripts/backup_and_restore.sh | 31 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/helper-scripts/backup_and_restore.sh b/helper-scripts/backup_and_restore.sh index 6d81fc49..29b8857e 100755 --- a/helper-scripts/backup_and_restore.sh +++ b/helper-scripts/backup_and_restore.sh @@ -23,8 +23,8 @@ if [[ ${1} == "help" ]]; then NODATE: Allows you to omit the date stamped folder. example: NODATE=1 backup_and_restore.sh backup all - - IMPORTANT: If you'd like to restore a NODATE backup, you have to + + IMPORTANT: If you'd like to restore a NODATE=1 backup, you have to use NODATE=1 for restoring as well! Otherwise, Mailcow will only look for timestamped folders, which you will not have. @@ -46,6 +46,7 @@ fi if [[ ! -z ${MAILCOW_BACKUP_LOCATION} ]]; then BACKUP_LOCATION="${MAILCOW_BACKUP_LOCATION}" + echo $BACKUP_LOCATION fi if [[ ! ${1} =~ (backup|restore|help) ]]; then @@ -136,7 +137,7 @@ fi function backup() { DATE=$(date +"%Y-%m-%d-%H-%M-%S") - if [[ -z "${NODATE}" ]]; then + if [[ -z "$NODATE" ]]; then # No NODATE defined so we backup normally FINAL_BACKUP_LOCATION="${BACKUP_LOCATION}/mailcow-${DATE}" else @@ -371,25 +372,31 @@ if [[ ${1} == "backup" ]]; then elif [[ ${1} == "restore" ]]; then i=1 declare -A FOLDER_SELECTION - - if [[ -z "${NODATE}" ]]; then - # No NODATE defined so restore normally + + if [[ -z "$NODATE" ]]; then + # Normal backup mode, check if any timestamped folders exist at backup location if [[ $(find ${BACKUP_LOCATION}/mailcow-* -maxdepth 1 -type d 2> /dev/null| wc -l) -lt 1 ]]; then echo "Selected backup location has no timestamped subfolders" exit 1 fi + for folder in $(ls -d ${BACKUP_LOCATION}/mailcow-*/); do + echo "[ ${i} ] - ${folder}" + FOLDER_SELECTION[${i}]="${folder}" + ((i++)) + done else + # NODATE set, any sub-folder will be shown to user if [[ $(find ${BACKUP_LOCATION}/* -maxdepth 1 -type d 2> /dev/null| wc -l) -lt 1 ]]; then echo "Selected backup location has no subfolders" exit 1 fi + for folder in $(ls -d ${BACKUP_LOCATION}/*/); do + echo "[ ${i} ] - ${folder}" + FOLDER_SELECTION[${i}]="${folder}" + ((i++)) + done fi - - for folder in $(ls -d ${BACKUP_LOCATION}/mailcow-*/); do - echo "[ ${i} ] - ${folder}" - FOLDER_SELECTION[${i}]="${folder}" - ((i++)) - done + echo input_sel=0 while [[ ${input_sel} -lt 1 || ${input_sel} -gt ${i} ]]; do