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
1420set -euxo pipefail
1521
22+ # Usage
1623if [[ $# -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
1926fi
2027
@@ -24,7 +31,6 @@ NEW_DEPLOYMENT=${2}
2431DUMP_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/||' )
2834oc exec -i deployment/${OLD_DEPLOYMENT} -- bash -c " pg_dump -U \$ {POSTGRES_USER} -d \$ {POSTGRES_DB} -Fc" > ${DUMP_FILE_PATH}
2935ls -lh ${DUMP_FILE_PATH}
3036
0 commit comments