feat(backup): SET GLOBAL read_only quiesce + PostgreSQL & native DB support#1
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_onlyinstead of FTWRLSwitched the quiesce from
FLUSH TABLES WITH READ LOCKtoSET GLOBAL read_only=ON(+super_read_only=ONon 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-10ssyncwindow, then restored before imaging.Safety: reads the prior
read_onlystate 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 aCHECKPOINTthen images the live filesystem — writes are never blocked. WAL crash-recovery makes the single-volume snapshot (data dir incl.pg_wal) consistent on restore. NewDB_PG_USERconfig.3. Native (non-Docker) DB detection
DB_CONTAINER="auto"now detects nativemariadbd/mysqld/postgreshost processes, not just Docker containers. Native MySQL/MariaDB previously fell back to stop-the-service downtime; it now uses the zero-downtime path (setDB_ROOT_PASSWORD). Newdb_resolve_target()resolves engine + location and dispatches.4. Agent-runnable install
install.shgains a non-interactive env-var mode (S3_BUCKET/S3_REGION/NTFY_URL+PI2S3_YES). AddedAGENTS.mdandpi2s3.com/llms.txtso 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 -xclean onpi-image-backup.sh,lib/containers.sh,website/install(install.sh: only 2 pre-existing SC1090);bash -npasses on all (the CI gate).find_db/container_db_engine(8 cases),db_resolve_target(11 branches),db_lock_mysql/db_unlockread-only logic (normal, replica-safe, stale-sentinel recovery, verify-fail, query-fail), andconfirm()(4 modes incl. EOF-safe underset -e).🤖 Generated with Claude Code