Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github action #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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@master
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.
Expand Down
36 changes: 36 additions & 0 deletions action.yml
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
14 changes: 9 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ get_date () {
}

# Script
: ${GPG_KEYSERVER:='keyserver.ubuntu.com'}
: ${GPG_KEYID:=''}
: ${COMPRESS:='pigz'}
: ${COMPRESS_LEVEL:='9'}
: ${MAINTENANCE_DB:='postgres'}
: ${GPG_KEYSERVER:=${INPUT_GPG_KEYSERVER:='keyserver.ubuntu.com'}}
: ${GPG_KEYID:=${INPUT_GPG_KEYID:=''}}
: ${COMPRESS:=${INPUT_COMPRESS:='pigz'}}
: ${COMPRESS_LEVEL:=${INPUT_COMPRESS_LEVEL:='9'}}
: ${MAINTENANCE_DB:=${INPUT_MAINTENANCE_DB:='postgres'}}
: ${S3_URI:=${INPUT_S3_URI:=''}}
: ${S3_BUCK:=${INPUT_S3_BUCK:=''}}
: ${S3_NAME:=${INPUT_S3_NAME:=''}}
: ${PG_URI:=${INPUT_PG_URI:=''}}
START_DATE=`date +%Y-%m-%d_%H-%M-%S`

if [ -z "$GPG_KEYID" ]
Expand Down