Skip to content

Commit ec75310

Browse files
committed
Action
1 parent 18ee2bc commit ec75310

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Docker image to backup Postgres database(s) to S3 using pg_dump and compress usi
1414
- [x] PGP encryption
1515
- [x] Available `COMPRESS=` methods: pigz, xz, bzip2, lrzip, brotli, zstd
1616
- [x] Ping database before backup
17+
- [x] Github Actions CI/CD
1718
- [ ] TODO: Add other dbs (e.g. postgres, mysql)
1819
- [ ] TODO: Separate definition of HOST, PORT, USERNAME, PASSWORD environment variables as an alternative to PG_URI
1920

@@ -31,6 +32,29 @@ COMPRESS_LEVEL=7 # Compression level of desired compression program
3132

3233
Or see `docker-compose.yml` file to run this container with Docker.
3334

35+
## Github Actions
36+
```yaml
37+
name: Backup database
38+
on:
39+
schedule:
40+
- cron: '0 15 * * *'
41+
workflow_dispatch: {}
42+
43+
jobs:
44+
backup-prod:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Create backup
48+
uses: BackupTools/postgres-backup-s3@action
49+
with:
50+
s3_buck: 'backups' # s3 bucket name
51+
s3_name: 'service-name/db-name' # optionally nested path to store backups
52+
s3_uri: '${{ secrets.BACKUP_S3_URI }}' # https://s3-key:[email protected]
53+
pg_uri: '${{ secrets.BACKUP_READONLY_URI }}' # postgres://readonly:super-secret@db:5432/postgres
54+
compress: pigz # Available: pigz, xz, bzip2, lrzip, brotli, zstd
55+
56+
```
57+
3458
## Cron backup with kubernetes
3559

3660
See `kubernetes-cronjob.yml` file.

action.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Backup postgres to S3"
2+
description: "Backup postgres to S3 bucket with encryption and compression"
3+
author: JargeZ
4+
branding:
5+
icon: "save"
6+
color: "orange"
7+
runs:
8+
using: "docker"
9+
image: "Dockerfile"
10+
inputs:
11+
gpg_keyserver:
12+
description: "your hpks keyserver"
13+
default: "keyserver.ubuntu.com"
14+
gpg_keyid:
15+
description: "recipient key, backup will be encrypted if added"
16+
compress:
17+
description: "Available: pigz, xz, bzip2, lrzip, brotli, zstd"
18+
default: "pigz"
19+
compress_level:
20+
description: "Compression level of desired compression program"
21+
default: "9"
22+
maintenance_db:
23+
description:
24+
default: "postgres"
25+
s3_uri:
26+
description: "URI of S3 bucket. eg: https://s3-key:[email protected]"
27+
required: true
28+
s3_buck:
29+
description: "S3 bucket name. eg: postgres1-backups"
30+
required: true
31+
s3_name:
32+
description: "S3 path to store backups. eg: backups/db1"
33+
required: true
34+
pg_uri:
35+
description: "Postgres URI. eg: postgres://readonly:super-secret@db:5432/postgres"
36+
required: true

entrypoint.sh

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ get_date () {
88
}
99

1010
# Script
11-
: ${GPG_KEYSERVER:='keyserver.ubuntu.com'}
12-
: ${GPG_KEYID:=''}
13-
: ${COMPRESS:='pigz'}
14-
: ${COMPRESS_LEVEL:='9'}
15-
: ${MAINTENANCE_DB:='postgres'}
11+
: ${GPG_KEYSERVER:=${INPUT_GPG_KEYSERVER:='keyserver.ubuntu.com'}}
12+
: ${GPG_KEYID:=${INPUT_GPG_KEYID:=''}}
13+
: ${COMPRESS:=${INPUT_COMPRESS:='pigz'}}
14+
: ${COMPRESS_LEVEL:=${INPUT_COMPRESS_LEVEL:='9'}}
15+
: ${MAINTENANCE_DB:=${INPUT_MAINTENANCE_DB:='postgres'}}
16+
: ${S3_URI:=${INPUT_S3_URI:=''}}
17+
: ${S3_BUCK:=${INPUT_S3_BUCK:=''}}
18+
: ${S3_NAME:=${INPUT_S3_NAME:=''}}
19+
: ${PG_URI:=${INPUT_PG_URI:=''}}
1620
START_DATE=`date +%Y-%m-%d_%H-%M-%S`
1721

1822
if [ -z "$GPG_KEYID" ]

0 commit comments

Comments
 (0)