Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

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

Signed-off-by: Marcel Wagner <[email protected]>
  • Loading branch information
wagmarcel authored and oguzcankirmemis committed Sep 7, 2021
1 parent 6c92bea commit e9d3fcb
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 ${NAMESPACE} get pods --selector=app=${NAMESPACE}-stolon-proxy -o jsonpath='{.items[*].metadata.name}'; then
CONTAINER=$(kubectl -n ${NAMESPACE} get pods --selector=app=${NAMESPACE}-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 ${NAMESPACE} get pods --selector=app=${NAMESPACE}-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 e9d3fcb

Please sign in to comment.