Skip to content

Commit

Permalink
Fix backup scripts for stolon
Browse files Browse the repository at this point in the history
See Open-IoT-Service-Platform#463
Close Open-IoT-Service-Platform#472

Signed-off-by: Marcel Wagner <wagmarcel@web.de>
  • Loading branch information
wagmarcel committed Sep 7, 2021
1 parent d061a78 commit a0f6716
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions util/backup/db_dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ fi
TMPDIR=$1
NAMESPACE=$2

if kubectl -n ${NAMESPACE} get pod ${NAMESPACE}-stolon-keeper-0; then
CONTAINER=${NAMESPACE}-stolon-keeper-0
if kubectl -n oisp-staging get pods --selector=app=oisp-staging-stolon-proxy -o jsonpath='{.items[*].metadata.name}'; then
CONTAINER=$(kubectl -n oisp-staging get pods --selector=app=oisp-staging-stolon-proxy -o jsonpath='{.items[*].metadata.name}')
elif kubectl -n ${NAMESPACE} get pod acid-${NAMESPACE}-0; then
CONTAINER=acid-${NAMESPACE}-0
else
Expand Down
10 changes: 5 additions & 5 deletions util/backup/db_restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ fi
TMPDIR=$1
NAMESPACE=$2

if kubectl -n ${NAMESPACE} get pod ${NAMESPACE}-stolon-keeper-0 > /dev/null 2>&1; then
CONTAINER=${NAMESPACE}-stolon-keeper-0
if kubectl -n ${NAMESPACE} get pods --selector=app=${NAMESPACE}-stolon-proxy -o jsonpath='{.items[*].metadata.name}' > /dev/null 2>&1; then
CONTAINER=$(kubectl -n oisp-staging get pods --selector=app=oisp-staging-stolon-proxy -o jsonpath='{.items[*].metadata.name}')
elif kubectl -n ${NAMESPACE} get pod acid-${NAMESPACE}-1 > /dev/null 2>&1; then
CONTAINER=acid-${NAMESPACE}-0
else
Expand Down Expand Up @@ -120,17 +120,17 @@ if [ -z "${DBONLY}" ]; then
echo "password:" ${PASSWORD}
echo "new superpassword:" ${NEW_SUPERPASSWORD}

echo kubectl -n ${NAMESPACE} exec -i ${CONTAINER} -- /bin/bash -c "export PGPASSWORD=${PASSWORD}; export PGSSLMODE=require; psql -h ${HOSTNAME} -U ${USERNAME} -d ${DBNAME}"
echo kubectl -n ${NAMESPACE} exec -i ${CONTAINER} -- /bin/bash -c "export PGPASSWORD=${PASSWORD}; export PGSSLMODE=allow; psql -h ${HOSTNAME} -U ${USERNAME} -d ${DBNAME}"

if (echo "ALTER USER oisp_user WITH PASSWORD '${NEW_USERPASSWORD}';" | kubectl -n ${NAMESPACE} exec -i ${CONTAINER} -- /bin/bash -c "export PGPASSWORD=${PASSWORD}; export PGSSLMODE=require; psql -h ${HOSTNAME} -U ${USERNAME} -d ${DBNAME}"); then
if (echo "ALTER USER oisp_user WITH PASSWORD '${NEW_USERPASSWORD}';" | kubectl -n ${NAMESPACE} exec -i ${CONTAINER} -- /bin/bash -c "export PGPASSWORD=${PASSWORD}; export PGSSLMODE=allow; psql -h ${HOSTNAME} -U ${USERNAME} -d ${DBNAME}"); then
echo "User password changed"
else
echo "Failed to change user password."
exit 1;
fi
echo "Moving on the superuser"

echo "ALTER USER superuser WITH PASSWORD '${NEW_SUPERPASSWORD}';" | kubectl -n ${NAMESPACE} exec -i ${CONTAINER} -- /bin/bash -c "export PGPASSWORD=${PASSWORD}; export PGSSLMODE=require; psql -h ${HOSTNAME} -U ${USERNAME} -d ${DBNAME} -h ${HOSTNAME}"
echo "ALTER USER superuser WITH PASSWORD '${NEW_SUPERPASSWORD}';" | kubectl -n ${NAMESPACE} exec -i ${CONTAINER} -- /bin/bash -c "export PGPASSWORD=${PASSWORD}; export PGSSLMODE=allow; psql -h ${HOSTNAME} -U ${USERNAME} -d ${DBNAME} -h ${HOSTNAME}"
echo "Password restored"
else
SCRIPT_DIR=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
Expand Down

0 comments on commit a0f6716

Please sign in to comment.