diff --git a/postgres-backup-s3/Dockerfile b/postgres-backup-s3/Dockerfile index aa95c63..5aaaa2a 100644 --- a/postgres-backup-s3/Dockerfile +++ b/postgres-backup-s3/Dockerfile @@ -15,6 +15,8 @@ ENV S3_SECRET_ACCESS_KEY **None** ENV S3_BUCKET **None** ENV S3_REGION us-west-1 ENV S3_PATH 'backup' +ENV S3_ENDPOINT **None** +ENV S3_S3V4 no ENV SCHEDULE **None** ADD run.sh run.sh diff --git a/postgres-backup-s3/backup.sh b/postgres-backup-s3/backup.sh index c4cbba2..6e5a7f0 100644 --- a/postgres-backup-s3/backup.sh +++ b/postgres-backup-s3/backup.sh @@ -43,6 +43,12 @@ if [ "${POSTGRES_PASSWORD}" = "**None**" ]; then exit 1 fi +if [ "${S3_ENDPOINT}" == "**None**" ]; then + AWS_ARGS="" +else + AWS_ARGS="--endpoint-url ${S3_ENDPOINT}" +fi + # env vars needed for aws tools export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY @@ -57,6 +63,6 @@ pg_dump $POSTGRES_HOST_OPTS $POSTGRES_DATABASE | gzip > dump.sql.gz echo "Uploading dump to $S3_BUCKET" -cat dump.sql.gz | aws s3 cp - s3://$S3_BUCKET/$S3_PREFIX/${POSTGRES_DATABASE}_$(date +"%Y-%m-%dT%H:%M:%SZ").sql.gz || exit 2 +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 echo "SQL backup uploaded successfully" diff --git a/postgres-backup-s3/run.sh b/postgres-backup-s3/run.sh index 05dfcaa..8cc86cc 100644 --- a/postgres-backup-s3/run.sh +++ b/postgres-backup-s3/run.sh @@ -2,6 +2,10 @@ set -e +if [ "${S3_S3V4}" = "yes"]; then + aws configure set default.s3.signature_version s3v4 +fi + if [ "${SCHEDULE}" = "**None**" ]; then sh backup.sh else