Browse Source

Add new environment variable for specifying prefix before filename

pull/113/head
Przemysław Szurmak 6 years ago
parent
commit
5c8d66ba23
  1. 1
      postgres-backup-s3/Dockerfile
  2. 3
      postgres-backup-s3/README.md
  3. 7
      postgres-backup-s3/backup.sh

1
postgres-backup-s3/Dockerfile

@ -18,6 +18,7 @@ ENV S3_PATH 'backup'
ENV S3_ENDPOINT **None** ENV S3_ENDPOINT **None**
ENV S3_S3V4 no ENV S3_S3V4 no
ENV SCHEDULE **None** ENV SCHEDULE **None**
ENV DB_ENV_PREFIX **None**
ADD run.sh run.sh ADD run.sh run.sh
ADD backup.sh backup.sh ADD backup.sh backup.sh

3
postgres-backup-s3/README.md

@ -6,7 +6,7 @@ Backup PostgresSQL to S3 (supports periodic backups)
Docker: Docker:
```sh ```sh
$ docker run -e S3_ACCESS_KEY_ID=key -e S3_SECRET_ACCESS_KEY=secret -e S3_BUCKET=my-bucket -e S3_PREFIX=backup -e POSTGRES_DATABASE=dbname -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_HOST=localhost schickling/postgres-backup-s3
$ docker run -e S3_ACCESS_KEY_ID=key -e S3_SECRET_ACCESS_KEY=secret -e S3_BUCKET=my-bucket -e S3_PREFIX=backup -e POSTGRES_DATABASE=dbname -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_HOST=localhost -e DB_ENV_PREFIX=prod schickling/postgres-backup-s3
``` ```
Docker Compose: Docker Compose:
@ -23,6 +23,7 @@ pgbackups3:
- postgres - postgres
environment: environment:
SCHEDULE: '@daily' SCHEDULE: '@daily'
DB_ENV_PREFIX: 'prod'
S3_REGION: region S3_REGION: region
S3_ACCESS_KEY_ID: key S3_ACCESS_KEY_ID: key
S3_SECRET_ACCESS_KEY: secret S3_SECRET_ACCESS_KEY: secret

7
postgres-backup-s3/backup.sh

@ -49,6 +49,11 @@ else
AWS_ARGS="--endpoint-url ${S3_ENDPOINT}" AWS_ARGS="--endpoint-url ${S3_ENDPOINT}"
fi fi
if [ "${DB_ENV_PREFIX}" = "**None**" ]; then
echo "You need to set the DB_ENV_PREFIX environment variable."
exit 1
fi
# env vars needed for aws tools # env vars needed for aws tools
export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
@ -63,6 +68,6 @@ pg_dump $POSTGRES_HOST_OPTS $POSTGRES_DATABASE | gzip > dump.sql.gz
echo "Uploading dump to $S3_BUCKET" 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
cat dump.sql.gz | aws $AWS_ARGS s3 cp - s3://$S3_BUCKET/$S3_PREFIX/${DB_ENV_PREFIX}_${POSTGRES_DATABASE}_$(date +"%Y-%m-%dT%H_%M_%SZ").sql.gz || exit 2
echo "SQL backup uploaded successfully" echo "SQL backup uploaded successfully"
Loading…
Cancel
Save