entrypoint.sh46 lines · main
| 1 | #!/bin/sh |
| 2 | # briven pgBackRest entrypoint — Phase 9 of BACKEND_FORK_BRIEF.md. |
| 3 | # |
| 4 | # What this does (in order): |
| 5 | # 1. Ensure work dirs exist (idempotent). |
| 6 | # 2. Run `stanza-create` if the repo has no stanza yet (idempotent — |
| 7 | # pgbackrest will refuse if a stanza exists with mismatched config). |
| 8 | # 3. Take an initial full backup if none exists, so the first cron `incr` |
| 9 | # has a parent. |
| 10 | # 4. Exec crond in foreground (busybox crond, reading /etc/crontabs/root) |
| 11 | # so the container stays alive and runs the schedule from |
| 12 | # pgbackrest/crontab. |
| 13 | # |
| 14 | # What this does NOT do — known gap tracked in HANDOFF.md: |
| 15 | # - Does not set Postgres `archive_command`. That requires the pgbackrest |
| 16 | # binary inside the db container, which is not present in |
| 17 | # supabase/postgres:15.8.1.085. Without archive_command, RPO degrades |
| 18 | # from "last WAL push" (seconds) to "last cron run" (15 min). To close: |
| 19 | # build a custom db image (supabase/postgres + apk add pgbackrest + |
| 20 | # archive.sql init script that runs `ALTER SYSTEM SET archive_command`). |
| 21 | # Do not build on the deploy host — see docs/DOCKER.md rule 5. |
| 22 | |
| 23 | set -eu |
| 24 | |
| 25 | STANZA=briven |
| 26 | LOG="[briven-pgbackrest]" |
| 27 | |
| 28 | mkdir -p /var/log/pgbackrest /var/lib/pgbackrest/spool /var/lib/pgbackrest/lock |
| 29 | |
| 30 | if pgbackrest --stanza="$STANZA" info >/dev/null 2>&1; then |
| 31 | echo "$LOG stanza '$STANZA' already exists in repo" |
| 32 | else |
| 33 | echo "$LOG creating stanza '$STANZA'" |
| 34 | pgbackrest --stanza="$STANZA" stanza-create |
| 35 | fi |
| 36 | |
| 37 | if pgbackrest --stanza="$STANZA" info --output=json 2>/dev/null | grep -q '"type":"full"'; then |
| 38 | echo "$LOG existing full backup found" |
| 39 | else |
| 40 | echo "$LOG no full backup yet; taking initial full (this may take several minutes)" |
| 41 | pgbackrest --stanza="$STANZA" --type=full backup || \ |
| 42 | echo "$LOG WARNING: initial full failed; cron nightly full will retry" |
| 43 | fi |
| 44 | |
| 45 | echo "$LOG starting crond (schedule from /etc/crontabs/root)" |
| 46 | exec crond -f -L /dev/stdout |