Skip to content
Snippets Groups Projects
Commit 64f5d0f8 authored by nimrod's avatar nimrod
Browse files

Postgres: Backup and restore scripts.

parent 3537690f
No related branches found
No related tags found
No related merge requests found
Pipeline #3640 passed
FROM docker.io/postgres:16.1-alpine3.19
COPY --chown=root:root healthcheck /usr/local/bin/
COPY --chown=root:root healthcheck backup restore /usr/local/bin/
HEALTHCHECK --start-period=3m CMD healthcheck
# postgres
Just the upstream image but with a healthcheck.
## Backups
The image includes a `backup` and `restore` scripts. The `backup` scripts dumps
all of the databases using `pg_dumpall` and compresses the output using `zstd`
to stdout. This is meant so that backups are run by an external process and it
saves the output to a file, for example:
```
docker exec pg1 backup > /var/backups/pg1/dump.sql.zstd
```
The `restore` script matches the `backup` script in that the it reads a zstd
compress SQL dump from stdin. An example restore:
```
cat dump.sql.zstd | docker exec -i pg2 restore
```
In fact you're able to migrate data from 1 instance to another like so:
```
docker exec pg1 backup | docker exec -i pg2 restore
```
#!/usr/bin/env bash
set -euo pipefail
export PGUSER="${POSTGRES_USER:-postgres}"
pg_dumpall | zstd
#!/usr/bin/env bash
set -euo pipefail
export PGUSER="${POSTGRES_USER:-postgres}"
zstd --decompress - | psql
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment