Remove oracle_funcs.sh for RSC

This commit is contained in:
2025-10-15 10:09:36 +01:00
parent 185238e95d
commit 7ed76ad0d3
7 changed files with 286 additions and 20 deletions

View File

@@ -5,7 +5,7 @@
#
# Perfoms a database clone operation
#
# usage: rsc_clone.sh -n <newname> -o <optionsfile> -h <targethost> [-s sourcehost] [-t "YYYY-MM-DD HH:MM:SS"] <srcdb>
# usage: rsc_clone.sh -n <newname> -o <optionsfile> -h <targethost> [-s sourcehost] [-t "YYYY-MM-DD HH:MM:SS"] [-d] <srcdb>
#
# Options:
# -n <newname> : db_name / SID of the new cloned database
@@ -13,6 +13,7 @@
# -h <targethost> : Target host where the cloned database will be created
# -s <sourcehost> : Source host where the original database is located (optional, use when there is ambiguity)
# -t "YYYY-MM-DD HH:MM:SS" : Optional timestamp for the recovery point, defaults to latest PIT
# -d : Dry-run mode - show mutation variables without executing the clone
# <srcdb> : Source database name or RSC dbid (if known, can be used directly)
#
# Example options file content:
@@ -22,14 +23,13 @@
# DB_CREATE_FILE_DEST=/u01/app/oracle/oradata/NEWNAME/
# AUDIT_FILE_DEST='/u01/app/oracle/admin/NEWNAME/adump'
usage() { echo "Usage: $0 -n <newname> -o <optionsfile> -h <targethost> [-s sourcehost] [-t "YYYY-MM-DD HH:MM:SS"] <srcdb>" 1>&2; exit 1; }
usage() { echo "Usage: $0 -n <newname> -o <optionsfile> -h <targethost> [-s sourcehost] [-t \"YYYY-MM-DD HH:MM:SS\"] [-d] <srcdb>" 1>&2; exit 1; }
MYDIR="$(dirname "$(realpath "$0")")"
source $MYDIR/oracle_funcs.sh
source $MYDIR/rsc_ops.sh
while getopts "n:o:t:h:s:" o; do
while getopts "n:o:t:h:s:d" o; do
case "${o}" in
n)
newName=${OPTARG}
@@ -46,6 +46,9 @@ while getopts "n:o:t:h:s:" o; do
s)
node_name=${OPTARG}
;;
d)
dryrun=true
;;
*)
usage
;;
@@ -258,15 +261,30 @@ oracleDatabases(filter: $filter) {
gqlVars="$(echo $variables)"
rsc_gql_query
dbid=$(cat /tmp/rbkresponse.$$ | jq -r --arg NODE "$node_name" '.data.oracleDatabases.nodes[] | select(.logicalPath[]?.name | test("^" + $NODE + "(\\.|$)")) | .id')
cdmId=$(cat /tmp/rbkresponse.$$ | jq -r --arg NODE "$node_name" '.data.oracleDatabases.nodes[] | select(.logicalPath[]?.name | test("^" + $NODE + "(\\.|$)")) | .cluster.id')
dbid_count=$(echo "$dbid" | grep -c .)
if [[ "$dbid_count" -ne 1 || -z "$dbid" ]]; then
echo "ERROR: Expected exactly one database running on node '$node_name', found $dbid_count:"
cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | "\(.dbUniqueName) \(.logicalPath[0].name) \(.id)"'
cleanup
exit 4
if [[ -n "$node_name" ]]; then
# Filter by source host if specified
dbid=$(cat /tmp/rbkresponse.$$ | jq -r --arg NODE "$node_name" '.data.oracleDatabases.nodes[] | select(.logicalPath[]?.name | test("^" + $NODE + "(\\.|$)")) | .id')
cdmId=$(cat /tmp/rbkresponse.$$ | jq -r --arg NODE "$node_name" '.data.oracleDatabases.nodes[] | select(.logicalPath[]?.name | test("^" + $NODE + "(\\.|$)")) | .cluster.id')
dbid_count=$(echo "$dbid" | grep -c .)
if [[ "$dbid_count" -ne 1 || -z "$dbid" ]]; then
echo "ERROR: Expected exactly one database running on node '$node_name', found $dbid_count:"
cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | "\(.dbUniqueName) \(.logicalPath[0].name) \(.id)"'
cleanup
exit 4
fi
else
# No source host specified, get all matching databases
dbid=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[].id')
cdmId=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[].cluster.id')
dbid_count=$(echo "$dbid" | grep -c .)
if [[ "$dbid_count" -ne 1 || -z "$dbid" ]]; then
echo "ERROR: Expected exactly one database with name '$1', found $dbid_count:"
cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | "\(.dbUniqueName) \(.logicalPath[0].name) \(.id)"'
cleanup
exit 4
fi
fi
echo "DEBUG: DB ID is $dbid"
@@ -334,6 +352,22 @@ gqlClone='mutation OracleDatabaseExportMutation($input: ExportOracleDatabaseInpu
gqlQuery="$(echo $gqlClone)"
gqlVars="$(echo $variables)"
if [ "$dryrun" = true ]; then
echo "=== DRY-RUN MODE ==="
echo "Would execute the following GraphQL mutation:"
echo
echo "QUERY:"
echo "$gqlQuery"
echo
echo "VARIABLES:"
echo "$gqlVars" | jq .
echo
echo "=== END DRY-RUN ==="
cleanup
exit 0
fi
rsc_gql_query
cat /tmp/rbkresponse.$$ | jq