PostgreSQL backup helper. Portable, single-binary backup & restore with automated restore procedure
MIT License
PostgreSQL simple backup & restore helper tool created for usage with Backup Repository, but can be used also standalone.
Features:
Requirements:
Sensible defaults
Backup & Restore should be simple and fault-tolerant, that's why this tool is automating basic things like disconnecting clients, or connecting to database using an empty database schema during restore - we cannot restore database we connect to, also we cannot recreate from backup something that is in use.
Both pgbr db backup
and pgbr db restore
should work out-of-the-box with sensible defaults.
Selected database or all databases are dumped into a custom formatted
file, readable by pg_restore
.
# for single database "pbr"
pgbr db backup --password riotkit --user riotkit --db-name pbr > dump.gz
# for all databases
pgbr db backup --password riotkit --user riotkit > dump.gz
Procedure:
pg_restore
, which uses --clean
and --create
by defaultcat dump.gz | ./.build/pgbr db restore --password riotkit --user riotkit --connection-database=postgres
Both pgbr db backup
and pgbr db restore
are supporting UNIX-like parameters passing to subprocess, which is pg_dump
/pg_dumpall
for Backup and pg_restore
for Restore.
Example
pgbr db backup --password riotkit --user riotkit -- --role=my-role > dump.gz
pgbr
can rely on your host OS or use docker run
to trigger psql
, pg_dump
, pg_dumpall
or pg_restore
.
In order to use a docker image that will provide client tools you can set those environment variables:
export PGBR_USE_CONTAINER=true
export POSTGRES_VERSION=15
# optional: image name
export PGBR_CONTAINER_IMAGE=my-registry/image-name