#!/bin/bash # # Perform a Live Mount of an Oracle DB # v0.2 - James Pattinson - August 2021 # # usage: oracle_mount.sh [-h ] [-d [-f] <"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 #---------------------------------------------------------------------------------------- # Version: Autor: Date: Descrpition: # -------- ------ ----- ------------ # 1.0.0.0 U701053 05.04.23 Modification the search of target_id # When we mount a live mount on the production clusters, rubrik returns the 2 lines # (2 possibilities) and the script did not know which one to choose) # 1.0.0.1 U701053 07.02.25 Modification of the command to find the live mount id (RBK_ID_LV) #---------------------------------------------------------------------------------------- MYDIR="$(dirname "$(realpath "$0")")" # source $MYDIR/rbk_api.conf source $MYDIR/oracle_funcs.sh usage() { echo "Usage: $0 [-h ] [-d [-f|-n] <\"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' fi #echo "##############################################" #cat /tmp/rbkresponse.$$ #echo "##############################################" target_id=$(cat /tmp/rbkresponse.$$ | jq -r '.data[0].id') echo " Target_id : $target_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[]' cat /tmp/rbkresponse.$$ | jq -r '.data[] | "\(.id), \(.status), \(.sourceDatabaseName), \(.creationDate)"' | grep Mounting | grep ${RBK_SID} | sort -k 4 #RBK_ID_LV=$(cat /tmp/rbkresponse.$$ | jq -r '.data[] | select(.status=="Mounting") | .id') RBK_ID_LV=`cat /tmp/rbkresponse.$$ | jq -r '.data[] | "\(.id), \(.status), \(.sourceDatabaseName), \(.creationDate)"' | grep Mounting | grep ${RBK_SID} | sort -k 4 | tail -1 | awk '{print $1}' | sed 's/,$//'` 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