Skip to content

Commit 253eb80

Browse files
authored
Update upgrade_postgres.sh
1 parent ddef269 commit 253eb80

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

on-prem-installers/onprem/upgrade_postgres.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
podname="postgresql-0"
87
postgres_namespace=orch-database
9-
POSTGRES_LOCAL_BACKUP_PATH="./"
8+
POSTGRES_LOCAL_BACKUP_PATH="./"
109
local_backup_file="${postgres_namespace}_backup.sql"
1110
local_backup_path="${POSTGRES_LOCAL_BACKUP_PATH}${local_backup_file}"
12-
POSTGRES_USERNAME="postgres"
11+
POSTGRES_USERNAME="postgres"
1312
application_namespace=onprem
1413

14+
if [[ "$UPGRADE_3_1_X" == "true" ]]; then
15+
podname="postgresql-0"
16+
else
17+
podname="postgresql-cluster-1"
18+
fi
19+
1520
check_postgres() {
1621
if [[ -f "$local_backup_path" ]]; then
17-
read -rp "A backfile file already exists.
22+
read -rp "A backfile file already exists.
1823
If you would like to continue using this backup file type Continue :
1924
" confirm && [[ $confirm == [cC][oO][nN][tT][iI][nN][uU][eE] ]] || exit 1
2025
# avoid the rest of the check function as this could be a recovery from a failed update
@@ -49,7 +54,7 @@ backup_postgres() {
4954
fi
5055
echo "Backing up databases from pod $podname in namespace $postgres_namespace..."
5156

52-
remote_backup_path="/tmp/${postgres_namespace}_backup.sql"
57+
remote_backup_path="/var/lib/postgresql/data/${postgres_namespace}_backup.sql"
5358
kubectl exec -n $postgres_namespace $podname -- /bin/bash -c "$(typeset -f disable_security); disable_security"
5459

5560
if kubectl exec -n $postgres_namespace $podname -- /bin/bash -c "pg_dumpall -U $POSTGRES_USERNAME -f '$remote_backup_path'"; then
@@ -99,11 +104,15 @@ restore_postgres() {
99104
echo "Restoring backup databases from pod $podname in namespace $postgres_namespace..."
100105

101106
# Get postgres password from secret
102-
PGPASSWORD=$(kubectl get secret -n $postgres_namespace postgresql -o jsonpath='{.data.postgres-password}' | base64 -d)
107+
if [[ "$UPGRADE_3_1_X" == "true" ]]; then
108+
PGPASSWORD=$(kubectl get secret -n $postgres_namespace postgresql -o jsonpath='{.data.postgres-password}' | base64 -d)
109+
else
110+
PGPASSWORD=$(kubectl get secret -n $postgres_namespace orch-database-postgresql -o jsonpath='{.data.password}' | base64 -d)
111+
fi
103112

104113
# CloudNativePG doesn't need security disable/enable, just use credentials
105114
# Use the remote backup file that was copied to the pod
106115
kubectl exec -n $postgres_namespace "$podname" -c postgres -- env PGPASSWORD="$PGPASSWORD" psql -U $POSTGRES_USERNAME -f "$remote_backup_path"
107116

108117
echo "Restore completed successfully."
109-
}
118+
}

0 commit comments

Comments
 (0)