Skip to content

feat(backup): SET GLOBAL read_only quiesce + PostgreSQL & native DB support#1

Merged
andrewbakercloudscale merged 1 commit into
mainfrom
feat/db-readonly-postgres-native
May 31, 2026
Merged

feat(backup): SET GLOBAL read_only quiesce + PostgreSQL & native DB support#1
andrewbakercloudscale merged 1 commit into
mainfrom
feat/db-readonly-postgres-native

Conversation

@andrewbakercloudscale

Copy link
Copy Markdown
Owner

Summary

Three related improvements to how pi2s3 quiesces a database for a consistent, zero-downtime backup, plus agent-runnable install docs.

1. MySQL/MariaDB: SET GLOBAL read_only instead of FTWRL

Switched the quiesce from FLUSH TABLES WITH READ LOCK to SET GLOBAL read_only=ON (+ super_read_only=ON on MySQL, best-effort — MariaDB has no such variable). Gentler than holding a global read lock and needs no keepalive connection. Held only for the sub-10s sync window, then restored before imaging.

Safety: reads the prior read_only state and only flips it when OFF, so a replica that is already read-only is left untouched. A sentinel file recovers a stale read-only state left by a hard-killed run; the on-exit trap restores read-write on any normal or error exit.

2. PostgreSQL support (zero downtime)

New db_lock_postgres() issues a CHECKPOINT then images the live filesystem — writes are never blocked. WAL crash-recovery makes the single-volume snapshot (data dir incl. pg_wal) consistent on restore. New DB_PG_USER config.

3. Native (non-Docker) DB detection

DB_CONTAINER="auto" now detects native mariadbd/mysqld/postgres host processes, not just Docker containers. Native MySQL/MariaDB previously fell back to stop-the-service downtime; it now uses the zero-downtime path (set DB_ROOT_PASSWORD). New db_resolve_target() resolves engine + location and dispatches.

4. Agent-runnable install

install.sh gains a non-interactive env-var mode (S3_BUCKET/S3_REGION/NTFY_URL + PI2S3_YES). Added AGENTS.md and pi2s3.com/llms.txt so an AI agent pointed at the repo/site can "backup my site with pi2s3" unattended.

Docs (README, config.env.example, website) updated to reflect the real <10s write window and the new Postgres/native support.

Testing

  • shellcheck -x clean on pi-image-backup.sh, lib/containers.sh, website/install (install.sh: only 2 pre-existing SC1090); bash -n passes on all (the CI gate).
  • Unit-tested with mocks: find_db/container_db_engine (8 cases), db_resolve_target (11 branches), db_lock_mysql/db_unlock read-only logic (normal, replica-safe, stale-sentinel recovery, verify-fail, query-fail), and confirm() (4 modes incl. EOF-safe under set -e).
  • Not exercised against a live DB / real S3 (no Linux+partclone+AWS env available locally).

🤖 Generated with Claude Code

…pport

Switch the MySQL/MariaDB consistent-snapshot quiesce from FLUSH TABLES WITH
READ LOCK to SET GLOBAL read_only=ON (plus super_read_only on MySQL,
best-effort). Gentler than a global read lock, needs no keepalive connection.
A server already read-only (e.g. a replica) is left untouched; a sentinel file
recovers a stale read-only state from a hard-killed run, and the on-exit trap
restores read-write on any normal or error exit.

Add engine-aware quiesce: db_resolve_target() detects MySQL/MariaDB or
PostgreSQL, in a Docker container OR natively on the host, and dispatches to
db_lock_mysql() / db_lock_postgres(). PostgreSQL uses CHECKPOINT + WAL
crash-recovery (writes never blocked). Native (non-Docker) databases are now
auto-detected instead of falling back to stop-the-service downtime.

New config: DB_ENGINE, DB_PG_USER. install.sh gains a non-interactive env-var
mode (S3_BUCKET/S3_REGION/NTFY_URL + PI2S3_YES) so an AI agent can install and
back up unattended. Add AGENTS.md and pi2s3.com/llms.txt agent runbooks.

Docs (README, config.env.example, website) updated to reflect the real <10s
write window and the new Postgres/native support.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@andrewbakercloudscale
andrewbakercloudscale merged commit be1da66 into main May 31, 2026
1 check passed
@andrewbakercloudscale
andrewbakercloudscale deleted the feat/db-readonly-postgres-native branch May 31, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant