From 6c8e853950328e644a0f5d5fd6eb80e017255f57 Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Tue, 4 Jun 2024 16:01:35 -0400 Subject: [PATCH 1/4] add option to backup to BackBlaze --- application/backup.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/application/backup.sh b/application/backup.sh index 74cd505..a3b497a 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -40,4 +40,22 @@ else echo "${MYNAME}: Copy backup to ${S3_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds." fi +if [ "${B2_BUCKET}" != "" ]; then + start=$(date +%s) + s3cmd \ + --access_key=${B2_APPLICATION_KEY_ID} \ + --secret_key=${B2_APPLICATION_KEY} \ + --host=${B2_HOST} \ + --host-bucket='%(bucket)s.'"${B2_HOST}" \ + put /tmp/${DB_NAME}.sql.gz s3://${B2_BUCKET}/${DB_NAME}.sql.gz + STATUS=$? + end=$(date +%s) + if [ $STATUS -ne 0 ]; then + echo "${MYNAME}: FATAL: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." + exit $STATUS + else + echo "${MYNAME}: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds." + fi +fi + echo "${MYNAME}: backup: Completed" From 6c9dde9a5d4347d4c5194202c9c916005795143e Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Tue, 4 Jun 2024 16:40:01 -0400 Subject: [PATCH 2/4] update README with backblaze variables --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f52c514..eedbdc0 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,17 @@ Service to backup and/or restore a PostgreSQL database to/from S3 `S3_BUCKET` e.g., _s3://database-backups_ **NOTE: no trailing slash** ->**It's recommended that your S3 bucket have versioning turned on.** +>**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. +`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. + +>**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). + +`B2_APPLICATION_KEY_ID` (optional; required if `B2_BUCKET` is defined) Backblaze application key ID + +`B2_APPLICATION_KEY` (optional; required if `B2_BUCKET` is defined) Backblaze application key secret + +`B2_HOST` (optional; required if `B2_BUCKET` is defined) Backblaze B2 bucket's `Endpoint` ## Docker Hub This image is built automatically on Docker Hub as [silintl/postgresql-backup-restore](https://hub.docker.com/r/silintl/postgresql-backup-restore/) From f2c39b885c23e167a2ba1d226b01b0998d1d7b03 Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Tue, 4 Jun 2024 16:40:38 -0400 Subject: [PATCH 3/4] update example local.env file with backblaze vars --- local.env.dist | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/local.env.dist b/local.env.dist index 3124830..61d76ff 100644 --- a/local.env.dist +++ b/local.env.dist @@ -1,3 +1,9 @@ AWS_ACCESS_KEY= AWS_SECRET_KEY= S3_BUCKET= + +# BackBlaze variables +B2_BUCKET= +B2_APPLICATION_KEY_ID= +B2_APPLICATION_KEY= +B2_HOST= From 77bc0e20838508b4f9e19f11112a156b0fb927a3 Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Tue, 4 Jun 2024 16:41:55 -0400 Subject: [PATCH 4/4] Fix deprecations --- Makefile | 8 ++++---- docker-compose.yml | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1e27b87..e9d4ea0 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ start: restore backup restore: db - docker-compose up -d restore + docker compose up -d restore backup: db - docker-compose up -d backup + docker compose up -d backup db: - docker-compose up -d db + docker compose up -d db clean: - docker-compose kill + docker compose kill docker system prune -f diff --git a/docker-compose.yml b/docker-compose.yml index 1d39abc..075b007 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '2' services: data: image: silintl/data-volume:latest