Skip to content
Snippets Groups Projects
Commit 53c5ca4b authored by Elliott Shugerman's avatar Elliott Shugerman
Browse files

share common env var code

parent abbe4b37
Branches master
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ ENV PASSPHRASE ''
ENV BACKUP_KEEP_DAYS ''
ADD src/run.sh run.sh
ADD src/env.sh env.sh
ADD src/backup.sh backup.sh
ADD src/restore.sh restore.sh
......
......@@ -3,51 +3,7 @@
set -eu
set -o pipefail
if [ -z "$S3_BUCKET" ]; then
echo "You need to set the S3_BUCKET environment variable."
exit 1
fi
if [ -z "$POSTGRES_DATABASE" ]; then
echo "You need to set the POSTGRES_DATABASE environment variable."
exit 1
fi
if [ -z "$POSTGRES_HOST" ]; then
if [ -n "$POSTGRES_PORT_5432_TCP_ADDR" ]; then
POSTGRES_HOST=$POSTGRES_PORT_5432_TCP_ADDR
POSTGRES_PORT=$POSTGRES_PORT_5432_TCP_PORT
else
echo "You need to set the POSTGRES_HOST environment variable."
exit 1
fi
fi
if [ -z "$POSTGRES_USER" ]; then
echo "You need to set the POSTGRES_USER environment variable."
exit 1
fi
if [ -z "$POSTGRES_PASSWORD" ]; then
echo "You need to set the POSTGRES_PASSWORD environment variable."
exit 1
fi
if [ -z "$S3_ENDPOINT" ]; then
aws_args=""
else
aws_args="--endpoint-url $S3_ENDPOINT"
fi
if [ -n "$S3_ACCESS_KEY_ID" ]; then
export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID
fi
if [ -n "$S3_SECRET_ACCESS_KEY" ]; then
export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
fi
export AWS_DEFAULT_REGION=$S3_REGION
export PGPASSWORD=$POSTGRES_PASSWORD
source ./env.sh
echo "Creating backup of $POSTGRES_DATABASE database..."
pg_dump --format=custom \
......
if [ -z "$S3_BUCKET" ]; then
echo "You need to set the S3_BUCKET environment variable."
exit 1
fi
if [ -z "$POSTGRES_DATABASE" ]; then
echo "You need to set the POSTGRES_DATABASE environment variable."
exit 1
fi
if [ -z "$POSTGRES_HOST" ]; then
# https://docs.docker.com/network/links/#environment-variables
if [ -n "$POSTGRES_PORT_5432_TCP_ADDR" ]; then
POSTGRES_HOST=$POSTGRES_PORT_5432_TCP_ADDR
POSTGRES_PORT=$POSTGRES_PORT_5432_TCP_PORT
else
echo "You need to set the POSTGRES_HOST environment variable."
exit 1
fi
fi
if [ -z "$POSTGRES_USER" ]; then
echo "You need to set the POSTGRES_USER environment variable."
exit 1
fi
if [ -z "$POSTGRES_PASSWORD" ]; then
echo "You need to set the POSTGRES_PASSWORD environment variable."
exit 1
fi
if [ -z "$S3_ENDPOINT" ]; then
aws_args=""
else
aws_args="--endpoint-url $S3_ENDPOINT"
fi
if [ -n "$S3_ACCESS_KEY_ID" ]; then
export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID
fi
if [ -n "$S3_SECRET_ACCESS_KEY" ]; then
export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
fi
export AWS_DEFAULT_REGION=$S3_REGION
export PGPASSWORD=$POSTGRES_PASSWORD
......@@ -3,52 +3,7 @@
set -u # `-e` omitted intentionally, but i can't remember why exactly :'(
set -o pipefail
if [ -z "$S3_BUCKET" ]; then
echo "You need to set the S3_BUCKET environment variable."
exit 1
fi
if [ -z "$POSTGRES_DATABASE" ]; then
echo "You need to set the POSTGRES_DATABASE environment variable."
exit 1
fi
if [ -z "$POSTGRES_HOST" ]; then
# https://docs.docker.com/network/links/#environment-variables
if [ -n "$POSTGRES_PORT_5432_TCP_ADDR" ]; then
POSTGRES_HOST=$POSTGRES_PORT_5432_TCP_ADDR
POSTGRES_PORT=$POSTGRES_PORT_5432_TCP_PORT
else
echo "You need to set the POSTGRES_HOST environment variable."
exit 1
fi
fi
if [ -z "$POSTGRES_USER" ]; then
echo "You need to set the POSTGRES_USER environment variable."
exit 1
fi
if [ -z "$POSTGRES_PASSWORD" ]; then
echo "You need to set the POSTGRES_PASSWORD environment variable."
exit 1
fi
if [ -z "$S3_ENDPOINT" ]; then
aws_args=""
else
aws_args="--endpoint-url $S3_ENDPOINT"
fi
if [ -n "$S3_ACCESS_KEY_ID" ]; then
export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID
fi
if [ -n "$S3_SECRET_ACCESS_KEY" ]; then
export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
fi
export AWS_DEFAULT_REGION=$S3_REGION
export PGPASSWORD=$POSTGRES_PASSWORD
source ./env.sh
s3_uri_base="s3://${S3_BUCKET}/${S3_PREFIX}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment