Skip to content

Commit

Permalink
Add postgres v17, delete v14
Browse files Browse the repository at this point in the history
  • Loading branch information
th0th committed Nov 25, 2024
1 parent 412add8 commit d2ccb55
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM alpine:3
FROM alpine:edge

WORKDIR /root

RUN apk update && \
apk add bash curl pigz postgresql14-client postgresql15-client postgresql16-client rclone
apk add bash curl pigz postgresql15-client postgresql16-client postgresql17-client rclone

COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
Expand Down
60 changes: 33 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,46 @@
| POSTGRES_PASSWORD || | Postgres server password |
| POSTGRES_PORT | | 5432 | Postgres server port |
| POSTGRES_USER | | postgres | Postgres server user |
| POSTGRES_VERSION | | 16 | Postgres server version (14, 15 or 16) |
| POSTGRES_VERSION | | 17 | Postgres server version (15, 16 or 17) |
| WEBGAZER_HEARTBEAT_URL | | | [WebGazer Heartbeat Monitor](https://www.webgazer.io/services/cron-job-monitoring) URL |

### Running

$ docker run th0th/postgres-s3-backup \
-e AWS_ACCESS_KEY_ID=<aws_access_key_id> \
-e AWS_REGION=<aws_region> \
-e AWS_S3_ENDPOINT=<aws_s3_endpoint> \
-e AWS_S3_STORAGE_CLASS=<aws_s3_storage_class[STANDARD_IA]> \
-e AWS_SECRET_ACCESS_KEY=<aws_secret_access_key> \
-e POSTGRES_DB=<database> \
-e POSTGRES_HOST=<postgres_hostname[postgres]> \
-e POSTGRES_PASSWORD=<postgres_password> \
-e POSTGRES_PORT=<postgres_port[5432]> \
-e POSTGRES_USER=<postgres_user[postgres]> \
-e POSTGRES_VERSION=<postgres_version[15]> \
-e WEBGAZER_HEARTBEAT_URL=<webgazer_heartbeat_url>
```shell
$ docker run \
-e AWS_ACCESS_KEY_ID=<aws_access_key_id> \
-e AWS_REGION=<aws_region> \
-e AWS_S3_ENDPOINT=<aws_s3_endpoint> \
-e AWS_S3_STORAGE_CLASS=<aws_s3_storage_class[STANDARD_IA]> \
-e AWS_SECRET_ACCESS_KEY=<aws_secret_access_key> \
-e POSTGRES_DB=<database> \
-e POSTGRES_HOST=<postgres_hostname[postgres]> \
-e POSTGRES_PASSWORD=<postgres_password> \
-e POSTGRES_PORT=<postgres_port[5432]> \
-e POSTGRES_USER=<postgres_user[postgres]> \
-e POSTGRES_VERSION=<postgres_version[17]> \
-e WEBGAZER_HEARTBEAT_URL=<webgazer_heartbeat_url> \
th0th/postgres-s3-backup
```

### Example

$ docker run th0th/postgres-s3-backup \
-e AWS_ACCESS_KEY_ID=g9XqNnqKmUk6xqwkStkN \
-e AWS_REGION=eu-west-1 \
-e AWS_S3_ENDPOINT=my-bucket/postgres-backup \
-e AWS_S3_STORAGE_CLASS=GLACIER \
-e AWS_SECRET_ACCESS_KEY=GLBZ8mQf27UL57YHbkLhXWtfJWVwtUBbQup6mFzw \
-e POSTGRES_DB=database \
-e POSTGRES_HOST=postgres \
-e POSTGRES_PASSWORD=postgres_password \
-e POSTGRES_PORT=5432 \
-e POSTGRES_USER=postgres_user \
-e POSTGRES_VERSION=15 \
-e WEBGAZER_HEARTBEAT_URL=https://heartbeat.webgazer.io/1-8f713c75d659
```shell
$ docker run \
-e AWS_ACCESS_KEY_ID=g9XqNnqKmUk6xqwkStkN \
-e AWS_REGION=eu-west-1 \
-e AWS_S3_ENDPOINT=my-bucket/postgres-backup \
-e AWS_S3_STORAGE_CLASS=GLACIER \
-e AWS_SECRET_ACCESS_KEY=GLBZ8mQf27UL57YHbkLhXWtfJWVwtUBbQup6mFzw \
-e POSTGRES_DB=database \
-e POSTGRES_HOST=postgres \
-e POSTGRES_PASSWORD=postgres_password \
-e POSTGRES_PORT=5432 \
-e POSTGRES_USER=postgres_user \
-e POSTGRES_VERSION=17 \
-e WEBGAZER_HEARTBEAT_URL=https://heartbeat.webgazer.io/1-8f713c75d659 \
th0th/postgres-s3-backup
```

## Shameless plug

Expand Down
17 changes: 8 additions & 9 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

set -eo pipefail

SECONDS=0
Expand All @@ -17,10 +16,10 @@ AWS_S3_STORAGE_CLASS="${AWS_S3_STORAGE_CLASS:-STANDARD_IA}"
POSTGRES_HOST="${POSTGRES_HOST:-postgres}"
POSTGRES_PORT="${POSTGRES_PORT:-5432}"
POSTGRES_USER="${POSTGRES_USER:-postgres}"
POSTGRES_VERSION="${POSTGRES_VERSION:-16}"
POSTGRES_VERSION="${POSTGRES_VERSION:-17}"

# validate environment variables
POSTGRES_VERSIONS=(14 15 16)
POSTGRES_VERSIONS=(15 16 17)

if [[ ! " ${POSTGRES_VERSIONS[*]} " =~ " ${POSTGRES_VERSION} " ]]; then
echo "error: POSTGRES_VERSION can be one of these: ${POSTGRES_VERSIONS[*]}"
Expand All @@ -32,12 +31,12 @@ BACKUP_FILE_NAME=$(date +"${POSTGRES_DB}-%F_%T.gz")

echo "Dumping the database..."
PGPASSWORD="${POSTGRES_PASSWORD}" "/usr/libexec/postgresql${POSTGRES_VERSION}/pg_dump" \
--host="${POSTGRES_HOST}" \
--port="${POSTGRES_PORT}" \
--username="${POSTGRES_USER}" \
--dbname="${POSTGRES_DB}" \
--format=c \
| pigz --fast > "${BACKUP_FILE_NAME}"
--host="${POSTGRES_HOST}" \
--port="${POSTGRES_PORT}" \
--username="${POSTGRES_USER}" \
--dbname="${POSTGRES_DB}" \
--format=c \
| pigz --fast > "${BACKUP_FILE_NAME}"
echo "Dumping the database... Done."

echo "Uploading to S3..."
Expand Down

0 comments on commit d2ccb55

Please sign in to comment.