restore.sh aktualisiert
parent
877661b729
commit
9da41592df
44
restore.sh
44
restore.sh
|
|
@ -15,19 +15,19 @@
|
|||
# --rsync-target Rsync-Ziel auf Backup-Server z.B. /backup/incoming/TNP
|
||||
# --pbs-storage PVE-Storage-ID des PBS-Datastores z.B. pbs-tnp-invest-gmbh
|
||||
#
|
||||
# KEYS – beide werden per Rsync vom PBS-Server geholt (PBS_HOST aus pbs.conf):
|
||||
# PBS Encrypt-Key: /root/Scripte/${DATASTORE}.keyfile → für qmrestore
|
||||
# 7z-Passwort wird per Rsync vom PBS-Server geholt (PBS_HOST aus pbs.conf):
|
||||
# 7z-Passwort: /root/Scripte/password_7z.txt → für 7z-Archiv
|
||||
# Format: "tnp-Invest-GmbH: Passwort123"
|
||||
# PBS Encrypt-Key entfällt – Entschlüsselung läuft über pvesm (Fingerprint in DB)
|
||||
#
|
||||
# VM_IMAGE_DIR wird dynamisch aus dem PVE-Storage-Pfad ermittelt:
|
||||
# pvesh get /storage/${RESTORE_PATH} → path → /mnt/HDD_5TB.1/images/${VM_ID}
|
||||
#
|
||||
# ABLAUF:
|
||||
# [0] Keys holen – Keyfile + 7z-Passwort per Rsync vom PBS-Server
|
||||
# [0] 7z-Passwort holen – password_7z.txt per Rsync vom PBS-Server
|
||||
# [1] Space-Check – Freier Platz auf restore-mount prüfen
|
||||
# [2] VM-ID ermitteln – Original aus Backup-Pfad, Restore-ID ab 1000
|
||||
# [3] qmrestore – Direkt vom PBS-Storage mit --keyfile
|
||||
# [3] qmrestore – Direkt vom PBS-Storage (kein --keyfile nötig)
|
||||
# [4] VM_IMAGE_DIR – Dynamisch aus PVE-Storage-Pfad ermitteln
|
||||
# [5] Images prüfen – Abbruch wenn leer/nicht vorhanden
|
||||
# [6] VM vorbereiten – unlock, cdrom/ide0 entfernen, alle Netzwerkkarten
|
||||
|
|
@ -183,46 +183,28 @@ trap 'STATUS="failed"
|
|||
send_webhook "failed" "Abgebrochen in Zeile $LINENO – $LOG_FILE"' ERR
|
||||
|
||||
# ═════════════════════════════════════════════════════════════════════════════
|
||||
# [0/12] KEYS VOM PBS-SERVER HOLEN
|
||||
# PBS_HOST kommt aus pbs.conf. Beide Dateien werden lokal gecacht.
|
||||
# [0/12] 7Z-PASSWORT VOM PBS-SERVER HOLEN
|
||||
# PBS_HOST kommt aus pbs.conf. Datei wird lokal gecacht.
|
||||
# Bei mehreren VMs desselben Datastores nur einmal geholt.
|
||||
#
|
||||
# PBS Encrypt-Keyfile: /root/Scripte/${DATASTORE}.keyfile → qmrestore --keyfile
|
||||
# 7z-Passwort: /root/Scripte/password_7z.txt → 7z -p
|
||||
# Format: "tnp-Invest-GmbH: Passwort123"
|
||||
#
|
||||
# PBS Encrypt-Key entfällt – Entschlüsselung läuft über den registrierten
|
||||
# pvesm PBS-Storage (Fingerprint ist in bronze.backup.datastore.config hinterlegt
|
||||
# und wurde von Windmill Step C beim pvesm add pbs eingetragen).
|
||||
# ═════════════════════════════════════════════════════════════════════════════
|
||||
echo ""
|
||||
echo "==> [0/12] Keys vom PBS-Server holen ($PBS_HOST)..."
|
||||
echo "==> [0/12] 7z-Passwort vom PBS-Server holen ($PBS_HOST)..."
|
||||
KEY_DIR="/opt/windmill-restore/keys"
|
||||
mkdir -p "$KEY_DIR"
|
||||
chmod 700 "$KEY_DIR"
|
||||
|
||||
# ── PBS Encrypt-Keyfile ───────────────────────────────────────────────────────
|
||||
KEYFILE_LOCAL="${KEY_DIR}/${DATASTORE}.keyfile"
|
||||
if [[ -f "$KEYFILE_LOCAL" && -s "$KEYFILE_LOCAL" ]]; then
|
||||
echo " Keyfile bereits vorhanden: $KEYFILE_LOCAL"
|
||||
else
|
||||
echo " Hole Keyfile: root@${PBS_HOST}:/root/Scripte/${DATASTORE}.keyfile"
|
||||
rsync -az \
|
||||
-e "ssh -o StrictHostKeyChecking=no" \
|
||||
"root@${PBS_HOST}:/root/Scripte/${DATASTORE}.keyfile" \
|
||||
"$KEYFILE_LOCAL" \
|
||||
2>&1
|
||||
chmod 600 "$KEYFILE_LOCAL"
|
||||
echo " Keyfile gespeichert ✓"
|
||||
fi
|
||||
|
||||
[[ ! -f "$KEYFILE_LOCAL" || ! -s "$KEYFILE_LOCAL" ]] && {
|
||||
echo "FEHLER: Keyfile fehlt oder leer für Datastore '$DATASTORE'" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ── 7z-Passwort aus password_7z.txt ──────────────────────────────────────────
|
||||
PW_FILE_LOCAL="${KEY_DIR}/password_7z.txt"
|
||||
if [[ ! -f "$PW_FILE_LOCAL" || ! -s "$PW_FILE_LOCAL" ]]; then
|
||||
echo " Hole password_7z.txt: root@${PBS_HOST}:/root/Scripte/password_7z.txt"
|
||||
rsync -az \
|
||||
-e "ssh -o StrictHostKeyChecking=no" \
|
||||
"root@${PBS_HOST}:/root/Scripte/password_7z.txt" \
|
||||
"$PW_FILE_LOCAL" \
|
||||
2>&1
|
||||
|
|
@ -286,21 +268,19 @@ echo " Restore VM-ID: $VM_ID_RESTORED"
|
|||
# ═════════════════════════════════════════════════════════════════════════════
|
||||
# [3/12] QMRESTORE VOM PBS-STORAGE
|
||||
# --storage aus DB (restore_path), z.B. "5TB.1"
|
||||
# --keyfile lokal gecachtes Keyfile vom PBS-Server
|
||||
# --unique 1 verhindert Konflikte mit bestehenden VM-Configs
|
||||
# Kein --keyfile nötig – Entschlüsselung über registrierten pvesm PBS-Storage
|
||||
# ═════════════════════════════════════════════════════════════════════════════
|
||||
echo ""
|
||||
echo "==> [3/12] qmrestore vom PBS-Storage..."
|
||||
echo " Backup-Ref: $PVE_BACKUP_REF"
|
||||
echo " Storage: $RESTORE_PATH"
|
||||
echo " Keyfile: $KEYFILE_LOCAL"
|
||||
echo " VM-ID: $VM_ID_RESTORED"
|
||||
|
||||
RESTORE_START_INNER=$(date +%s)
|
||||
|
||||
qmrestore "$PVE_BACKUP_REF" "$VM_ID_RESTORED" \
|
||||
--storage "$RESTORE_PATH" \
|
||||
--keyfile "$KEYFILE_LOCAL" \
|
||||
--unique 1 \
|
||||
2>&1
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue