From 6d6d7103d091633da828590801f100a1cda61b8f Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 31 Aug 2022 19:04:42 +0200 Subject: [PATCH] added database recovery --- docker-volume-recover.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/docker-volume-recover.sh b/docker-volume-recover.sh index befbf5b..4ce3cdd 100644 --- a/docker-volume-recover.sh +++ b/docker-volume-recover.sh @@ -1,9 +1,13 @@ #!/bin/bash -# @param $1 Volume-Name -# @param $2 Hash-Name -volume_name="$1" -backup_hash="$2" -backup_path="/Backups/$backup_hash/docker-volume-backup/latest/$volume_name/files" +volume_name="$1" # Volume-Name +backup_hash="$2" # Hashed Machine ID +container="$3" # optional +user="$4" # optional +password="$5" # optional +database="$6" # optional +backup_folder="Backups/$backup_hash/docker-volume-backup/latest/$volume_name" +backup_files="/$backup_folder/files" +backup_sql="/$backup_folder/sql/backup.sql" echo "Inspect volume $volume_name" docker volume inspect "$volume_name" exit_status_volume_inspect=$? @@ -13,8 +17,11 @@ if [ $exit_status_volume_inspect -eq 0 ]; then echo "Create volume $volume_name" docker volume create "$volume_name" fi -if [ ! -d "$backup_path" ]; then - echo "ERROR: $backup_path doesn't exist" - exit 1 +if [ ! -d "$backup_files" ]; then + if [ ! -f "$backup_sql" ]; then + echo "ERROR: $backup_files and $backup_sql don't exist" + exit 1 + fi + cat $backup_sql | docker exec -i $container /usr/bin/mysql -u $user --password=$password $database fi -docker run --rm -v "$volume_name:/recover/" -v "$backup_path:/backup/" "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv --delete /backup/ /recover/" +docker run --rm -v "$volume_name:/recover/" -v "$backup_files:/backup/" "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv --delete /backup/ /recover/"