check-connection: verify backup namespace exists; flag namespace-not-found

This commit is contained in:
Christoph Haas 2026-09-20 11:53:04 +00:00
parent 0d385480d7
commit 2038e5ef88
2 changed files with 15 additions and 11 deletions

View file

@ -87,8 +87,10 @@ read-only checks:
1. the files `backup.sh` needs (encryption key, exclude list) exist; 1. the files `backup.sh` needs (encryption key, exclude list) exist;
2. `PBS_SERVER:PBS_PORT` is reachable on TCP; 2. `PBS_SERVER:PBS_PORT` is reachable on TCP;
3. an authenticated API round-trip succeeds (it lists existing snapshots for 3. an authenticated API round-trip succeeds — it confirms the token works *and*
this host on the PBS — nothing is written). that the namespace `BACKUP_NS` actually exists on the server (a missing
namespace is reported explicitly, so a new host fails here until its
namespace has been created: `proxmox-backup-client namespace create <ns>`).
It prints a `[ok]` per check and exits 0 on success, 1 on failure: It prints a `[ok]` per check and exits 0 on success, 1 on failure:

View file

@ -8,7 +8,6 @@ source "$SCRIPT_DIR/backup.env"
# ============================================================================== # ==============================================================================
# CONNECTION CHECK # CONNECTION CHECK
# ============================================================================== # ==============================================================================
BACKUP_LABEL="${HOSTNAME}-root"
EXCLUDE_FILE="/opt/backup/exclude" EXCLUDE_FILE="/opt/backup/exclude"
fail() { fail() {
@ -33,17 +32,20 @@ fi
echo "[ok] TCP connection to ${PBS_SERVER}:${PBS_PORT}" echo "[ok] TCP connection to ${PBS_SERVER}:${PBS_PORT}"
echo echo
# 3. Authenticated round-trip: list existing snapshots for this host # 3. Authenticated round-trip + namespace existence: list backups in our namespace
if ! SNAP_OUT="$(timeout 30 proxmox-backup-client snapshot list "host/${BACKUP_LABEL}" --ns "$BACKUP_NS" 2>&1)"; then if ! LIST_OUT="$(timeout 30 proxmox-backup-client list --ns "$BACKUP_NS" 2>&1)"; then
echo "$SNAP_OUT" >&2 if echo "$LIST_OUT" | grep -q "ENOENT"; then
fail "namespace '${BACKUP_NS}' does not exist on ${PBS_SERVER} — create it, or point BACKUP_NS at an existing namespace"
fi
echo "$LIST_OUT" >&2
fail "authenticated request failed — check PBS_AUTH_ID / PBS_PASSWORD in backup.env" fail "authenticated request failed — check PBS_AUTH_ID / PBS_PASSWORD in backup.env"
fi fi
echo "[ok] authentication + API round-trip to the server" echo "[ok] authentication + API round-trip to the server (namespace ${BACKUP_NS} exists)"
if [ -n "$SNAP_OUT" ]; then if [ -n "$LIST_OUT" ]; then
echo "existing snapshots for ${BACKUP_LABEL}:" echo "existing backups in namespace ${BACKUP_NS}:"
echo "$SNAP_OUT" echo "$LIST_OUT"
else else
echo " (none yet for ${BACKUP_LABEL} — the first backup has not run)" echo " (no backups there yet — the first one has not run)"
fi fi
echo echo