From 18fcd3b06d987af041094dff0b538bb98bf4b7b0 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 27 Mar 2023 01:49:58 +0200 Subject: [PATCH] Solved bug in recovery logic --- docker-volume-recover.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docker-volume-recover.sh b/docker-volume-recover.sh index 7ef5347..55c47f7 100644 --- a/docker-volume-recover.sh +++ b/docker-volume-recover.sh @@ -17,11 +17,16 @@ if [ $exit_status_volume_inspect -eq 0 ]; then echo "Create volume $volume_name" docker volume create "$volume_name" fi -if [ ! -d "$backup_files" ]; then - if [ ! -f "$backup_sql" ]; then - echo "ERROR: $backup_files and $backup_sql don't exist" - exit 1 - fi + +if [ -f "$backup_sql" ]; then + echo "recover mysql dump" cat $backup_sql | docker exec -i "$container" '/usr/bin/mysql -u root --password="'$mysql_root_password'" "'$database'"' + exit 0 +else + 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/" + fi fi -docker run --rm -v "$volume_name:/recover/" -v "$backup_files:/backup/" "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv --delete /backup/ /recover/" +echo "ERROR: $backup_files and $backup_sql don't exist" +exit 1