docker-volume-backup/docker-volume-recover.sh

28 lines
1.0 KiB
Bash
Raw Normal View History

2020-10-13 13:32:08 +02:00
#!/bin/bash
2022-08-31 19:04:42 +02:00
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"
2021-11-11 13:17:02 +01:00
echo "Inspect volume $volume_name"
docker volume inspect "$volume_name"
exit_status_volume_inspect=$?
if [ $exit_status_volume_inspect -eq 0 ]; then
2021-11-11 13:03:19 +01:00
echo "Volume $volume_name allready exists"
else
echo "Create volume $volume_name"
docker volume create "$volume_name"
fi
2022-08-31 19:04:42 +02:00
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
2021-11-11 13:03:19 +01:00
fi
2022-08-31 19:04:42 +02:00
docker run --rm -v "$volume_name:/recover/" -v "$backup_files:/backup/" "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv --delete /backup/ /recover/"