2024-12-06 03:11:49 +01:00
# PG-BKUP
2024-10-10 21:18:36 +02:00
2024-12-06 03:11:49 +01:00
**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.
2023-12-22 07:13:49 +01:00
2024-08-03 08:41:03 +02:00
[](https://github.com/jkaninda/pg-bkup/actions/workflows/release.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


2024-09-05 22:40:36 +02:00
< a href = "https://ko-fi.com/jkaninda" > < img src = "https://uploads-ssl.webflow.com/5c14e387dab576fe667689cf/5cbed8a4ae2b88347c06c923_BuyMeACoffee_blue.png" height = "20" alt = "buy ma a coffee" > < / a >
2024-12-06 03:11:49 +01:00
## Features
- **Storage Options:**
- Local storage
- AWS S3 or any S3-compatible object storage
- FTP
- SSH-compatible storage
2024-12-06 21:27:50 +01:00
- Azure Blob storage
2024-12-06 03:11:49 +01:00
- **Data Security:**
- Backups can be encrypted using **GPG** to ensure confidentiality.
- **Deployment Flexibility:**
- Available as the [jkaninda/pg-bkup ](https://hub.docker.com/r/jkaninda/pg-bkup ) Docker image.
- Deployable on **Docker** , **Docker Swarm** , and **Kubernetes** .
- Supports recurring backups of PostgreSQL databases when deployed:
- On Docker for automated backup schedules.
- As a **Job** or **CronJob** on Kubernetes.
- **Notifications:**
- Get real-time updates on backup success or failure via:
- **Telegram**
- **Email**
## Use Cases
- **Automated Recurring Backups:** Schedule regular backups for PostgreSQL databases.
- **Cross-Environment Migration:** Easily migrate your PostgreSQL databases across different environments using supported storage options.
- **Secure Backup Management:** Protect your data with GPG encryption.
2023-12-22 07:13:49 +01:00
2024-08-15 06:09:06 +02:00
Successfully tested on:
2023-12-22 10:48:27 +01:00
- Docker
2024-08-15 06:09:06 +02:00
- Docker in Swarm mode
2023-12-22 10:48:27 +01:00
- Kubernetes
2024-08-21 03:54:58 +02:00
- OpenShift
2023-12-22 10:48:27 +01:00
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
2024-10-23 10:29:21 +02:00
- SSH remote storage server
- FTP remote storage server
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-10 10:14:33 +02:00
To run a one time backup, bind your local volume to `/backup` in the container and run the `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" \
2024-08-10 09:39:50 +02:00
jkaninda/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-11 09:41:31 +02:00
```yaml
docker run --rm --network your_network_name \
2024-08-11 09:50:12 +02:00
--env-file your-env-file \
2024-08-11 09:41:31 +02:00
-v $PWD/backup:/backup/ \
jkaninda/pg-bkup backup -d database_name
```
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
2024-08-10 09:39:50 +02:00
command: 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-09-30 17:48:23 +02:00
- TZ=Europe/Paris
2024-08-03 01:18:14 +02:00
# pg-bkup container must be connected to the same network with your database
networks:
2024-12-06 03:11:49 +01:00
- web
2024-08-03 01:18:14 +02:00
networks:
web:
2023-12-22 07:13:49 +01:00
```
2024-09-29 06:52:38 +02:00
### Docker recurring backup
```shell
docker run --rm --network network_name \
-v $PWD/backup:/backup/ \
-e "DB_HOST=hostname" \
-e "DB_USERNAME=user" \
-e "DB_PASSWORD=password" \
2024-10-15 16:24:48 +02:00
jkaninda/pg-bkup backup -d dbName --cron-expression "@every 15m" #@midnight
2024-09-29 06:52:38 +02:00
```
See: https://jkaninda.github.io/pg-bkup/reference/#predefined -schedules
2024-08-03 01:18:14 +02:00
## Deploy on Kubernetes
2023-12-24 19:08:43 +01:00
2024-08-14 21:30:29 +02:00
For Kubernetes, you don't need to run it in scheduled mode. You can deploy it as Job or CronJob.
2023-12-24 19:08:43 +01:00
2024-08-14 21:30:29 +02:00
### Simple Kubernetes backup Job :
2023-12-22 07:13:49 +01:00
```yaml
apiVersion: batch/v1
2024-08-14 21:30:29 +02:00
kind: Job
2023-12-22 07:13:49 +01:00
metadata:
2024-08-30 13:47:50 +02:00
name: backup-job
2023-12-22 07:13:49 +01:00
spec:
2024-08-30 13:47:50 +02:00
ttlSecondsAfterFinished: 100
2024-08-14 21:30:29 +02:00
template:
2023-12-22 07:13:49 +01:00
spec:
2024-08-14 21:30:29 +02:00
containers:
2024-08-28 20:27:27 +02:00
- name: pg-bkup
# 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.
image: jkaninda/pg-bkup
command:
- /bin/sh
- -c
2024-08-30 13:47:50 +02:00
- backup -d dbname
2024-08-28 20:27:27 +02:00
resources:
limits:
memory: "128Mi"
cpu: "500m"
env:
- name: DB_HOST
2024-08-30 13:47:50 +02:00
value: "postgres"
2024-08-28 20:27:27 +02:00
- name: DB_USERNAME
2024-08-30 13:47:50 +02:00
value: "postgres"
2024-08-28 20:27:27 +02:00
- name: DB_PASSWORD
2024-08-30 13:47:50 +02:00
value: "password"
volumeMounts:
- mountPath: /backup
name: backup
volumes:
- name: backup
hostPath:
path: /home/toto/backup # directory location on host
type: Directory # this field is optional
restartPolicy: Never
2024-08-03 08:23:58 +02:00
```
## 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` :
```
2024-08-10 11:37:50 +02:00
docker pull jkaninda/pg-bkup
docker pull ghcr.io/jkaninda/pg-bkup
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.
## References
We decided to publish this image as a simpler and more lightweight alternative because of the following requirements:
2024-09-29 20:38:07 +02:00
- The original image is based on `Alpine` and requires additional tools, making it heavy.
2024-08-03 08:23:58 +02:00
- 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]