Files
dm-oracle-clone/oracle_mount.sh
2025-10-03 06:06:30 -04:00

123 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
#
# Perform a Live Mount of an Oracle DB
# v0.2 - James Pattinson - August 2021
#
# usage: oracle_mount.sh [-h <dbhost>] [-d <oracle_home> [-f] <srcSID> <tgtHOSTNAME> <"timestamp">
#
# -d specify $ORACLE_HOME on target - needed for mount of Data Guard DBs
# -f mount files only - do not create database
#
# Timestamp YYYY-MM-DD HH:MM:SS
# Time is passed to 'date' on THIS machine, will use local timezone
MYDIR="$(dirname "$(realpath "$0")")"
# source $MYDIR/rbk_api.conf
source $MYDIR/oracle_funcs.sh
usage() { echo "Usage: $0 [-h <dbhost>] [-d <oracle_home> [-f|-n] <srcSID> <tgtHOSTNAME> <\"timestamp\">" 1>&2
echo "Format Timestamp YYYY-MM-DD HH:MM:SS"
exit 1; }
filesonly=false
while getopts "h:d:f" o; do
case "${o}" in
h)
RBK_HOST=${OPTARG}
;;
f)
filesonly=true
;;
d)
oraclehome=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
RBK_SID=$1
if [ -z "${RBK_SID}" ]; then
usage
fi
RBK_SID=$1
RBK_TGT=$2
echo Connecting to Rubrik with IP $RUBRIK_IP
# API call to list Oracle DBs
find_database
# API call to get the host ID of the target
ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/host?name=$RBK_TGT"
rest_api_get
total=$(cat /tmp/rbkresponse.$$ | jq -r .total)
if [ $total -ne 1 ]; then
echo Target host name of $RBK_TGT does not map to a single host:
cat /tmp/rbkresponse.$$ | jq -r '.data[].name'
exit_with_error
fi
target_id=$(cat /tmp/rbkresponse.$$ | jq -r '.data[0].id')
# convert datestamp from string into milliseconds
datestring=$3
echo requested timestamp is $datestring
ts=$(date -d"$datestring" +%s)
if [ $? -ne 0 ]; then
echo Problem with timestamp
exit_with_error
fi
((millis = $ts * 1000))
if [ ! -z ${oraclehome+x} ]; then
configmap="\"ORACLE_HOME\":\"$oraclehome\""
fi
# API call to perform the mount
PAYLOAD="{\"recoveryPoint\":{\"timestampMs\":$millis},\"targetOracleHostOrRacId\":\"$target_id\",\"targetMountPath\":\"/rbk/\",\"shouldMountFilesOnly\":$filesonly,\"advancedRecoveryConfigMap\":{$configmap}}"
ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/$db_id/mount"
rest_api_post
ENDPOINT=$(cat /tmp/rbkresponse.$$ | jq -r '.links[0].href')
LOOP=0
while true; do
rest_api_get
status=$(cat /tmp/rbkresponse.$$ | jq -r '.status')
if [ $status != "SUCCEEDED" ] && [ $status != "FAILED" ]; then
echo Status is $status, checking in 10 seconds
if [ $status = "RUNNING" ] && [ ${LOOP} -ne 1 ] ; then
LOOP=1
sleep 5
save=$ENDPOINT
ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/mount?source_database_name=$dbname"
rest_api_get
# cat /tmp/rbkresponse.$$ | jq -r '.data[]'
RBK_ID_LV=$(cat /tmp/rbkresponse.$$ | jq -r '.data[] | select(.status=="Mounting") | .id')
ENDPOINT=$save
fi
else
if [ $status != "SUCCEEDED" ]; then
echo LIVE MOUNT FAILED WITH STATUS $status
exit_with_error
else
echo LIVE MOUNT SUCCEEDED
echo "The live mount id is: ${RBK_ID_LV}"
# cat /tmp/rbkresponse.$$ | jq -r ' '
exit 0
fi
fi
sleep 10
done
cleanup