An open API service indexing awesome lists of open source software.

https://github.com/riotkit-org/br-pgbr

PostgreSQL backup helper. Portable, single-binary backup & restore with automated restore procedure
https://github.com/riotkit-org/br-pgbr

backup-repository database pgbr pgdump pgrestore pgsql pgsql-backup postgres postgres-backup postgresql psql single-binary

Last synced: 9 days ago
JSON representation

PostgreSQL backup helper. Portable, single-binary backup & restore with automated restore procedure

Awesome Lists containing this project

README

          

pgbr
====

PostgreSQL simple backup & restore helper tool created for usage with Backup Repository, but can be used also standalone.

**Features:**
- Opinionated backup & restore commands basing on PostgreSQL built-in commands

**Requirements:**
- Linux (x86_64/amd64 architecture)
- PostgreSQL in desired version

Conception
----------

**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.

Backup
------

Selected database or all databases are dumped into a `custom formatted` file, readable by `pg_restore`.

```bash
# 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
```

Restore
-------

Procedure:
1) Existing connections to selected one database, or to all databases are terminated
2) Selected database, or all databases are closed for incoming connections
3) Selected database, or all databases are recreated from backup using `pg_restore`, which uses `--clean` and `--create` by default

```bash
cat dump.gz | ./.build/pgbr db restore --password riotkit --user riotkit --connection-database=postgres
```

Passing extra arguments
-----------------------

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**

```bash
pgbr db backup --password riotkit --user riotkit -- --role=my-role > dump.gz
```

Using tooling from docker image
-------------------------------

`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:

```bash
export PGBR_USE_CONTAINER=true
export POSTGRES_VERSION=15

# optional: image name
export PGBR_CONTAINER_IMAGE=my-registry/image-name
```