Deploy: taeglicher pg_dump-Backup ausserhalb des Containers (Host-Verzeichnis, Rotation 14 Tage)
This commit is contained in:
parent
da70bbfac3
commit
8378296b6e
|
|
@ -0,0 +1,30 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# ITSM: taeglicher PostgreSQL-Backup, ausserhalb des Containers auf dem Host
|
||||||
|
# abgelegt (Verzeichnis unter /docker/itsm/backups, kein Docker-Volume).
|
||||||
|
# Grund: das Live-Datenverzeichnis (pgdata) ist zwar schon ein Host-Bind-Mount,
|
||||||
|
# schuetzt aber nicht vor Korruption oder versehentlichem Loeschen -- ein
|
||||||
|
# separater, komprimierter Dump-Snapshot ist der eigentliche Wiederherstellungs-
|
||||||
|
# punkt (Nutzer-Vorgabe 2026-07-13: "nichtveraenderliche Daten ausserhalb des
|
||||||
|
# Docker-Containers").
|
||||||
|
#
|
||||||
|
# Aufruf per Cron (siehe crontab -l), z. B. taeglich 03:00 UTC:
|
||||||
|
# 0 3 * * * /docker/itsm/backup.sh >> /docker/itsm/backup.log 2>&1
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BACKUP_DIR=/docker/itsm/backups
|
||||||
|
RETAIN_DAYS=14
|
||||||
|
STAMP=$(date -u +%Y%m%d-%H%M%S)
|
||||||
|
OUT="$BACKUP_DIR/itsm-$STAMP.sql.gz"
|
||||||
|
|
||||||
|
mkdir -p "$BACKUP_DIR"
|
||||||
|
|
||||||
|
echo "[backup] $(date -u) -- starte Dump nach $OUT"
|
||||||
|
docker exec itsm_postgres pg_dump -U itsm -d itsm | gzip > "$OUT.tmp"
|
||||||
|
mv "$OUT.tmp" "$OUT"
|
||||||
|
echo "[backup] fertig: $(du -h "$OUT" | cut -f1)"
|
||||||
|
|
||||||
|
echo "[backup] entferne Backups aelter als $RETAIN_DAYS Tage"
|
||||||
|
find "$BACKUP_DIR" -name 'itsm-*.sql.gz' -mtime +"$RETAIN_DAYS" -print -delete
|
||||||
|
|
||||||
|
echo "[backup] aktueller Bestand:"
|
||||||
|
ls -lh "$BACKUP_DIR" | tail -n +2
|
||||||
Loading…
Reference in New Issue