From 15a1f17184e1cc7d8d4376b99b7c4d8d9965dbbf Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 11 Jan 2024 10:58:35 +0100 Subject: [PATCH] Changed logic so that volume is not created for db recoveries --- recover-docker-from-local.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/recover-docker-from-local.sh b/recover-docker-from-local.sh index f8cb51d..5ed9879 100644 --- a/recover-docker-from-local.sh +++ b/recover-docker-from-local.sh @@ -8,7 +8,7 @@ fi volume_name="$1" # Volume-Name backup_hash="$2" # Hashed Machine ID -version="$3" # version to backup +version="$3" # version to recover # DATABASE PARAMETERS database_type="$4" # Valid values; mariadb, postgress @@ -26,17 +26,6 @@ echo "Inspect volume $volume_name" docker volume inspect "$volume_name" exit_status_volume_inspect=$? -if [ $exit_status_volume_inspect -eq 0 ]; then - echo "Volume $volume_name already exists" -else - echo "Create volume $volume_name" - docker volume create "$volume_name" - if [ $? -ne 0 ]; then - echo "ERROR: Failed to create volume $volume_name" - exit 1 - fi -fi - if [ -f "$backup_sql" ]; then if [ -n "$database_container" ] && [ -n "$database_password" ] && [ -n "$database_name" ]; then echo "recover mysql dump" @@ -51,6 +40,17 @@ if [ -f "$backup_sql" ]; then exit 1 fi +if [ $exit_status_volume_inspect -eq 0 ]; then + echo "Volume $volume_name already exists" +else + echo "Create volume $volume_name" + docker volume create "$volume_name" + if [ $? -ne 0 ]; then + echo "ERROR: Failed to create volume $volume_name" + exit 1 + fi +fi + if [ -d "$backup_files" ]; then echo "recover files" docker run --rm -v "$volume_name:/recover/" -v "$backup_files:/backup/" "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv --delete /backup/ /recover/"