Proxmos Hostbackup hinzugefügt
All checks were successful
ci/woodpecker/push/default Pipeline was successful

This commit is contained in:
Daniel Spittank 2024-07-15 15:03:51 +02:00
parent d2d637d59b
commit e95aa289a0

View File

@ -0,0 +1,63 @@
# Host auf PBS sichern
Wenn man einen PBS betreibt, ist das Sichern des PVE-Hosts (oder jeder anderen Linux-Maschine) ein Kinderspiel.
## Skript
``` bash
#!/bin/bash
# Datei, die analysiert werden soll
CONFIG_FILE="/etc/pve/storage.cfg"
# Initialisieren der Variablen
PBS_NAME=""
PBS_DS=""
PBS_IP=""
PBS_FINGERPRINT=""
PBS_NAMESPACE=""
PBS_USERNAME=""
# Lesen der Datei Zeile für Zeile
while IFS= read -r line
do
# Prüfen, ob die Zeile mit "pbs: " beginnt
if [[ $line == pbs:* ]]; then
# Extrahieren des PBS-Namens
PBS_NAME=$(echo $line | awk '{print $2}')
fi
# Prüfen und Extrahieren der entsprechenden Eigenschaften
if [[ $PBS_NAME != "" ]]; then
if [[ $line == *datastore* ]]; then
PBS_DS=$(echo $line | awk '{print $2}')
elif [[ $line == *server* ]]; then
PBS_IP=$(echo $line | awk '{print $2}')
elif [[ $line == *fingerprint* ]]; then
PBS_FINGERPRINT=$(echo $line | awk '{print $2}')
elif [[ $line == *namespace* ]]; then
PBS_NAMESPACE=$(echo $line | awk '{print $2}')
elif [[ $line == *username* ]]; then
PBS_USERNAME=$(echo $line | awk '{print $2}')
# Da wir den ersten pbs-Eintrag gefunden haben, können wir abbrechen
break
fi
fi
done < "$CONFIG_FILE"
export PBS_REPOSITORY="$PBS_USERNAME@$PBS_IP:$PBS_DS"
export PBS_PASSWORD=$(cat "/etc/pve/priv/storage/$PBS_NAME.pw")
export PBS_REPOSITORY
export PBS_PASSWORD
export PBS_FINGERPRINT
proxmox-backup-client backup root.pxar:/ --keyfile /etc/pve/priv/storage/$PBS_NAME.enc --include-dev /etc/pve --ns $PBS_NAMESPACE
```
!!!tip
Das Skript verarbeitet automatisch die erste auf dem Host vorgefundene PBS-Storage-Konfiguration und nutzt deren Daten.
## Automatisierung
Das Skript kann natürlich auch als Cronjob regelmäßig ausgeführt werden
Quelle der Idee: [Proxmox-Forum](https://forum.proxmox.com/threads/anleitung-sicherung-des-pve-hosts-mit-dem-proxmox-backup-server.110972/)