79 lines
2.9 KiB
Bash
Executable File
79 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Restore-Skript für Docker-Backups
|
|
# Nutzt einen Backup-Ordner aus /home/thomas/backup_images/<DATUM_UHRZEIT>
|
|
|
|
if [ -z "$1" ]; then
|
|
echo "Bitte gib den Backup-Ordner als Argument an!"
|
|
echo "Beispiel: $0 2024-07-01_12-00-00"
|
|
exit 1
|
|
fi
|
|
|
|
BACKUP_ROOT="/home/thomas/backup_images"
|
|
BACKUP_DIR="$BACKUP_ROOT/$1"
|
|
|
|
if [ ! -d "$BACKUP_DIR" ]; then
|
|
echo "Backup-Ordner nicht gefunden: $BACKUP_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
# 1. Images wiederherstellen
|
|
if [ -d "$BACKUP_DIR/images" ]; then
|
|
for IMG in "$BACKUP_DIR/images"/*.tar.gz; do
|
|
echo "Importiere Image: $IMG"
|
|
gunzip -c "$IMG" | docker load
|
|
done
|
|
fi
|
|
|
|
# 2. Volumes wiederherstellen (Achtung: überschreibt aktuelle Daten!)
|
|
# Beispiel für Webshop Media/Static/Templates
|
|
if [ -f "$BACKUP_DIR/volumes/webshop_media.tar.gz" ]; then
|
|
echo "Stelle Webshop Media wieder her..."
|
|
tar xzf "$BACKUP_DIR/volumes/webshop_media.tar.gz" -C /home/thomas/container/webshop/cleanbuild
|
|
fi
|
|
if [ -f "$BACKUP_DIR/volumes/webshop_staticfiles.tar.gz" ]; then
|
|
echo "Stelle Webshop Staticfiles wieder her..."
|
|
tar xzf "$BACKUP_DIR/volumes/webshop_staticfiles.tar.gz" -C /home/thomas/container/webshop/cleanbuild
|
|
fi
|
|
if [ -f "$BACKUP_DIR/volumes/webshop_templates.tar.gz" ]; then
|
|
echo "Stelle Webshop Templates wieder her..."
|
|
tar xzf "$BACKUP_DIR/volumes/webshop_templates.tar.gz" -C /home/thomas/container/webshop/cleanbuild
|
|
fi
|
|
# SSV Media/Static
|
|
if [ -f "$BACKUP_DIR/volumes/ssv_media.tar.gz" ]; then
|
|
echo "Stelle SSV Media wieder her..."
|
|
tar xzf "$BACKUP_DIR/volumes/ssv_media.tar.gz" -C /home/thomas/container/ssv/html
|
|
fi
|
|
if [ -f "$BACKUP_DIR/volumes/ssv_staticfiles.tar.gz" ]; then
|
|
echo "Stelle SSV Staticfiles wieder her..."
|
|
tar xzf "$BACKUP_DIR/volumes/ssv_staticfiles.tar.gz" -C /home/thomas/container/ssv/html
|
|
fi
|
|
|
|
# 3. DB-Dumps importieren (automatisch aus db_uebersicht.md)
|
|
DB_UEBERSICHT="/home/thomas/db_uebersicht.md"
|
|
DUMP_DIR="$BACKUP_DIR/db_dumps"
|
|
if [ -d "$DUMP_DIR" ]; then
|
|
tail -n +5 "$DB_UEBERSICHT" | grep -v '^$' | while IFS='|' read -r _ app db_host port user pass _ _ _; do
|
|
db_host=$(echo "$db_host" | xargs)
|
|
user=$(echo "$user" | xargs)
|
|
pass=$(echo "$pass" | xargs)
|
|
if [[ -n "$db_host" && -n "$user" && -n "$pass" && "$db_host" != "DB-Host" ]]; then
|
|
DUMP_FILE="$DUMP_DIR/${db_host}.sql"
|
|
if [ -f "$DUMP_FILE" ]; then
|
|
echo "Importiere Dump für $db_host ($user)..."
|
|
cat "$DUMP_FILE" | docker exec -i $db_host mysql -u $user -p$pass || echo "Fehler beim Import in $db_host"
|
|
else
|
|
echo "Kein Dump für $db_host gefunden: $DUMP_FILE"
|
|
fi
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# 4. Konfigs wiederherstellen (manuell prüfen!)
|
|
# cp "$BACKUP_DIR/docker-compose.yml" /home/thomas/docker-compose.yml
|
|
# cp "$BACKUP_DIR/nginx.conf" /home/thomas/container/nginx/nginx.conf
|
|
|
|
# 5. Zertifikate (optional)
|
|
# cp -r "$BACKUP_DIR/letsencrypt"/* /etc/letsencrypt/
|
|
|
|
echo "Restore abgeschlossen. Bitte prüfe die Konfigurationen und starte ggf. die Container neu!" |