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.)
This commit is contained in:
BallsOfSpaghetti 2022-12-01 13:00:53 +01:00
parent d1754bb5a6
commit 3442520e2e
1 changed files with 19 additions and 12 deletions

View File

@ -24,7 +24,7 @@ if [[ ${1} == "help" ]]; then
NODATE: Allows you to omit the date stamped folder. NODATE: Allows you to omit the date stamped folder.
example: NODATE=1 backup_and_restore.sh backup all 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 use NODATE=1 for restoring as well! Otherwise, Mailcow will only
look for timestamped folders, which you will not have. look for timestamped folders, which you will not have.
@ -46,6 +46,7 @@ fi
if [[ ! -z ${MAILCOW_BACKUP_LOCATION} ]]; then if [[ ! -z ${MAILCOW_BACKUP_LOCATION} ]]; then
BACKUP_LOCATION="${MAILCOW_BACKUP_LOCATION}" BACKUP_LOCATION="${MAILCOW_BACKUP_LOCATION}"
echo $BACKUP_LOCATION
fi fi
if [[ ! ${1} =~ (backup|restore|help) ]]; then if [[ ! ${1} =~ (backup|restore|help) ]]; then
@ -136,7 +137,7 @@ fi
function backup() { function backup() {
DATE=$(date +"%Y-%m-%d-%H-%M-%S") DATE=$(date +"%Y-%m-%d-%H-%M-%S")
if [[ -z "${NODATE}" ]]; then if [[ -z "$NODATE" ]]; then
# No NODATE defined so we backup normally # No NODATE defined so we backup normally
FINAL_BACKUP_LOCATION="${BACKUP_LOCATION}/mailcow-${DATE}" FINAL_BACKUP_LOCATION="${BACKUP_LOCATION}/mailcow-${DATE}"
else else
@ -372,24 +373,30 @@ elif [[ ${1} == "restore" ]]; then
i=1 i=1
declare -A FOLDER_SELECTION declare -A FOLDER_SELECTION
if [[ -z "${NODATE}" ]]; then if [[ -z "$NODATE" ]]; then
# No NODATE defined so restore normally # 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 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" echo "Selected backup location has no timestamped subfolders"
exit 1 exit 1
fi fi
else
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
fi
for folder in $(ls -d ${BACKUP_LOCATION}/mailcow-*/); do for folder in $(ls -d ${BACKUP_LOCATION}/mailcow-*/); do
echo "[ ${i} ] - ${folder}" echo "[ ${i} ] - ${folder}"
FOLDER_SELECTION[${i}]="${folder}" FOLDER_SELECTION[${i}]="${folder}"
((i++)) ((i++))
done 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
echo echo
input_sel=0 input_sel=0
while [[ ${input_sel} -lt 1 || ${input_sel} -gt ${i} ]]; do while [[ ${input_sel} -lt 1 || ${input_sel} -gt ${i} ]]; do