feat(backup): restore subcommand (db + documents), proven on the sandbox

dolibarr-backup.sh restore --db|--docs <ts> --env <e> --yes — the recovery half of
the dedicated backup. DESTRUCTIVE (gated by --yes + explicit --env): scales the app
to 0, then
- --db: DROP OWNED BY <owner_role> CASCADE + pg_restore --no-owner --role (same
  mechanics as sandbox-lifecycle.sh), from s3://.../erp/<env>/db/<ts>.dump;
- --docs: clears /var/www/documents and untars s3://.../erp/<env>/docs/<ts>.tar.gz;
then scales the app back to 1. OWNER_ROLE per env (erp_role / erp_sandbox_role).
The key is the bare <ts> filename from `list`; --db/--docs selects the subpath.

Proven on the sandbox: backup → mutate MAIN_INFO_SOCIETE_NOM to a sentinel →
restore --db → the value reverted to the backup's ('Arcodange'). (First run caught
a path bug — the fetch missed the db/ subdir — now fixed.)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This commit is contained in:
2026-06-30 18:05:19 +02:00
co-authored by Claude Opus 4.7
parent 590dbe1f26
commit a8b80f17e4
2 changed files with 91 additions and 8 deletions
+13 -5
View File
@@ -60,14 +60,22 @@ orchestrator and the scheduled CronJob (see "Automation" below).
(`erp/prod/db/…` 1.2 MB, `erp/prod/docs/…` 12.5 MB). Proven end-to-end live on the
sandbox (dump + tar + GCS upload + retention prune).
## Restore (manual, for now)
## Restore
```sh
# DB: aws s3 cp s3://arcodange-backup/erp/<env>/db/<ts>.dump - | pg_restore -h <host> -U <user> -d <db> --clean
# docs: aws s3 cp s3://arcodange-backup/erp/<env>/docs/<ts>.tar.gz - | tar -C /var/www/documents -xzf -
ops/backup/dolibarr-backup.sh list --env <e> # find the <ts> key
ops/backup/dolibarr-backup.sh restore --db <ts>.dump --env <e> --yes
ops/backup/dolibarr-backup.sh restore --docs <ts>.tar.gz --env <e> --yes
```
The sandbox iso-prod refresh (`ops/sandbox/sandbox-lifecycle.sh`) is the natural
restore-drill bench. A `restore` subcommand is wired next.
**DESTRUCTIVE** (requires `--yes` + an explicit `--env`): scales the app to 0, then
- **`--db`**: `DROP OWNED BY <owner_role> CASCADE` + `pg_restore --no-owner --role`
(same reset mechanics as `ops/sandbox/sandbox-lifecycle.sh`), then scales back;
- **`--docs`**: clears `/var/www/documents` and untars the archive, then scales back.
The key is the bare `<ts>` filename from `list`; `--db`/`--docs` selects the
`db/` or `docs/` subpath. Proven on the sandbox: a mutated `MAIN_INFO_SOCIETE_NOM`
was reverted to the backup's value by `restore --db`.
## Automation — the CronJob (gated on creds)