Adding original DM files

This commit is contained in:
2025-10-03 10:15:23 -04:00
parent 1508078efb
commit bc30f7b788
31 changed files with 2818 additions and 0 deletions

View File

@@ -0,0 +1,114 @@
#!/bin/bash
#
# Example API call script for Die Mobiliar
# v0.2 - James Pattinson - August 2021
#
# Lists the registered DBs for a given Oracle Host or RAC
# and their assigned SLAs
#
# usage: oracle_list_db.sh <HOSTNAME>
MYDIR="$(dirname "$(realpath "$0")")"
# source $MYDIR/rbk_api.conf
source $MYDIR/oracle_funcs.sh
# Given RBK_SID return $db_id of matching database
find_database1 () {
# First get IDs of all the mounted DBs for this SID
ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/mount"
rest_api_get
cat /tmp/rbkresponse.$$ | jq -r --arg SID "$RBK_SID" '.data[] | select(.mountedDatabaseId!=null and .mountedDatabaseName==$SID) | .mountedDatabaseId' > /tmp/mountedDBs.$$
# Now get a list of Oracle DBs
ENDPOINT="https://$RUBRIK_IP/api/v1/oracle/db?name=$RBK_SID"
rest_api_get
# If no host is specified then just look for the DB with the right SID
if [ -z $RBK_HOST ]; then
# get list of DB IDs in scope (sid matches and not a relic)
myDBs=$(cat /tmp/rbkresponse.$$ | jq -r --arg SID "$RBK_SID" '.data[] | select(.name==$SID and .isRelic==false) | .id' ; cat /tmp/rbkresponse.$$ | jq -r --arg SID "$RBK_SID" '.data[] | select(.name==$SID and .isRelic==false) | .dataGuardGroupId' | sort | uniq)
for db in $myDBs; do
id=$(echo $db | cut -d: -f 4)
if grep -q $id /tmp/mountedDBs.$$; then
continue
else
break
fi
done
# Get the details for the specific DB ID
read name db_id sla_id dg_type dg_id RBK_HOST num_instances grp_name < <(echo $(cat /tmp/rbkresponse.$$ | jq -r --arg ID "OracleDatabase:::$id" '.data[] | select(.id==$ID) | .name, .id, .configuredSlaDomainId, .dataGuardType, .dataGuardGroupId, .instances[0].hostName, .numInstances, .dataGuardGroupName'))
# Host was specified
else
read name db_id sla_id dg_type dg_id RBK_HOST num_instances grp_name < <(echo $(cat /tmp/rbkresponse.$$ | jq -r --arg SID "$RBK_SID" --arg HOST "$RBK_HOST" '.data[] | select(.sid==$SID and .infraPath[0].name==$HOST and .isRelic==false) | .name, .id, .configuredSlaDomainId, .dataGuardType, .dataGuardGroupId, .instances[0].hostName, .numInstances, .dataGuardGroupName'))
fi
if [ "$dg_type" == "DataGuardMember" ]; then
db_id=$dg_id
fi
if [ -z "$db_id" ]; then
echo FATAL: No DB found with SID $RBK_SID on host $RBK_HOST
#exit_with_error
fi
}
# HTTP GET: Given $ENDPOINT write output to file
rest_api_get1 () {
http_response=$(curl -s -k -o /tmp/rbkresponse.$$ -w "%{http_code}" -X GET $ENDPOINT -H "accept: application/json" -H "Authorization: Bearer $AUTH_TOKEN")
#check_http_error
}
usage() { echo "Usage: $0 [-h <dbhost>] [-g|] <SID>" 1>&2; exit 1; }
while getopts "h:" o; do
case "${o}" in
h)
RBK_HOST=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
RBK_SID=$1
if [ -z "${RBK_SID}" ]; then
usage
fi
#echo "Fetching available snapshots for \"$RBK_SID\" on $RBK_HOST"
echo Connecting to Rubrik with IP $RUBRIK_IP
# API call to list Oracle DBs
find_database1
echo Fetching available snapshots for $RBK_SID on $RBK_HOST
# API call to get the recoverable range
ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/$db_id/snapshot"
rest_api_get1
#cat /tmp/rbkresponse.$$ | jq -r '.data | sort_by(.date) | .[] | "\(.date)\t\(.slaName)"' | grep 2021-11-26
if [ -z "`cat /tmp/rbkresponse.$$ | jq -r '.data | sort_by(.date) | .[] | "\(.date)\t\(.slaName)"'`" ] ; then
echo "last backup: ${RBK_SID} `hostname -s` 0001-01-01T00:00:00.000Z Problem-or-No-Backup No-info No-info"
if [ ! -z "${INFO_PROBLEM}" ] ; then
echo "${INFO_PROBLEM}"
fi
else
echo "last backup: ${RBK_SID} `hostname -s` `cat /tmp/rbkresponse.$$ | jq -r '.data | sort_by(.date) | .[] | "\(.date)\t\(.slaName)\t\(.isOnDemandSnapshot)\t\(.replicationLocationIds)"' | tail -1`"
fi
cleanup