This Docker image is built on top of the official PostgreSQL 16 image and includes pgBackRest for restoring a local development database from a backup.
To build the Docker image, run the following command in the directory containing the Dockerfile:
docker build -t pg16-restore .To run the container and restore a database from a pgBackRest backup, use the following command:
docker run -d \
--name pg16-restore \
-p 5432:5432 \
-e POSTGRES_PASSWORD=your_password \
-e POSTGRES_USER=your_username \
-v /path/to/pgbackrest.conf:/etc/pgbackrest/pgbackrest.conf \
pg16-restore your_stanza_nameReplace the following:
your_password: Set a password for the PostgreSQL useryour_username: Set the username for the PostgreSQL user (optional, defaults to 'postgres')/path/to/pgbackrest.conf: Path to your pgBackRest configuration fileyour_stanza_name: Name of the stanza to restore
To perform a point-in-time recovery, add the target datetime as the second argument:
docker run -d \
--name pg16-restore \
-p 5432:5432 \
-e POSTGRES_PASSWORD=your_password \
-e POSTGRES_USER=your_username \
-v /path/to/pgbackrest.conf:/etc/pgbackrest/pgbackrest.conf \
pg16-restore your_stanza_name "2024-10-01 12:00:00"After the restore process is complete, you can connect to the PostgreSQL server using the following command:
docker exec -it pg16-restore psql -U your_username your_db- The
POSTGRES_PASSWORDenvironment variable is required. - The
POSTGRES_USERenvironment variable is optional and defaults to 'postgres'. - The pgBackRest configuration file must be mounted at
/etc/pgbackrest/pgbackrest.conf. - This image is intended for restoring a local development database and does not include backup functionality.
- The restored database allows connections from all hosts for testing purposes.
- pgBackRest is removed after the restore process to ensure not accidentally overwrite backups.
- Once a container has started using this image, you cannot move the location of the pgbackrest config file, as it has been mounted. However, it's fine to empty the file after the restore process, as it contains sensitive information.
You can customize the PostgreSQL configuration by modifying the postgresql.conf and pg_hba.conf files in the data directory after the restore process.
If you encounter any issues, check the Docker logs for detailed information about the restore process and any errors:
docker logs pg16-restoreFor more information on pgBackRest configuration and usage, refer to the official pgBackRest documentation.