Backup and restore¶
What is protected how¶
| Data | Mechanism | RPO |
|---|---|---|
| Postgres (users, runs, metrics, audit, queue) | nightly pg_dump -Fc by the backup service, verified with pg_restore --list, gpg AES-256 encrypted, sha256 file, 14-day retention |
24 h |
MinIO hibiscus-datasets, hibiscus-artifacts |
bucket versioning (overwrites/deletes recoverable for HIBISCUS_NONCURRENT_EXPIRE_DAYS, default 30) |
0 for logical mistakes |
| MinIO against disk loss | weekly deploy/backup/minio-mirror.sh to another disk/NAS, every object gpg-encrypted |
7 days |
hibiscus-uploads |
not backed up (transient, expires after 14 days) | — |
| Redis | not backed up (rate-limit counters, pub/sub, caches only; AOF on its volume) | — |
| Prometheus/Loki/Grafana | not backed up (dashboards are provisioned from git) | — |
Put HIBISCUS_BACKUP_DIR on a different physical disk than Docker's data-root.
Encryption key (SEC-infra-2)¶
Backups leave the database and MinIO volumes, so they are encrypted at rest: OpenPGP symmetric
encryption (gpg --symmetric, AES-256, SHA-512 S2K, MDC integrity check) with the passphrase in
HIBISCUS_BACKUP_PASSPHRASE (deploy/.env, generated by deploy/scripts/gen-secrets.sh;
helpers in deploy/backup/crypt.sh). Plaintext never reaches HIBISCUS_BACKUP_DIR or the mirror
destination: the dump is written to a private temp directory inside the backup container,
verified, encrypted, decrypted again and compared before it is published. The scripts refuse to
run without a passphrase.
- Store a copy of the passphrase off this host (password manager / sealed envelope). A lost passphrase means every backup is lost; losing the host disk must not take the key with it.
- Rotation: put the new value in
deploy/.envanddocker compose up -d backup. Old dumps stay readable with the old passphrase only — keep it until they have aged out (14 days), and run the mirror with--removeinto a fresh directory to re-encrypt the MinIO copy. - Manual decrypt (any gpg >= 2.2):
gpg --decrypt --pinentry-mode loopback FILE.dump.gpg > FILE.dump.
Nightly Postgres dump¶
The backup service (postgres:16 image, deploy/backup/backup-loop.sh) runs
pg-backup.sh every day at HIBISCUS_BACKUP_AT (default 03:15, container TZ). Files:
$HIBISCUS_BACKUP_DIR/hibiscus-hibiscus-20261116T201500Z.dump.gpg # encrypted
$HIBISCUS_BACKUP_DIR/hibiscus-hibiscus-20261116T201500Z.dump.gpg.sha256 # of the .gpg file
$HIBISCUS_BACKUP_DIR/last-success # epoch seconds of the last good dump
The container turns unhealthy when no dump succeeded for 26 h (backup-health.sh); make ps
shows it and the Grafana "Targets up"/Docker health panels surface it. Manual dump: make backup-now.
Restore drill (monthly; does not touch production)¶
make restore-drill DUMP=$HIBISCUS_BACKUP_DIR/hibiscus-hibiscus-<stamp>.dump.gpg
docker compose --project-directory deploy exec postgres psql -U postgres -d hibiscus_restore_drill \
-c "select count(*) from runs; select count(*) from users;"
docker compose --project-directory deploy exec postgres psql -U postgres -c "drop database hibiscus_restore_drill"
This path is exercised by deploy/tests/test_postgres_backup_restore.py against a real
Postgres 16 with the full contract schema (dump → encrypt → sha256 → decrypt → restore into a
scratch DB → row counts, ownership and monitoring grants identical; tampered file, wrong or
missing passphrase are rejected).
In-place restore¶
It verifies the sha256, decrypts into a private temp file with HIBISCUS_BACKUP_PASSPHRASE (from
the environment, else deploy/.env; needs gpg on the host), stops proxy api worker-* backup, drops and recreates hibiscus owned by
the app role, pg_restore --single-transaction --exit-on-error --no-owner --role=hibiscus, prints
the table count, and starts the services again. Runs that were active at dump time come back
in their old states; the reaper re-queues those whose lease expired (ADR-0002). MinIO objects
newer than the dump are orphans and harmless.
MinIO¶
- Undelete / previous version:
docker compose --project-directory deploy run --rm --entrypoint sh minio-init -c 'mc alias set lt http://minio:9000 $MINIO_ROOT_USER $MINIO_ROOT_PASSWORD && mc ls --versions lt/hibiscus-artifacts/<prefix>'thenmc cp --version-id <id> .... - Off-disk mirror (weekly systemd timer, as the deploy user):
# /etc/systemd/system/hibiscus-minio-mirror.service
[Service]
Type=oneshot
User=hibiscus
WorkingDirectory=/opt/hibiscus
ExecStart=/opt/hibiscus/deploy/backup/minio-mirror.sh /mnt/backup/hibiscus-minio
# /etc/systemd/system/hibiscus-minio-mirror.timer
[Timer]
OnCalendar=Sun 04:30
Persistent=true
[Install]
WantedBy=timers.target
The mirror holds <bucket>/<key>.gpg (+ a keyed-hash .gpg.etag used to skip unchanged
objects); nothing in it is readable without the passphrase.
Restore from the mirror (decrypt to a plaintext tree on the server's own disk, push it back, delete the plaintext):
deploy/backup/decrypt-tree.sh /mnt/backup/hibiscus-minio /srv/restore/minio # passphrase from deploy/.env
docker run --rm --network hibiscus_data -v /srv/restore/minio:/restore:ro \
-e MC_HOST_lt="http://<MINIO_ROOT_USER>:<MINIO_ROOT_PASSWORD>@minio:9000" --entrypoint sh <mc image> \
-c 'for b in hibiscus-datasets hibiscus-artifacts; do mc mirror --overwrite /restore/$b lt/$b; done'
rm -rf /srv/restore/minio
This round trip (encrypt, incremental re-run, --remove, decrypt) is exercised by
test_minio_mirror_is_encrypted_incremental_and_restorable.