Skip to content

Commit 5fbae1a

Browse files
committed
Usage
1 parent 2fbc7c1 commit 5fbae1a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

db/db_transfer.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#!/bin/bash
22
#
3-
# Database Upgrade/Migration Script for OpenShift
3+
# Database Transfer Script for OpenShift
44
# Usage:
5-
# ./dbUpgrade.sh <old-deployment-name> <new-deployment-name>
5+
# ./db_transfer.sh <old-deployment-name> <new-deployment-name>
66
#
7-
# This script takes a database dump from the OLD_DEPLOYMENT and restores it into the NEW_DEPLOYMENT.
7+
# This script takes a PostgreSQL database dump from the OLD_DEPLOYMENT and restores it into the NEW_DEPLOYMENT.
88
# Requirements:
9-
# - Both deployments must have running pods with the correct labels.
9+
# - Both deployments must have running pods managed by the given deployment names.
1010
# - The database template should use a PersistentVolumeClaim with a different name for the new deployment.
1111
# - The new deployment should be ready to accept a restore.
12+
# - The script assumes the container name is the default or the first in the pod spec.
13+
#
14+
# Notes:
15+
# - If the target database is not empty, you may see errors like "schema ... already exists".
16+
# These are expected if objects already exist and can usually be ignored, but always review
17+
# the output for unexpected or
1218

1319
# Strict mode with verbose output
1420
set -euxo pipefail
1521

22+
# Usage
1623
if [[ $# -lt 2 ]]; then
17-
echo "Usage: $0 <old-deployment-name> <new-deployment-name>"
24+
grep -v '^#!' "$0" | awk '/^#/ { sub(/^# ?/, ""); print; next } NF==0 { exit }'
1825
exit 1
1926
fi
2027

@@ -24,7 +31,6 @@ NEW_DEPLOYMENT=${2}
2431
DUMP_FILE_PATH=/tmp/backup.dump
2532

2633
# Create dump from the old deployment and save locally
27-
OLD_POD=$(oc get po -l deployment=${OLD_DEPLOYMENT} -o name | head -n 1 | sed 's|pod/||')
2834
oc exec -i deployment/${OLD_DEPLOYMENT} -- bash -c "pg_dump -U \${POSTGRES_USER} -d \${POSTGRES_DB} -Fc" > ${DUMP_FILE_PATH}
2935
ls -lh ${DUMP_FILE_PATH}
3036

0 commit comments

Comments
 (0)