2024-01-19 07:10:13 +01:00
# PostgreSQL Backup
2024-08-03 02:04:58 +02:00
pg-bkup is a Docker container image that can be used to backup and restore Postgres database. It supports local storage, AWS S3 or any S3 Alternatives for Object Storage, and SSH compatible storage.
2024-08-03 01:18:14 +02:00
It also supports __encrypting__ your backups using GPG.
The [jkaninda/pg-bkup ](https://hub.docker.com/r/jkaninda/pg-bkup ) Docker image can be deployed on Docker, Docker Swarm and Kubernetes.
It handles __recurring__ backups of postgres database on Docker and can be deployed as __CronJob on Kubernetes__ using local, AWS S3 or SSH compatible storage.
It also supports __encrypting__ your backups using GPG.
2023-12-22 07:13:49 +01:00
[](https://github.com/jkaninda/pg-bkup/actions/workflows/build.yml)
2024-01-18 16:08:11 +01:00
[](https://goreportcard.com/report/github.com/jkaninda/pg-bkup)
2023-12-22 07:13:49 +01:00


2023-12-22 10:48:27 +01:00
- Docker
- Kubernetes
2024-08-03 08:23:58 +02:00
## Documentation is found at <https://jkaninda.github.io/pg-bkup>
2023-12-26 21:56:59 +01:00
## Links:
2023-12-22 10:48:27 +01:00
2023-12-22 07:13:49 +01:00
- [Docker Hub ](https://hub.docker.com/r/jkaninda/pg-bkup )
- [Github ](https://github.com/jkaninda/pg-bkup )
2023-12-24 19:08:43 +01:00
## MySQL solution :
2023-12-22 10:48:27 +01:00
- [MySQL ](https://github.com/jkaninda/mysql-bkup )
2023-12-22 07:13:49 +01:00
## Storage:
2024-08-03 01:18:14 +02:00
- Local
- AWS S3 or any S3 Alternatives for Object Storage
- SSH
2024-01-18 16:08:11 +01:00
2024-08-03 01:18:14 +02:00
## Quickstart
2024-01-18 16:08:11 +01:00
2024-08-03 01:18:14 +02:00
### Simple backup using Docker CLI
2024-01-18 16:08:11 +01:00
2024-08-03 01:18:14 +02:00
To run a one time backup, bind your local volume to `/backup` in the container and run the `pg-bkup backup` command:
2024-01-18 16:08:11 +01:00
2024-08-03 01:18:14 +02:00
```shell
docker run --rm --network your_network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=dbhost" \
-e "DB_USERNAME=username" \
-e "DB_PASSWORD=password" \
jkaninda/pg-bkup pg-bkup backup -d database_name
2023-12-22 07:13:49 +01:00
```
2024-02-25 21:38:27 +01:00
2024-08-03 01:18:14 +02:00
Alternatively, pass a `--env-file` in order to use a full config as described below.
2023-12-22 07:13:49 +01:00
2024-08-03 01:18:14 +02:00
### Simple backup in docker compose file
2023-12-22 07:13:49 +01:00
```yaml
services:
pg-bkup:
2024-08-03 01:18:14 +02:00
# In production, it is advised to lock your image tag to a proper
# release version instead of using `latest` .
# Check https://github.com/jkaninda/pg-bkup/releases
# for a list of available releases.
2023-12-24 19:08:43 +01:00
image: jkaninda/pg-bkup
2023-12-22 07:13:49 +01:00
container_name: pg-bkup
command:
- /bin/sh
- -c
2024-08-03 01:18:14 +02:00
- pg-bkup backup
2023-12-22 07:13:49 +01:00
volumes:
- ./backup:/backup
environment:
- DB_PORT=5432
- DB_HOST=postgres
2024-08-03 01:18:14 +02:00
- DB_NAME=foo
- DB_USERNAME=bar
2023-12-22 07:13:49 +01:00
- DB_PASSWORD=password
2024-08-03 01:18:14 +02:00
# pg-bkup container must be connected to the same network with your database
networks:
- web
networks:
web:
2023-12-22 07:13:49 +01:00
```
2024-08-03 01:18:14 +02:00
## Deploy on Kubernetes
2023-12-24 19:08:43 +01:00
2024-08-03 01:18:14 +02:00
For Kubernetes, you don't need to run it in scheduled mode. You can deploy it as CronJob.
2023-12-24 19:08:43 +01:00
2024-08-03 01:18:14 +02:00
### Simple Kubernetes CronJob usage:
2023-12-22 07:13:49 +01:00
```yaml
apiVersion: batch/v1
kind: CronJob
metadata:
2023-12-22 10:19:30 +01:00
name: bkup-job
2023-12-22 07:13:49 +01:00
spec:
2023-12-22 10:19:30 +01:00
schedule: "0 1 * * *"
2023-12-22 07:13:49 +01:00
jobTemplate:
spec:
template:
spec:
containers:
- name: pg-bkup
image: jkaninda/pg-bkup
command:
- /bin/sh
- -c
2024-01-20 14:37:21 +01:00
- pg-bkup backup -s s3 --path /custom_path
2023-12-22 07:13:49 +01:00
env:
- name: DB_PORT
2023-12-22 10:19:30 +01:00
value: "5432"
2023-12-22 07:13:49 +01:00
- name: DB_HOST
2023-12-22 10:19:30 +01:00
value: ""
2023-12-22 07:13:49 +01:00
- name: DB_NAME
2023-12-22 10:19:30 +01:00
value: ""
2023-12-22 07:13:49 +01:00
- name: DB_USERNAME
2023-12-22 10:19:30 +01:00
value: ""
# Please use secret!
2023-12-22 07:13:49 +01:00
- name: DB_PASSWORD
2023-12-22 10:19:30 +01:00
value: ""
2024-08-03 01:18:14 +02:00
- name: AWS_S3_ENDPOINT
value: "https://s3.amazonaws.com"
- name: AWS_S3_BUCKET_NAME
value: "xxx"
- name: AWS_REGION
value: "us-west-2"
- name: AWS_ACCESS_KEY
value: "xxxx"
- name: AWS_SECRET_KEY
value: "xxxx"
- name: AWS_DISABLE_SSL
value: "false"
2024-08-03 08:23:58 +02:00
restartPolicy: Never
```
## Available image registries
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:v1.0
docker pull ghcr.io/jkaninda/pg-bkup:v1.0
2023-12-26 21:56:05 +01:00
```
2024-08-03 08:23:58 +02:00
Documentation references Docker Hub, but all examples will work using ghcr.io just as well.
## Supported Engines
This image is developed and tested against the Docker CE engine and Kubernetes exclusively.
While it may work against different implementations, there are no guarantees about support for non-Docker engines.
## References
We decided to publish this image as a simpler and more lightweight alternative because of the following requirements:
- The original image is based on `ubuntu` and requires additional tools, making it heavy.
- This image is written in Go.
- `arm64` and `arm/v7` architectures are supported.
- Docker in Swarm mode is supported.
- Kubernetes is supported.
2023-12-26 21:56:05 +01:00
## License
This project is licensed under the MIT License. See the LICENSE file for details.
## Authors
**Jonas Kaninda**
- < https: // github . com / jkaninda >
## Copyright
Copyright (c) [2023] [Jonas Kaninda]