From 46d458a75025e1af253003fb0351ec3ce713a143 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 14:09:10 +0100 Subject: [PATCH 1/4] Added filename but untested --- postgres-backup-s3/Dockerfile | 1 + postgres-backup-s3/README.md | 6 ++++++ postgres-backup-s3/backup.sh | 8 +++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/postgres-backup-s3/Dockerfile b/postgres-backup-s3/Dockerfile index d5eed1c..ac5079f 100644 --- a/postgres-backup-s3/Dockerfile +++ b/postgres-backup-s3/Dockerfile @@ -15,6 +15,7 @@ ENV S3_SECRET_ACCESS_KEY **None** ENV S3_BUCKET **None** ENV S3_REGION us-west-1 ENV S3_PATH 'backup' +ENV S3_FILENAME **None** ENV S3_ENDPOINT **None** ENV S3_S3V4 no ENV SCHEDULE **None** diff --git a/postgres-backup-s3/README.md b/postgres-backup-s3/README.md index a5339de..83c933b 100644 --- a/postgres-backup-s3/README.md +++ b/postgres-backup-s3/README.md @@ -40,3 +40,9 @@ You can additionally set the `SCHEDULE` environment variable like `-e SCHEDULE=" More information about the scheduling can be found [here](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules). +### Overwriting S3 files + +You can use the following environment variable to disable the timestamps and set a custom name for the S3 files. +- `S3_FILENAME` a consistent filename to overwrite with your backup. If not set will use a timestamp. + + diff --git a/postgres-backup-s3/backup.sh b/postgres-backup-s3/backup.sh index 6e5a7f0..5510c01 100644 --- a/postgres-backup-s3/backup.sh +++ b/postgres-backup-s3/backup.sh @@ -63,6 +63,12 @@ pg_dump $POSTGRES_HOST_OPTS $POSTGRES_DATABASE | gzip > dump.sql.gz echo "Uploading dump to $S3_BUCKET" -cat dump.sql.gz | aws $AWS_ARGS s3 cp - s3://$S3_BUCKET/$S3_PREFIX/${POSTGRES_DATABASE}_$(date +"%Y-%m-%dT%H:%M:%SZ").sql.gz || exit 2 +if [ "${S3_FILENAME}" == "**None**" ]; then + S3_UPLOAD_PATH=s3://$S3_BUCKET/$S3_PREFIX/${POSTGRES_DATABASE}_$(date +"%Y-%m-%dT%H:%M:%SZ").sql.gz +else + S3_UPLOAD_PATH=s3://$S3_BUCKET/$S3_PREFIX/${S3_FILENAME}.sql.gz +fi + +cat dump.sql.gz | aws $AWS_ARGS s3 cp - "$S3_UPLOAD_PATH" || exit 2 echo "SQL backup uploaded successfully" From 9df2f693721f666e01ff5906d674791868434d08 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 16:43:43 +0100 Subject: [PATCH 2/4] Fixed build version --- postgres-backup-s3/Dockerfile | 2 ++ postgres-backup-s3/integration-tests.test.yml | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/postgres-backup-s3/Dockerfile b/postgres-backup-s3/Dockerfile index 54fa911..59014f9 100644 --- a/postgres-backup-s3/Dockerfile +++ b/postgres-backup-s3/Dockerfile @@ -25,4 +25,6 @@ ADD backup.sh backup.sh ADD integration-tests.sh integration-tests.sh ADD config/sample_sql_file.sql sample_sql_file.sql + + CMD ["sh", "run.sh"] diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml index 727e4ca..9772ac0 100644 --- a/postgres-backup-s3/integration-tests.test.yml +++ b/postgres-backup-s3/integration-tests.test.yml @@ -7,7 +7,10 @@ services: - POSTGRES_USER=user - PGDATA=/var/lib/postgresql/data/pgdata sut: - build: . + build: + context: . + args: + DOCKER_API_VERSION: "1.37" command: 'sh integration-tests.sh' depends_on: - postgres From 45bbdf5a4e06a42aa4bdac24645a3a9fa8cb0e41 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 17:39:51 +0100 Subject: [PATCH 3/4] Changed version --- postgres-backup-s3/integration-tests.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml index 9772ac0..4e64aa9 100644 --- a/postgres-backup-s3/integration-tests.test.yml +++ b/postgres-backup-s3/integration-tests.test.yml @@ -1,4 +1,4 @@ -version: '3.7' +version: '3.6' services: postgres: image: camptocamp/postgres:9.6 From 693387ec37369f3d12b1e05b98cbf8cdb76c336c Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 18:02:24 +0100 Subject: [PATCH 4/4] Removed some space --- postgres-backup-s3/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/postgres-backup-s3/Dockerfile b/postgres-backup-s3/Dockerfile index 59014f9..54fa911 100644 --- a/postgres-backup-s3/Dockerfile +++ b/postgres-backup-s3/Dockerfile @@ -25,6 +25,4 @@ ADD backup.sh backup.sh ADD integration-tests.sh integration-tests.sh ADD config/sample_sql_file.sql sample_sql_file.sql - - CMD ["sh", "run.sh"]