Skip to content

Commit

Permalink
Merge pull request #38 from integr8ly/INTLY-2023
Browse files Browse the repository at this point in the history
allow for different postgres versions
  • Loading branch information
pb82 committed May 9, 2019
2 parents 3326c40 + 51c9593 commit 3274958
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN yum --enablerepo=extras install -y epel-release && \
yum install -y --setopt=tsflags=nodocs python-pip mysql && \
yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm && \
yum install -y postgresql96 && \
yum install -y postgresql10 && \
yum clean all && \
pip install -U pip && \
pip install awscli s3cmd && \
Expand Down
23 changes: 17 additions & 6 deletions image/tools/lib/component/postgres.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

function get_postgres_version {
echo "`oc get secret ${COMPONENT_SECRET_NAME} -n ${COMPONENT_SECRET_NAMESPACE} -o jsonpath={.data.POSTGRES_VERSION} | base64 --decode`"
}

function get_postgres_username {
echo "`oc get secret ${COMPONENT_SECRET_NAME} -n ${COMPONENT_SECRET_NAMESPACE} -o jsonpath={.data.POSTGRES_USERNAME} | base64 --decode`"
}
Expand Down Expand Up @@ -27,6 +31,13 @@ function component_dump_data {
local POSTGRES_HOST=$(get_postgres_host)
local POSTGRES_DATABASE=$(get_postgres_database)
local POSTGRES_SUPERUSER=$(get_postgres_superuser)
local POSTGRES_VERSION=$(get_postgres_version)

if [[ -z "$POSTGRES_VERSION" ]]; then
POSTGRES_VERSION=9.6
fi

local POSTGRES_PREFIX="/usr/pgsql-${POSTGRES_VERSION}/bin"

echo "*:5432:*:${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}" > ~/.pgpass
chmod 0600 ~/.pgpass
Expand All @@ -35,19 +46,19 @@ function component_dump_data {
namespace=${POSTGRES_HOST#*.}
namespace=${namespace%.*}

if [ "${POSTGRES_SUPERUSER}" == "true" ]; then
pg_dumpall --clean --if-exists --oids -U ${POSTGRES_USERNAME} -h ${POSTGRES_HOST} | gzip > ${dest}/archives/${namespace}.${ts}.pg_dumpall.gz
if [[ "${POSTGRES_SUPERUSER}" == "true" ]]; then
${POSTGRES_PREFIX}/pg_dumpall --clean --if-exists --oids -U ${POSTGRES_USERNAME} -h ${POSTGRES_HOST} | gzip > ${dest}/archives/${namespace}.${ts}.pg_dumpall.gz
rc=$?
if [ "${rc}" -ne "0" ]; then
if [[ "${rc}" -ne "0" ]]; then
echo "backup of postgresql: FAILED"
exit 1
fi
else
for db in $(psql -U ${POSTGRES_USERNAME} -h ${POSTGRES_HOST} ${POSTGRES_DATABASE} -A -t -c '\l' | cut -f1 -d'|' | grep -v '=' | grep -v 'template'); do
for db in $(${POSTGRES_PREFIX}/psql -U ${POSTGRES_USERNAME} -h ${POSTGRES_HOST} ${POSTGRES_DATABASE} -A -t -c '\l' | cut -f1 -d'|' | grep -v '=' | grep -v 'template'); do
echo "dumping ${db}"
pg_dump --clean --if-exists --oids -U ${POSTGRES_USERNAME} -h ${POSTGRES_HOST} ${db} | gzip > ${dest}/archives/${namespace}.${db}-${ts}.pg_dump.gz
${POSTGRES_PREFIX}/pg_dump --clean --if-exists --oids -U ${POSTGRES_USERNAME} -h ${POSTGRES_HOST} ${db} | gzip > ${dest}/archives/${namespace}.${db}-${ts}.pg_dump.gz
rc=$?
if [ "${rc}" -ne "0" ]; then
if [[ "${rc}" -ne "0" ]]; then
echo "==> Dump $db: FAILED"
exit 1
fi
Expand Down

0 comments on commit 3274958

Please sign in to comment.