#!/bin/bash # # Perform a validation of an Oracle DB backup # v0.2 - James Pattinson - August 2021 # # usage: oracle_validate.sh <"timestamp"> [sgasizeMB] # # Timestamp YYYY-MM-DD HH:MM:SS # Time is passed to 'date' on THIS machine, will use local timezone # # SGA size defaults to 30% of target host RAM if size in MB is not specified MYDIR="$(dirname "$(realpath "$0")")" # source $MYDIR/rbk_api.conf source $MYDIR/oracle_funcs.sh usage() { echo "Usage: $0 [-h ] [-n] [-s sgasizeMB] <"timestamp">" 1>&2; exit 1; } while getopts "h:s:n" o; do case "${o}" in h) RBK_HOST=${OPTARG} ;; s) sgasizeMB=${OPTARG} ;; n) nowait=1 ;; *) 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" 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 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)) # API call to perform the validation # is SGA size specified? if [ -z $sgasizeMB ]; then PAYLOAD="{\"recoveryPoint\":{\"timestampMs\":$millis},\"targetOracleHostOrRacId\":\"$target_id\"}" else PAYLOAD="{\"recoveryPoint\":{\"timestampMs\":$millis},\"targetOracleHostOrRacId\":\"$target_id\",\"sgaMaxSizeInMb\":$sgasizeMB}" fi echo Requesting validation for $RBK_SID on target host $RBK_TGT ENDPOINT="https://$RUBRIK_IP/api/v1/oracle/db/$db_id/validate" rest_api_post # Check the status in a loop. Translation of link using sed because API returns wrong href! ENDPOINT=$(cat /tmp/rbkresponse.$$ | jq -r '.links[0].href' | sed 's/v1/internal/') check_status cleanup