Container image to Backup, Restore and Migrate PostgreSQL database to Local, AWS S3 or SSH, Azure.
100K+
PG-BKUP is a Docker container image designed to backup, restore, and migrate PostgreSQL databases. It supports a variety of storage options and ensures data security through GPG encryption.
PG-BKUP is designed for seamless deployment on Docker and Kubernetes, simplifying PostgreSQL backup, restoration, and migration across environments. It is a lightweight, multi-architecture solution compatible with Docker, Docker Swarm, Kubernetes, and other container orchestration platforms.
Flexible Storage Backends:
Data Security:
Deployment Flexibility:
Notifications:
migrate feature.PG-BKUP isn't just another PostgreSQL backup tool, it's a robust, production-ready solution purpose-built for modern DevOps workflows.
Here’s why developers, sysadmins, and DevOps choose PG-BKUP:
Whether you're backing up a single database, restoring critical data, or migrating across environments, PG-BKUP handles it all with a single, unified CLI no scripting gymnastics required.
Designed to be cloud-native:
Store your backups anywhere:
Stay in the loop with real-time notifications via Telegram and Email. Know immediately when a backup succeeds—or fails.
Written in Go, PG-BKUP is fast, multi-arch compatible (amd64, arm64, arm/v7), and optimized for minimal memory and CPU usage. Ideal for both cloud and edge deployments.
Actively maintained with automated testing, Docker image size optimizations, and verified support across major container platforms.
PG-BKUP supports PostgreSQL versions 9.5 and above, ensuring compatibility with most modern PostgreSQL deployments.
PG-BKUP has been tested and runs successfully on:
To perform a one-time backup, bind your local volume to /backup in the container and run the backup command:
docker run --rm --network your_network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=dbhost" \
-e "DB_PORT=5432" \
-e "DB_USERNAME=username" \
-e "DB_PASSWORD=password" \
jkaninda/pg-bkup backup -d database_name
Alternatively, use an environment file (--env-file) for configuration:
docker run --rm --network your_network_name \
--env-file your-env-file \
-v $PWD/backup:/backup/ \
jkaninda/pg-bkup backup -d database_name
Note: Use
data-onlyflag to back up only the data without schema.
To back up only the schema of a specific database, use the --schema-only flag:
docker run --rm --network your_network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=dbhost" \
-e "DB_PORT=5432" \
-e "DB_USERNAME=username" \
-e "DB_PASSWORD=password" \
jkaninda/pg-bkup backup -d database_name --schema-only
To back up specific tables within a database, use the --tables or -t flag followed by a comma-separated list of table names:
docker run --rm --network your_network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=dbhost" \
-e "DB_PORT=5432" \
-e "DB_USERNAME=username" \
-e "DB_PASSWORD=password" \
jkaninda/pg-bkup backup -d database_name --tables table1,table2
To back up all databases on the server, use the --all-databases or -a flag. By default, this creates individual backup files for each database.
docker run --rm --network your_network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=dbhost" \
-e "DB_PORT=5432" \
-e "DB_USERNAME=username" \
-e "DB_PASSWORD=password" \
jkaninda/pg-bkup backup --all-databases --disable-compression
Note: Use the
--all-in-oneor-Aflag to combine backups into a single file.
The migrate command allows you to transfer a PostgreSQL database from a source to a target database in a single step, combining backup and restore operations.
docker run --rm --network your_network_name \
--env-file your-env \
jkaninda/pg-bkup migrate
Note: Use the
--all-databases(-a) flag to migrate all databases, PG-BKUP supports database creation if it does not exist on the target database.
For database migration, refer to the documentation.
To restore a database, bind your local volume to /backup and run the restore command:
docker run --rm --network your_network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=dbhost" \
-e "DB_PORT=5432" \
-e "DB_USERNAME=username" \
-e "DB_PASSWORD=password" \
jkaninda/pg-bkup restore -d database_name -f backup_file.sql.gz
Below is an example of a docker-compose.yml file for running a one-time backup:
services:
pg-bkup:
# In production, pin your image tag to a specific release version instead of `latest`.
# See available releases: https://github.com/jkaninda/pg-bkup/releases
image: jkaninda/pg-bkup
container_name: pg-bkup
command: backup
volumes:
- ./backup:/backup
environment:
- DB_PORT=5432
- DB_HOST=postgres
- DB_NAME=foo
- DB_USERNAME=bar
- DB_PASSWORD=password
- TZ=Europe/Paris
networks:
- web
networks:
web:
You can schedule recurring backups using the --cron-expression or -e flag:
docker run --rm --network network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=hostname" \
-e "DB_USERNAME=user" \
-e "DB_PASSWORD=password" \
jkaninda/pg-bkup backup -d dbName --cron-expression "@every 15m"
For predefined schedules, refer to the documentation.
PG-BKUP supports backing up multiple PostgreSQL databases in a single run using a configuration file. You can pass the file using the --config or -c flag, or by setting the BACKUP_CONFIG_FILE environment variable.
This is ideal for setups where multiple services or applications each require independent database backups.
Below is a sample config.yaml file that defines multiple databases along with their respective connection and backup settings:
# Optional: Global cron expression for scheduled backups.
# Examples: "@daily", "@every 5m", "0 3 * * *"
cronExpression: ""
databases:
- host: lldap-db # Optional: Overrides DB_HOST or uses DB_HOST_LLDAP.
port: 5432 # Optional: Defaults to 5432. Overrides DB_PORT or uses DB_PORT_LLDAP.
name: lldap # Required: Database name
user: lldap # Optional: Can override via DB_USERNAME or uses DB_USERNAME_LLDAP.
password: password # Optional: Can override via DB_PASSWORD or uses DB_PASSWORD_LLDAP.
path: /s3-path/lldap # Required: Destination path (S3, FTP, SSH, etc.)
- host: keycloak-db
port: 5432
name: keycloak
user: keycloak
password: password
path: /s3-path/keycloak
- host: gitea-db
port: 5432
name: gitea
user: gitea
password: "" # Can be empty or sourced from DB_PASSWORD_GITEA
path: /s3-path/gitea
🔹 Tip: You can override any field using environment variables. For example,
DB_PASSWORD_KEYCLOAKtakes precedence over thepasswordfield for thekeycloakentry.
To run backups using this configuration in Docker Compose:
BACKUP_CONFIG_FILE environment variable or use the -c flag in the command.docker-compose.yamlservices:
pg-bkup:
image: jkaninda/pg-bkup
container_name: pg-bkup
command: backup -c /backup/config.yaml
volumes:
- ./backup:/backup # Backup target directory
- ./config.yaml:/backup/config.yaml # Mount configuration file
environment:
- DB_PASSWORD_GITEA=password
- BACKUP_CRON_EXPRESSION=@daily # Optional: Overrides config file cronExpression
networks:
- web
networks:
web:
⚠️ Ensure the
pg-bkupcontainer shares a network with the target databases to allow proper connectivity.
For Kubernetes, you can deploy pg-bkup as a Job or CronJob. Below are examples for both.
This example defines a one-time backup job:
apiVersion: batch/v1
kind: Job
metadata:
name: backup-job
spec:
ttlSecondsAfterFinished: 100
template:
spec:
containers:
- name: pg-bkup
# Pin the image tag to a specific release version in production.
# See available releases: https://github.com/jkaninda/pg-bkup/releases
image: jkaninda/pg-bkup
command: ["backup", "-d", "db_name"]
resources:
limits:
memory: "128Mi"
cpu: "500m"
env:
- name: DB_HOST
value: "postgres"
- name: DB_USERNAME
value: "postgres"
- name: DB_PASSWORD
value: "password"
volumeMounts:
- mountPath: /backup
name: backup
volumes:
- name: backup
hostPath:
path: /home/toto/backup # Directory location on the host
type: Directory # Optional field
restartPolicy: Never
For scheduled backups, use a CronJob:
apiVersion: batch/v1
kind: CronJob
metadata:
name: pg-bkup-cronjob
spec:
schedule: "0 2 * * *" # Runs daily at 2 AM
jobTemplate:
spec:
template:
spec:
containers:
- name: pg-bkup
image: jkaninda/pg-bkup
command: ["backup", "-d", "db_name"]
env:
- name: DB_HOST
value: "postgres"
- name: DB_USERNAME
value: "postgres"
- name: DB_PASSWORD
value: "password"
volumeMounts:
- mountPath: /backup
name: backup
volumes:
- name: backup
hostPath:
path: /home/toto/backup
type: Directory
restartPolicy: OnFailure
If this project helped you, do not skip on giving it a star on GitHub.Thanks!
This Docker image is published to both Docker Hub and the GitHub container registry.
Depending on your preferences and needs, you can reference both jkaninda/pg-bkup as well as ghcr.io/jkaninda/pg-bkup:
docker pull jkaninda/pg-bkup
docker pull ghcr.io/jkaninda/pg-bkup
Documentation references Docker Hub, but all examples will work using ghcr.io just as well.
We created this image as a simpler and more lightweight alternative to existing solutions. Here’s why:
arm64 and arm/v7 architectures.This project is licensed under the MIT License. See the LICENSE file for details.
Jonas Kaninda
Copyright (c) [2024] [Jonas Kaninda]
Content type
Image
Digest
sha256:25e0f9dbf…
Size
20.5 MB
Last updated
7 months ago
docker pull jkaninda/pg-bkup