File tree 3 files changed +24
-4
lines changed
3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ Docker image to backup Postgres database to S3 using pg_dump and compress using
10
10
- [x] Compression is done with pigz (parallel gzip)
11
11
- [x] Creates bucket if it's not created
12
12
- [x] Can be run in Kubernetes or Docker
13
- - [ > ] TODO: Add possibility to detect and backup all databases [ planned]
14
- - [ ] TODO: OpenSSL encryption
13
+ - [ ] TODO: Add possibility to detect and backup all databases [ planned]
14
+ - [x] PGP encryption
15
15
- [ ] TODO: Add other compression methods
16
16
- [ ] TODO: Add other dbs (e.g. postgres, mysql)
17
17
@@ -21,6 +21,8 @@ S3_BUCK=postgres1-backups
21
21
S3_NAME=folder-name/backup-name-prefix
22
22
S3_URI=https://s3-key:
[email protected]
23
23
PG_URI=postgres://mongo-host:5432/db-name
24
+ GPG_KEYSERVER=keyserver.ubuntu.com # your hpks keyserver
25
+ GPG_KEYID=< key_id> # recipient key, backup will be encrypted if added
24
26
```
25
27
26
28
Or see ` docker-compose.yml ` file to run this container with Docker.
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ services:
5
5
image : backuptools/postgres-backup-s3
6
6
build : .
7
7
environment :
8
- - S3_BUCK=mongo1 -backups
8
+ - S3_BUCK=postgres1 -backups
9
9
- S3_NAME=folder-name/backup-name-prefix
10
10
-
S3_URI=https://s3-key:[email protected]
11
11
- PG_URI=postgres://pg-user:pg-password@postgres-host:5432/db-name
Original file line number Diff line number Diff line change @@ -7,12 +7,30 @@ get_date () {
7
7
}
8
8
9
9
# Script
10
+ : ${GPG_KEYSERVER:= ' keyserver.ubuntu.com' }
11
+ : ${GPG_KEYID:= ' ' }
12
+
13
+ if [ -z " $GPG_KEYID " ]
14
+ then
15
+ echo " $( get_date) !WARNING! It's strongly recommended to encrypt your backups."
16
+ else
17
+ echo " $( get_date) Preparing keys: importing from keyserver"
18
+ gpg --keyserver ${GPG_KEYSERVER} --recv-keys ${GPG_KEYID}
19
+ fi
20
+
10
21
echo " $( get_date) Postgres backup started"
11
22
12
23
export MC_HOST_backup=$S3_URI
13
24
14
25
mc mb backup/${S3_BUCK} --insecure
15
26
16
- pg_dump $PG_URI | pigz -9 | mc pipe backup/${S3_BUCK} /${S3_NAME} -` date +%Y-%m-%d_%H-%M-%S` .pgdump --insecure
27
+ if [ -z " $GPG_KEYID " ]
28
+ then
29
+ pg_dump $PG_URI | pigz -9 | mc pipe backup/${S3_BUCK} /${S3_NAME} -` date +%Y-%m-%d_%H-%M-%S` .pgdump --insecure
30
+ else
31
+ pg_dump $PG_URI | pigz -9 \
32
+ | gpg --encrypt -z 0 --recipient ${GPG_KEYID} --trust-model always \
33
+ | mc pipe backup/${S3_BUCK} /${S3_NAME} -` date +%Y-%m-%d_%H-%M-%S` .pgdump.pgp --insecure
34
+ fi
17
35
18
36
echo " $( get_date) Postgres backup completed successfully"
You can’t perform that action at this time.
0 commit comments