Backup-Sidecar: täglicher pg_dump scharf geschaltet
Das dokumentierte Backup lief real nie (stock postgres-Image ohne Cron, backup.sh nirgends eingebunden) -> bei Volume-/Disk-Verlust drohte Totalverlust. - Neuer service "backup" (docker-compose.yml): postgres:16-alpine als Sidecar, taeglicher pg_dump um BACKUP_HOUR (Default 03:00 Europe/Berlin) - backup-loop.sh: abhaengigkeitsfreier Tages-Scheduler (umgeht busybox-cron- Environment-Eigenheiten) - backup.sh korrigiert: laeuft remote gegen PGHOST mit PGPASSWORD; -Fc statt "-Fc | gzip" (war doppelt komprimiert und als .sql.gz nicht restore-bar) -> .dump - BACKUP_HOUR/BACKUP_RETENTION_DAYS konfigurierbar (.env.example) - operations.md: Backup-/Restore-Anleitung an Ist-Zustand angepasst Verifiziert: pg_dump erstellt + pg_restore in frische DB, Daten intakt. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
39e259f3ac
commit
7285ed9cae
5 files changed
+95
-13
No files matched your search
+25
-4
@@ -54,14 +54,35 @@ docker compose exec api node -e "import('@cockpit/db/client').then(async ({ crea
|
||||
|
||||
## Backups (Story 6.3)
|
||||
|
||||
Tägliches `pg_dump` via Cron-Endpoint `POST /internal/cron/pg-dump-backup` mit Bearer-Token.
|
||||
14 Tage Retention. Restore-Drill quartalsweise.
|
||||
Tägliches `pg_dump` läuft im **Backup-Sidecar** (`docker-compose.yml` service `backup`):
|
||||
`scripts/backup-loop.sh` triggert `scripts/backup.sh` einmal pro Tag um
|
||||
`BACKUP_HOUR` (Default 03:00 Europe/Berlin). Dump im **Custom-Format** (`-Fc`,
|
||||
bereits komprimiert) nach `cockpit_backups:/backups` als `cockpit-<ts>.dump`.
|
||||
Retention `BACKUP_RETENTION_DAYS` (Default 14). Nach jedem Lauf ein Heartbeat an
|
||||
`POST /internal/cron/pg-dump-backup` (nur Logging — der Endpoint macht **kein**
|
||||
Backup). Restore-Drill quartalsweise.
|
||||
|
||||
Konfiguration (optional, in `.env.production`): `BACKUP_HOUR`, `BACKUP_RETENTION_DAYS`.
|
||||
|
||||
```bash
|
||||
# Status / letztes Backup ansehen
|
||||
docker compose logs --tail=20 backup
|
||||
docker compose exec backup ls -lh /backups
|
||||
|
||||
# Sofort ein Backup auslösen (außer der Reihe)
|
||||
docker compose exec backup /usr/local/bin/backup.sh
|
||||
```
|
||||
|
||||
### Restore-Anleitung
|
||||
|
||||
1. API stoppen: `docker compose stop api`
|
||||
2. Backup aus `/backups` auswählen.
|
||||
3. Restore in temporäre DB: `docker compose exec postgres pg_restore -U cockpit -d cockpit_restore /backups/<file>.sql.gz`
|
||||
2. Backup aus `/backups` auswählen (`docker compose exec postgres ls -lh /backups`).
|
||||
3. Restore in temporäre DB:
|
||||
```bash
|
||||
docker compose exec postgres createdb -U cockpit cockpit_restore
|
||||
docker compose exec postgres pg_restore -U cockpit -d cockpit_restore /backups/<file>.dump
|
||||
```
|
||||
(In die Produktiv-DB stattdessen mit `--clean --if-exists -d cockpit`.)
|
||||
4. Smoke-Test: `curl http://localhost:3000/api/health`
|
||||
5. API wieder starten: `docker compose start api`
|
||||
|
||||
|
||||
Reference in new issue
Block a user