bur-cli
BUR-6Run pg_dump, pg_restore, and pg_dumpall in the container
Description
dockerpg.py: thin wrappers that run the Postgres tools inside each container, so each database is dumped by a client of its own major version, and no DB password lives on the host.
dump(container, db, user) -> Popen:docker exec C sh -c 'PGPASSWORD="${POSTGRES_PASSWORD:-}" pg_dump -Fc -U <user> <db>'streamed to stdout.dump_globals(container, user):pg_dumpall --globals-only. Captures the roles, role passwords, and grants that a single-databasepg_dumpleaves out.restore(...):docker exec -i C pg_restore --clean --if-exists --single-transaction -U <user> -d <db>.restore_globals(...):docker exec -i C psql -U <user> -d postgres, applying the globals SQL before the per-database restore.
Acceptance
- dump streams custom-format output without buffering the whole DB; a non-zero exit from
pg_dump,pg_dumpall, orpg_restoresurfaces as an error. - auth works under peer/trust or password (
PGPASSWORDis set unconditionally from the container's own env, and ignored when unused). - restore runs
--single-transaction, so a failed restore rolls back instead of leaving a half-dropped DB. -
restore_globalsis idempotent (an already-existing role is tolerated, not fatal). - verified against both a 15 and a 16 container.
Sub-tickets
0No sub-tickets yet.
Links
No links.
Summary
src/bur/dockerpg.py: thindocker execwrappers so each database is dumped and restored by a client of its own major version, with no DB password on the host.dumpanddump_globalsreturn a streamingPopen(custom-formatpg_dump -Fcandpg_dumpall --globals-only);restoreruns--single-transaction --clean --if-exists, andrestore_globalsapplies globals viapsql -d postgreswith noON_ERROR_STOP.${POSTGRES_PASSWORD:-}, so it works under password auth and is empty/ignored if not needed.check()+DockerCommandErrorraises if a process has a non-zero exit codetests/test_dockerpg.py> uv run ruff check All checks passed! > uv run mypy Success: no issues found in 10 source files > uv run pytest .......................................... [100%] 42 passed in 0.04sCode: https://github.com/jmmd2000/bur-cli/commit/b8e7815ac4806828c6d1e2df3e50ead3cc361d24