137 lines
4.8 KiB
Bash
137 lines
4.8 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# setup-pbs.sh — richtet einen Proxmox Backup Server als LXC ein.
|
|
# Datastore landet auf der angegebenen (bereits eingebundenen) SSD.
|
|
#
|
|
# Macht NUR additive Dinge: LXC anlegen, PBS installieren, Datastore anlegen,
|
|
# in PVE als Storage einbinden. Fasst KEINE Platten an, loescht nichts,
|
|
# startet KEINE Backups. Das machst du danach bewusst selbst.
|
|
#
|
|
# Auf dem Proxmox-VE-Host als root ausfuehren. Vorher durchlesen.
|
|
|
|
set -euo pipefail
|
|
|
|
[[ $EUID -eq 0 ]] || { echo "Bitte als root ausfuehren."; exit 1; }
|
|
command -v pct >/dev/null || { echo "Kein Proxmox-VE-Host (pct fehlt)."; exit 1; }
|
|
|
|
echo "=== PBS-LXC Setup ==="
|
|
echo
|
|
|
|
# --- datastore-pfad (die neue SSD) ---
|
|
echo "Eingebundene Directory-Storages (Pfad-Spalte):"
|
|
awk '/^dir:/{name=$2} /path /{print " "name" -> "$2}' /etc/pve/storage.cfg || true
|
|
echo
|
|
read -rp "Pfad der SSD fuer den Datastore [/mnt/pve/pbs-ssd]: " DS_PATH
|
|
DS_PATH=${DS_PATH:-/mnt/pve/pbs-ssd}
|
|
[[ -d $DS_PATH ]] || { echo "FEHLER: $DS_PATH existiert nicht. Erst die SSD einbinden."; exit 1; }
|
|
|
|
# --- container-ID (naechste freie als default) ---
|
|
NEXTID=$(pvesh get /cluster/nextid)
|
|
read -rp "Container-ID [$NEXTID]: " CTID
|
|
CTID=${CTID:-$NEXTID}
|
|
|
|
# --- netzwerk (gateway autodetektiert) ---
|
|
GW_DETECT=$(ip route | awk '/default/{print $3; exit}')
|
|
read -rp "Gateway [$GW_DETECT]: " GW
|
|
GW=${GW:-$GW_DETECT}
|
|
read -rp "Bridge [vmbr0]: " BRIDGE
|
|
BRIDGE=${BRIDGE:-vmbr0}
|
|
read -rp "Feste IP fuer PBS inkl. Maske (z.B. 192.168.1.50/24): " CTIP
|
|
[[ -n ${CTIP:-} ]] || { echo "FEHLER: IP erforderlich."; exit 1; }
|
|
IPONLY=${CTIP%%/*}
|
|
|
|
# --- rootfs-storage ---
|
|
read -rp "Storage fuer die Container-rootfs [local-lvm]: " ROOTSTORE
|
|
ROOTSTORE=${ROOTSTORE:-local-lvm}
|
|
|
|
# --- root-passwort fuer den container (= PBS-Login root@pam) ---
|
|
read -rsp "Root-Passwort fuer den PBS-Container: " CTPW; echo
|
|
[[ -n ${CTPW:-} ]] || { echo "FEHLER: Passwort erforderlich."; exit 1; }
|
|
|
|
# --- zusammenfassung + bestaetigung ---
|
|
cat <<SUMMARY
|
|
|
|
Zusammenfassung:
|
|
CTID $CTID
|
|
Hostname pbs
|
|
IP / GW $CTIP / $GW (Bridge $BRIDGE)
|
|
rootfs ${ROOTSTORE}:16 GiB
|
|
Datastore-Pfad $DS_PATH -> im Container /datastore
|
|
Datastore-Name homelab
|
|
|
|
SUMMARY
|
|
read -rp "So anlegen? [y/N]: " OK
|
|
[[ ${OK,,} == y ]] || { echo "Abgebrochen."; exit 0; }
|
|
|
|
# --- debian-13-template sicherstellen ---
|
|
echo ">> Template pruefen/holen ..."
|
|
pveam update >/dev/null 2>&1 || true
|
|
TMPL=$(pveam available --section system | awk '/debian-13-standard/{print $2}' | sort | tail -n1)
|
|
[[ -n $TMPL ]] || { echo "FEHLER: kein debian-13-Template gefunden."; exit 1; }
|
|
pveam list local | grep -q "$TMPL" || pveam download local "$TMPL"
|
|
|
|
# --- LXC anlegen ---
|
|
echo ">> Erstelle LXC $CTID ..."
|
|
pct create "$CTID" "local:vztmpl/$TMPL" \
|
|
--hostname pbs --cores 2 --memory 2048 --swap 512 \
|
|
--rootfs "${ROOTSTORE}:16" --unprivileged 0 \
|
|
--net0 "name=eth0,bridge=${BRIDGE},ip=${CTIP},gw=${GW}" \
|
|
--onboot 1
|
|
|
|
# datastore reinmounten + starten
|
|
pct set "$CTID" -mp0 "${DS_PATH},mp=/datastore"
|
|
pct start "$CTID"
|
|
sleep 5
|
|
pct exec "$CTID" -- bash -c "echo 'root:${CTPW}' | chpasswd"
|
|
|
|
# --- PBS installieren ---
|
|
echo ">> Installiere PBS im Container ..."
|
|
pct exec "$CTID" -- bash -c '
|
|
set -e
|
|
wget -qO /usr/share/keyrings/proxmox-archive-keyring.gpg \
|
|
https://enterprise.proxmox.com/debian/proxmox-archive-keyring-trixie.gpg
|
|
cat > /etc/apt/sources.list.d/pbs.sources <<SRC
|
|
Types: deb
|
|
URIs: http://download.proxmox.com/debian/pbs
|
|
Suites: trixie
|
|
Components: pbs-no-subscription
|
|
Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg
|
|
SRC
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update
|
|
apt-get install -y proxmox-backup-server
|
|
'
|
|
|
|
# --- datastore anlegen ---
|
|
echo ">> Lege Datastore 'homelab' an ..."
|
|
pct exec "$CTID" -- proxmox-backup-manager datastore create homelab /datastore 2>/dev/null \
|
|
|| echo " (Datastore existiert evtl. schon - ok)"
|
|
|
|
# --- in PVE als storage einbinden (fingerprint automatisch) ---
|
|
echo ">> Binde PBS in PVE ein ..."
|
|
FP=$(pct exec "$CTID" -- proxmox-backup-manager cert info | awk -F': ' '/[Ff]ingerprint/{print $2; exit}')
|
|
if [[ -n ${FP:-} ]]; then
|
|
pvesm add pbs pbs --server "$IPONLY" --datastore homelab \
|
|
--username root@pam --password "$CTPW" --fingerprint "$FP" 2>/dev/null \
|
|
&& echo " PVE-Storage 'pbs' angelegt." \
|
|
|| echo " (Storage 'pbs' existiert evtl. schon - ok)"
|
|
else
|
|
echo " Fingerprint nicht automatisch gefunden - bitte manuell einbinden (siehe unten)."
|
|
fi
|
|
|
|
cat <<DONE
|
|
|
|
=== Fertig ===
|
|
PBS-Weboberflaeche: https://${IPONLY}:8007 (Login: root + dein Container-Passwort)
|
|
|
|
Empfohlen jetzt in der PBS-GUI:
|
|
- Datastore 'homelab' -> Prune & GC: keep-last 3, daily 7, weekly 4, monthly 6; GC woechentlich
|
|
- Verify Jobs -> woechentlich
|
|
|
|
Backups starten (bewusst, separat) - alle Gaeste einmalig ins PBS:
|
|
for id in \$(pct list | awk 'NR>1{print \$1}') \$(qm list | awk 'NR>1{print \$1}'); do
|
|
vzdump \$id --mode stop --storage pbs
|
|
done
|
|
|
|
DONE
|