entrypoint.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. set -eu
  23. STANZA=briven
  24. LOG="[briven-pgbackrest]"
  25. mkdir -p /var/log/pgbackrest /var/lib/pgbackrest/spool /var/lib/pgbackrest/lock
  26. if pgbackrest --stanza="$STANZA" info >/dev/null 2>&1; then
  27. echo "$LOG stanza '$STANZA' already exists in repo"
  28. else
  29. echo "$LOG creating stanza '$STANZA'"
  30. pgbackrest --stanza="$STANZA" stanza-create
  31. fi
  32. if pgbackrest --stanza="$STANZA" info --output=json 2>/dev/null | grep -q '"type":"full"'; then
  33. echo "$LOG existing full backup found"
  34. else
  35. echo "$LOG no full backup yet; taking initial full (this may take several minutes)"
  36. pgbackrest --stanza="$STANZA" --type=full backup || \
  37. echo "$LOG WARNING: initial full failed; cron nightly full will retry"
  38. fi
  39. echo "$LOG starting crond (schedule from /etc/crontabs/root)"
  40. exec crond -f -L /dev/stdout