2020-10-13 13:32:08 +02:00
|
|
|
#!/bin/bash
|
2022-09-01 07:43:08 +02:00
|
|
|
volume_name="$1" # Volume-Name
|
|
|
|
backup_hash="$2" # Hashed Machine ID
|
|
|
|
version="$3" # version to backup
|
|
|
|
container="$4" # optional
|
|
|
|
mysql_root_password="$5" # optional
|
|
|
|
database="$6" # optional
|
2023-04-19 13:21:09 +02:00
|
|
|
backup_folder="Backups/$backup_hash/docker-volume-backup/$version/$volume_name"
|
2022-08-31 19:04:42 +02:00
|
|
|
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
|
2023-03-27 01:49:58 +02:00
|
|
|
|
|
|
|
if [ -f "$backup_sql" ]; then
|
2023-06-28 21:22:02 +02:00
|
|
|
if [ -n "$container" ] && [ -n "$mysql_root_password" ] && [ -n "$database" ]; then
|
|
|
|
echo "recover mysql dump"
|
|
|
|
cat $backup_sql | docker exec -i "$container" /usr/bin/mysql -u root --password="$mysql_root_password" $database
|
|
|
|
exit 0
|
2023-03-27 01:49:58 +02:00
|
|
|
fi
|
2023-06-28 21:22:02 +02:00
|
|
|
echo "a database backup exists, but a parameter is missing. Files will be recovered instead."
|
|
|
|
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/"
|
2021-11-11 13:03:19 +01:00
|
|
|
fi
|
2023-06-28 21:22:02 +02:00
|
|
|
|
2023-03-27 01:49:58 +02:00
|
|
|
echo "ERROR: $backup_files and $backup_sql don't exist"
|
|
|
|
exit 1
|