diff --git a/postgres-restore-s3/Dockerfile b/postgres-restore-s3/Dockerfile index 501b66d..a0f8ce3 100644 --- a/postgres-restore-s3/Dockerfile +++ b/postgres-restore-s3/Dockerfile @@ -14,6 +14,7 @@ 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 DROP_PUBLIC 'no' ADD restore.sh restore.sh diff --git a/postgres-restore-s3/restore.sh b/postgres-restore-s3/restore.sh index 495c237..0a8adef 100644 --- a/postgres-restore-s3/restore.sh +++ b/postgres-restore-s3/restore.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 @@ -53,11 +59,11 @@ POSTGRES_HOST_OPTS="-h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER" echo "Finding latest backup" -LATEST_BACKUP=$(aws s3 ls s3://$S3_BUCKET/$S3_PREFIX/ | sort | tail -n 1 | awk '{ print $4 }') +LATEST_BACKUP=$(aws $AWS_ARGS s3 ls s3://$S3_BUCKET/$S3_PREFIX/ | sort | tail -n 1 | awk '{ print $4 }') echo "Fetching ${LATEST_BACKUP} from S3" -aws s3 cp s3://$S3_BUCKET/$S3_PREFIX/${LATEST_BACKUP} dump.sql.gz +aws $AWS_ARGS s3 cp s3://$S3_BUCKET/$S3_PREFIX/${LATEST_BACKUP} dump.sql.gz gzip -d dump.sql.gz if [ "${DROP_PUBLIC}" == "yes" ]; then