Skip to content

Commit d7cc513

Browse files
Merge pull request #10 from silinternational/develop
Add option to backup to BackBlaze
2 parents 82f248e + 77bc0e2 commit d7cc513

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
start: restore backup
22

33
restore: db
4-
docker-compose up -d restore
4+
docker compose up -d restore
55

66
backup: db
7-
docker-compose up -d backup
7+
docker compose up -d backup
88

99
db:
10-
docker-compose up -d db
10+
docker compose up -d db
1111

1212
clean:
13-
docker-compose kill
13+
docker compose kill
1414
docker system prune -f

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ Service to backup and/or restore a PostgreSQL database to/from S3
3030

3131
`S3_BUCKET` e.g., _s3://database-backups_ **NOTE: no trailing slash**
3232

33-
>**It's recommended that your S3 bucket have versioning turned on.**
33+
>**It's recommended that your S3 bucket have versioning turned on.** Each backup creates a file of the form _DB_NAME_.sql.gz. If versioning is not turned on, the previous backup file will be replaced with the new one, resulting in a single level of backups.
3434
35+
`B2_BUCKET` (optional) Name of the Backblaze B2 bucket, e.g., _database-backups_. When `B2_BUCKET` is defined, the backup file is copied to the B2 bucket in addition to the S3 bucket.
36+
37+
>**It's recommended that your B2 bucket have versioning and encryption turned on.** Each backup creates a file of the form _DB_NAME_.sql.gz. If versioning is not turned on, the previous backup file will be replaced with the new one, resulting in a single level of backups. Encryption may offer an additional level of protection from attackers. It also has the side effect of preventing downloads of the file via the Backblaze GUI (you'll have to use the `b2` command or the Backblaze API).
38+
39+
`B2_APPLICATION_KEY_ID` (optional; required if `B2_BUCKET` is defined) Backblaze application key ID
40+
41+
`B2_APPLICATION_KEY` (optional; required if `B2_BUCKET` is defined) Backblaze application key secret
42+
43+
`B2_HOST` (optional; required if `B2_BUCKET` is defined) Backblaze B2 bucket's `Endpoint`
3544
## Docker Hub
3645
This image is built automatically on Docker Hub as [silintl/postgresql-backup-restore](https://hub.docker.com/r/silintl/postgresql-backup-restore/)
3746

application/backup.sh

+18
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,22 @@ else
4040
echo "${MYNAME}: Copy backup to ${S3_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds."
4141
fi
4242

43+
if [ "${B2_BUCKET}" != "" ]; then
44+
start=$(date +%s)
45+
s3cmd \
46+
--access_key=${B2_APPLICATION_KEY_ID} \
47+
--secret_key=${B2_APPLICATION_KEY} \
48+
--host=${B2_HOST} \
49+
--host-bucket='%(bucket)s.'"${B2_HOST}" \
50+
put /tmp/${DB_NAME}.sql.gz s3://${B2_BUCKET}/${DB_NAME}.sql.gz
51+
STATUS=$?
52+
end=$(date +%s)
53+
if [ $STATUS -ne 0 ]; then
54+
echo "${MYNAME}: FATAL: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
55+
exit $STATUS
56+
else
57+
echo "${MYNAME}: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds."
58+
fi
59+
fi
60+
4361
echo "${MYNAME}: backup: Completed"

docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '2'
21
services:
32
data:
43
image: silintl/data-volume:latest

local.env.dist

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
AWS_ACCESS_KEY=
22
AWS_SECRET_KEY=
33
S3_BUCKET=
4+
5+
# BackBlaze variables
6+
B2_BUCKET=
7+
B2_APPLICATION_KEY_ID=
8+
B2_APPLICATION_KEY=
9+
B2_HOST=

0 commit comments

Comments
 (0)