Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match the POSTGRES_DB with default pg docker image #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG TARGETARCH
ADD src/install.sh install.sh
RUN sh install.sh && rm install.sh

ENV POSTGRES_DATABASE ''
ENV POSTGRES_DB ''
ENV POSTGRES_HOST ''
ENV POSTGRES_PORT 5432
ENV POSTGRES_USER ''
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
S3_BUCKET: my-bucket
S3_PREFIX: backup
POSTGRES_HOST: postgres
POSTGRES_DATABASE: dbname
POSTGRES_DB: dbname
POSTGRES_USER: user
POSTGRES_PASSWORD: password
```
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ services:
S3_BUCKET:
S3_PREFIX: backup
POSTGRES_HOST: postgres
POSTGRES_DATABASE: postgres
POSTGRES_DB: postgres
POSTGRES_USER: user
POSTGRES_PASSWORD: password
6 changes: 3 additions & 3 deletions src/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ set -o pipefail

source ./env.sh

echo "Creating backup of $POSTGRES_DATABASE database..."
echo "Creating backup of $POSTGRES_DB database..."
pg_dump --format=custom \
-h $POSTGRES_HOST \
-p $POSTGRES_PORT \
-U $POSTGRES_USER \
-d $POSTGRES_DATABASE \
-d $POSTGRES_DB \
$PGDUMP_EXTRA_OPTS \
> db.dump

timestamp=$(date +"%Y-%m-%dT%H:%M:%S")
s3_uri_base="s3://${S3_BUCKET}/${S3_PREFIX}/${POSTGRES_DATABASE}_${timestamp}.dump"
s3_uri_base="s3://${S3_BUCKET}/${S3_PREFIX}/${POSTGRES_DB}_${timestamp}.dump"

if [ -n "$PASSPHRASE" ]; then
echo "Encrypting backup..."
Expand Down
4 changes: 2 additions & 2 deletions src/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ if [ -z "$S3_BUCKET" ]; then
exit 1
fi

if [ -z "$POSTGRES_DATABASE" ]; then
echo "You need to set the POSTGRES_DATABASE environment variable."
if [ -z "$POSTGRES_DB" ]; then
echo "You need to set the POSTGRES_DB environment variable."
exit 1
fi

Expand Down
6 changes: 3 additions & 3 deletions src/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ fi

if [ $# -eq 1 ]; then
timestamp="$1"
key_suffix="${POSTGRES_DATABASE}_${timestamp}${file_type}"
key_suffix="${POSTGRES_DB}_${timestamp}${file_type}"
else
echo "Finding latest backup..."
key_suffix=$(
aws $aws_args s3 ls "${s3_uri_base}/${POSTGRES_DATABASE}" \
aws $aws_args s3 ls "${s3_uri_base}/${POSTGRES_DB}" \
| sort \
| tail -n 1 \
| awk '{ print $4 }'
Expand All @@ -35,7 +35,7 @@ if [ -n "$PASSPHRASE" ]; then
rm db.dump.gpg
fi

conn_opts="-h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -d $POSTGRES_DATABASE"
conn_opts="-h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -d $POSTGRES_DB"

echo "Restoring from backup..."
pg_restore $conn_opts --clean --if-exists db.dump
Expand Down