#!/bin/bash # # Oracle Backup script for Die Mobiliar # v0.3 - James Pattinson - October 2021 # # usage: oracle_backup.sh [-h ] [-a|-f|-n] # # -a archivelog backup # -f force full backup # -n do not wait for completion, submit job only # # The DB must already be protected by an SLA usage() { echo "Usage: $0 [-h ] [-a|-f|-n] " 1>&2; exit 1; } MYDIR="$(dirname "$(realpath "$0")")" # source $MYDIR/rbk_api.conf source $MYDIR/oracle_funcs.sh archivelog=0 full=0 while getopts "h:afn" o; do case "${o}" in h) RBK_HOST=${OPTARG} ;; a) archivelog=1 ;; f) full=1 ;; n) nowait=1 ;; *) usage ;; esac done shift $((OPTIND-1)) RBK_SID=$1 if [ -z "${RBK_SID}" ]; then usage fi if [ $archivelog -eq 1 ] && [ $full -eq 1 ]; then echo "FATAL: Can't specify both archivelog and full backup modes" exit_with_error fi echo Connecting to $RUBRIK_IP # API call to list Oracle DBs find_database # API call to perform the snapshot if [ $full -eq 1 ]; then PAYLOAD="{\"slaId\":\"$sla_id\",\"forceFullSnapshot\":true}" ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/$db_id/snapshot" echo Requesting full backup for $RBK_SID on $RBK_HOST elif [ $archivelog -eq 1 ]; then ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/$db_id/log_backup" PAYLOAD="{}" echo Requesting log backup for $RBK_SID on $RBK_HOST else PAYLOAD="{\"slaId\":\"$sla_id\"}" ENDPOINT="https://$RUBRIK_IP/api/internal/oracle/db/$db_id/snapshot" echo Requesting backup for $RBK_SID on $RBK_HOST fi rest_api_post ENDPOINT=$(cat /tmp/rbkresponse.$$ | jq -r '.links[0].href') check_status cleanup