Bash toolkit for safe PostgreSQL backup/restore operations with pgBackRest in Docker Compose, including restore-to-new-volume, shadow validation, controlled cutover, and rollback-friendly workflows.
Running pgbackrest commands is not the hard part. The hard part is operating restores and cutovers safely in production.
This toolkit exists to standardize that operational path:
- backup and restore-point creation
- restore to a new volume (instead of touching production in place)
- shadow validation before cutover
- controlled volume switch and simple rollback
For day-to-day operations, the primary interface is the interactive menu (scripts/pgbackrest-menu.sh), so operators do not need to remember low-level command sequences.
This project is intentionally opinionated for:
- Docker Compose
- a
postgresservice - a
pgbackrestservice - Docker volume-based
PGDATA
It is not trying to be a universal database framework.
- Explicit confirmations for destructive actions
- Refuses deleting current production volume unless explicitly overridden
- Restore-to-new-volume workflow to avoid in-place production overwrite
- Shadow validation before promotion/cutover
- Best-effort cleanup of shadow resources on failure
- Create local config:
cp config/ops.env.example config/ops.env-
Edit
config/ops.envfor your host (DEPLOY_DIR,COMPOSE_FILE,COMPOSE_ENV,PGBR_STANZA, prefixes). -
Verify effective config:
bash scripts/pgbackrest-ops.sh show-config- Run the interactive menu:
bash scripts/pgbackrest-menu.sh- Execute operations from the menu:
1snapshot backup2list backups7restore to new volume8switch production volume9/10inspect or delete volumes safely
Use the menu for regular operations. It wraps restore, validation, and cutover helpers in a guided flow with confirmations.
Direct scripts are still available, but mainly for:
- automation
- non-interactive runs
- advanced troubleshooting
Create snapshot:
bash scripts/pgbackrest-ops.sh snapshot --label "pre_deploy_$(date -u +%Y%m%dT%H%M%SZ)"List backups:
bash scripts/pgbackrest-ops.sh list-backupsRestore latest backup into a new volume and start a shadow Postgres for validation:
bash scripts/pgbackrest-restore-new-volume.sh --latest --new-volume pgrestore_20260314T120000ZPromote restored volume to production:
bash scripts/postgres-switch-volume.sh --to pgrestore_20260314T120000Z --stop-shadowRollback to previous production volume:
bash scripts/postgres-switch-volume.sh --to <previous_volume_name>config/ops.env.example: centralized defaultsscripts/pgbackrest-menu.sh: interactive operations menuscripts/pgbackrest-ops.sh: base operations (snapshot,list-backups,create-restorepoint)scripts/pgbackrest-restore-new-volume.sh: parallel restore + optional shadow validationscripts/postgres-switch-volume.sh: controlled production volume switchscripts/postgres-delete-volume.sh: guarded volume deletionscripts/install-systemd-backups.sh: installs/render systemd timers/servicessystemd/pgbackrest-*.service|timer: systemd templates
Scripts automatically load config/ops.env if it exists.
You can also use an external config file:
export PGBR_OPS_CONFIG=/absolute/path/to/ops.envInstall timers/services:
bash scripts/install-systemd-backups.shUseful installer variables:
DEPLOY_DIRSCRIPT_DST_DIRUNIT_DST_DIRSYSTEMD_UNIT_PREFIXUNIT_TEMPLATE_PREFIX(default:pgbackrest)
- Linux + Bash
- Docker Engine
- Docker Compose v2 (
docker compose) - Permissions to manage Docker containers, networks, and volumes
MIT. See LICENSE.