Files
dm-oracle-clone/fromDmOct2025/v930p2/check_recoverable_range_debug2.sh

103 lines
3.3 KiB
Bash

#!/bin/bash
#
# Fetch recoverable ranges for a given Oracle DB
# v0.2 - James Pattinson - August 2021
# v0.3 - Gerald Bailat - november 2024 - Add the option -R to see the recoverable range of the replicated backupfile
#
# usage: oracle_get_rr.sh [-h <dbhost>|local] <SID>
SCRIPT=`basename $0`
echo "script ${SCRIPT}"
MYDIR="$(dirname "$(realpath "$0")")"
# source $MYDIR/rbk_api.conf
source $MYDIR/oracle_funcs.sh
usage() { echo "Usage: $0 [-h <dbhost>|local] <SID>" 1>&2; exit 1; }
while getopts "h:" o; do
case "${o}" in
h)
RBK_HOST=${OPTARG}
RBK_HOST_TXT="${RBK_HOST}"
if [ "${RBK_HOST}" = "local" ] ; then
echo " The script will look for the “recoverable range” from the system where the script is executed"
RBK_HOST=""
fi
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
RBK_SID=$1
if [ -z "${RBK_SID}" ]; then
usage
exit 1
fi
if [ `ps -ef | grep ora_pmon_$RBK_SID | grep -v " grep " | wc -l` -eq 0 ]; then
#echo "Sid: $db is down, `hostname -s` "
ROLE="unknown"
STATUS=down
else
#echo "Sid: $db is up, `hostname -s` "
if [ `ps -ef | grep ora_arc[0-9]_$RBK_SID | grep -v " grep " | wc -l` -eq 0 ]; then
STATUS="no-/mnt"
else
STATUS=up
fi
if [ `ps -ef | grep ora_mrp[0-9]_$RBK_SID | grep -v " grep " | wc -l` -eq 0 ]; then
#echo "Sid: $db is stby, `hostname -s` "
ROLE=prim
else
#echo "Sid: $db is prim, `hostname -s` "
ROLE=stby
fi
fi
echo Connecting to Rubrik with IP $RUBRIK_IP
ret=0
# API call to list Oracle DBs
find_database
echo Fetching Recoverable Ranges for $RBK_SID on $RBK_HOST
# API call to get the recoverable range
ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/$db_id/recoverable_range"
http_response=$(curl -s -k -o /tmp/rbkresponse.$$ -w "%{http_code}" -X GET $ENDPOINT -H "accept: application/json" -H "Authorization: Bearer $AUTH_TOKEN")
# echo "ret $ret"
echo -e "SID\t Hostname Status Role Start Time\t\t\tEnd Time\t\t\tStatus"
echo -e "-------- -------- ------- ------- ----------\t\t\t--------\t\t\t------"
if [ $ret -ne 0 ] ; then
echo "" >> /apprepos/oracle/orauti/shell/rubrik/rr_debug.log
echo "Date: `date "+%Y-%m-%d-%H.%M.%S"`, RC: $ret" >> /apprepos/oracle/orauti/shell/rubrik/rr_debug.log
RESULT_GET=" No_date No_date KO RC rbk $ret " >> /apprepos/oracle/orauti/shell/rubrik/rr_debug.log
if [ ! -z "${INFO_RR_PROBLEM}" ] ; then
echo "${INFO_RR_PROBLEM}"
fi
else
RESULT_GET=`cat /tmp/rbkresponse.$$ | jq -r '.data[]' | jq -r ' "\(.beginTime)\t\(.endTime)\t\(.status)"'`
echo "" >> /apprepos/oracle/orauti/shell/rubrik/rr_debug.log
# echo "Date: `date "+%Y-%m-%d-%H.%M.%S"`, RC: $ret" >> /apprepos/oracle/orauti/shell/rubrik/rr_debug.log
# echo "${RESULT_GET}" >> /apprepos/oracle/orauti/shell/rubrik/rr_debug.log
cat /tmp/rbkresponse.$$ | tee -a /apprepos/oracle/orauti/shell/rubrik/rr_debug.log
if [ -z "${RESULT_GET}" ] ; then
RESULT_GET=" No_date No_date KO "
# echo " Problem rr" | mail -s "Rubrik RR problem" gerald.bailat@mobi.ch
if [ ! -z "${INFO_RR_PROBLEM}" ] ; then
echo "${INFO_RR_PROBLEM}"
fi
fi
fi
echo "${RESULT_GET}" | sed "s/^/${RBK_SID} `hostname -s` ${STATUS} ${ROLE} /" | awk '{printf "%-10s %-13s %-7s %-7s %-30s %-31s %-12s\n" ,$1,$2,$3,$4,$5,$6,$7}'
# cleanup