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"