-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ Docker image to backup Postgres database(s) to S3 using pg_dump and compress usi | |
- [x] PGP encryption | ||
- [x] Available `COMPRESS=` methods: pigz, xz, bzip2, lrzip, brotli, zstd | ||
- [x] Ping database before backup | ||
- [x] Github Actions CI/CD | ||
- [ ] TODO: Add other dbs (e.g. postgres, mysql) | ||
- [ ] TODO: Separate definition of HOST, PORT, USERNAME, PASSWORD environment variables as an alternative to PG_URI | ||
|
||
|
@@ -31,6 +32,29 @@ COMPRESS_LEVEL=7 # Compression level of desired compression program | |
|
||
Or see `docker-compose.yml` file to run this container with Docker. | ||
|
||
## Github Actions | ||
```yaml | ||
name: Backup database | ||
on: | ||
schedule: | ||
- cron: '0 15 * * *' | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
backup-prod: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Create backup | ||
uses: BackupTools/postgres-backup-s3@action | ||
with: | ||
s3_buck: 'backups' # s3 bucket name | ||
s3_name: 'service-name/db-name' # optionally nested path to store backups | ||
s3_uri: '${{ secrets.BACKUP_S3_URI }}' # https://s3-key:[email protected] | ||
pg_uri: '${{ secrets.BACKUP_READONLY_URI }}' # postgres://readonly:super-secret@db:5432/postgres | ||
compress: pigz # Available: pigz, xz, bzip2, lrzip, brotli, zstd | ||
|
||
``` | ||
|
||
## Cron backup with kubernetes | ||
|
||
See `kubernetes-cronjob.yml` file. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: "Backup postgres to S3" | ||
description: "Backup postgres to S3 bucket with encryption and compression" | ||
author: JargeZ | ||
branding: | ||
icon: "save" | ||
color: "orange" | ||
runs: | ||
using: "docker" | ||
image: "Dockerfile" | ||
inputs: | ||
gpg_keyserver: | ||
description: "your hpks keyserver" | ||
default: "keyserver.ubuntu.com" | ||
gpg_keyid: | ||
description: "recipient key, backup will be encrypted if added" | ||
compress: | ||
description: "Available: pigz, xz, bzip2, lrzip, brotli, zstd" | ||
default: "pigz" | ||
compress_level: | ||
description: "Compression level of desired compression program" | ||
default: "9" | ||
maintenance_db: | ||
description: | ||
default: "postgres" | ||
s3_uri: | ||
description: "URI of S3 bucket. eg: https://s3-key:[email protected]" | ||
required: true | ||
s3_buck: | ||
description: "S3 bucket name. eg: postgres1-backups" | ||
required: true | ||
s3_name: | ||
description: "S3 path to store backups. eg: backups/db1" | ||
required: true | ||
pg_uri: | ||
description: "Postgres URI. eg: postgres://readonly:super-secret@db:5432/postgres" | ||
required: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters