Bundles the post-2026-04-21 work that built out the two-layer backup architecture (PBS for VM images + restic for file/DB), plus the cross- site mirror and the disaster-recovery runbook. - configs/restic/esh-docker-vm/profiles.yaml: drop the obsolete *_offen_backup_data exclude (offen sidecars retired fleet-wide 2026-04-23; restic now covers the equivalent scope directly). - configs/restic/esh-vm-db/: new profile for the dedicated DB VM (10.0.50.60), with pre-backup pg_dumpall + mongodump hooks. - configs/rsync/: ana-nas → nh3-nas (04:00 daily, runs as lkraven) and nh3-nas → ana-nas (05:00 daily, runs as root because DSM rest-server-nh3 writes mode-400 files only root can read). - docs/runbooks/pbs-deployment.md: 9-phase PBS rollout runbook, refined during the 2026-04-22 deployment with per-hypervisor namespaces, NFSv3 + ZFS-case-insensitivity workaround, and the Synology syno_acl flatten step. - docs/runbooks/disaster-recovery.md: blast-radius runbook ordered Tier 0 → 5 (ana-nas → hypervisors → Docker hosts → VMs → specialty); references incident memory + recovery-step playbooks per consumer.
60 lines
2.2 KiB
Bash
60 lines
2.2 KiB
Bash
#!/bin/bash
|
|
# pre-backup.sh — esh-vm-db.
|
|
# Runs as root from resticprofile's `run-before`.
|
|
#
|
|
# Produces consistent DB dumps in /var/lib/restic/stage/. Two DBs here:
|
|
# - Postgres 15 (port 5432, local) — pg_dumpall all databases
|
|
# - MongoDB (port 27017, local) — mongodump all databases
|
|
#
|
|
# Peer-data DBs (paperless-ng on Postgres) are the primary consumers;
|
|
# raw volume capture isn't in the restic source list so these dumps
|
|
# are the ONLY way restic sees DB data.
|
|
#
|
|
# Errors in individual blocks log a WARN; whole script doesn't abort.
|
|
|
|
set -euo pipefail
|
|
|
|
STAGE=/var/lib/restic/stage
|
|
install -d -o root -g root -m 0700 "$STAGE"
|
|
|
|
log() { printf '%s pre-backup(esh-vm-db): %s\n' "$(date -Is)" "$*"; }
|
|
warn() { printf '%s pre-backup(esh-vm-db): WARN: %s\n' "$(date -Is)" "$*" >&2; }
|
|
|
|
# ---- Postgres ----------------------------------------------------------
|
|
PG_DUMP="$STAGE/pg_dumpall.sql.gz"
|
|
if sudo -u postgres pg_isready -h localhost -p 5432 > /dev/null 2>&1; then
|
|
log "pg_dumpall starting → $PG_DUMP"
|
|
if sudo -u postgres pg_dumpall -h localhost -p 5432 | gzip > "$PG_DUMP.tmp"; then
|
|
mv "$PG_DUMP.tmp" "$PG_DUMP"
|
|
log "pg_dumpall done ($(du -h "$PG_DUMP" | cut -f1))"
|
|
else
|
|
warn "pg_dumpall failed (exit $?); keeping previous dump if any"
|
|
rm -f "$PG_DUMP.tmp"
|
|
fi
|
|
else
|
|
warn "postgres not ready on :5432 — skipping pg_dumpall"
|
|
fi
|
|
|
|
# ---- MongoDB -----------------------------------------------------------
|
|
MONGO_DIR="$STAGE/mongodump"
|
|
if mongosh --quiet --eval 'db.adminCommand({ping: 1}).ok' | grep -q '^1$'; then
|
|
log "mongodump starting → $MONGO_DIR"
|
|
rm -rf "$MONGO_DIR.tmp"
|
|
if mongodump --out "$MONGO_DIR.tmp" > /dev/null 2>&1; then
|
|
rm -rf "$MONGO_DIR"
|
|
mv "$MONGO_DIR.tmp" "$MONGO_DIR"
|
|
log "mongodump done ($(du -sh "$MONGO_DIR" | cut -f1))"
|
|
else
|
|
warn "mongodump failed (exit $?); keeping previous dump if any"
|
|
rm -rf "$MONGO_DIR.tmp"
|
|
fi
|
|
else
|
|
warn "mongo not reachable via mongosh — skipping mongodump"
|
|
fi
|
|
|
|
# ---- Retention on stage dir --------------------------------------------
|
|
# restic dedupes identical dumps at the chunk level, so we can safely keep
|
|
# overwriting the same files. No explicit rotation needed here.
|
|
|
|
log "pre-backup complete"
|