#!/bin/bash # # v0.3 - James Pattinson - Feb 2025 # # usage: rsc_assign_sla.sh [-h ] [-c | -d] [sla name] # # If SLA name contains spaces then use quotes around it # # -c Clear any direct assignment # -d Do Not Protect (Override any higher SLA assignment) MYDIR="$(dirname "$(realpath "$0")")" #source $MYDIR/rbk_api.conf source $MYDIR/oracle_funcs.sh source $MYDIR/rsc_ops.sh usage() { echo "Usage: $0 [-h ] <-c | -d | sla name>" 1>&2; exit 1; } dg=0 SLA_OP="protectWithSlaId" existingSnapshotRetention="NOT_APPLICABLE" while getopts "h:cd" o; do case "${o}" in h) RBK_HOST=${OPTARG} ;; c) SLA_OP="noAssignment" ;; d) SLA_OP="doNotProtect" ;; *) usage ;; esac done shift $((OPTIND-1)) RBK_SID=$1 RBK_SLA=$2 if [ -z "${RBK_SID}" ]; then usage fi echo Connecting to Rubrik with IP $RUBRIK_IP if [ "$SLA_OP" != 'protectWithSlaId' ]; then new_sla_id=null RBK_SLA=$SLA_OP if [ "$SLA_OP" == 'doNotProtect' ]; then existingSnapshotRetention="RETAIN_SNAPSHOTS" fi else gql_SLAListQuery='query SLAListQuery($after: String, $first: Int, $filter: [GlobalSlaFilterInput!], $sortBy: SlaQuerySortByField, $sortOrder: SortOrder) { slaDomains( after: $after first: $first filter: $filter sortBy: $sortBy sortOrder: $sortOrder ) { edges { node { name ... on GlobalSlaReply { id objectTypes __typename } } } } }' filter=$RBK_SLA variables="{ \"shouldShowPausedClusters\":true, \"filter\":[{\"field\":\"NAME\",\"text\":\"$filter\"},{\"field\":\"OBJECT_TYPE\",\"objectTypeList\":[\"ORACLE_OBJECT_TYPE\"]}], \"sortBy\":\"NAME\", \"sortOrder\":\"ASC\", \"first\":50 }" gqlQuery="$(echo $gql_SLAListQuery)" gqlVars="$(echo $variables)" rsc_gql_query #cat /tmp/rbkresponse.$$ new_sla_id=$(cat /tmp/rbkresponse.$$ | jq --arg SLA "$RBK_SLA" -r '.data.slaDomains.edges[] | select(.node.name == $SLA) | .node.id') new_sla_id=\"${new_sla_id}\" fi if [ -z $new_sla_id ]; then echo FATAL: Unable to map SLA ID for $RBK_SLA exit_with_error else echo "INFO: SLA ID for $RBK_SLA is $new_sla_id" fi rsc_find_database echo "INFO: DB found $rsc_db_id which is a $database_type instance" gql_AssignSlaMutation='mutation AssignSla($input: AssignSlaInput!) { assignSla(input: $input) { success __typename } }' variables="{ \"input\": { \"objectIds\": [ \"$rsc_db_id\" ], \"slaDomainAssignType\": \"$SLA_OP\", \"slaOptionalId\": $new_sla_id, \"existingSnapshotRetention\": \"$existingSnapshotRetention\", \"shouldApplyToExistingSnapshots\": false, \"shouldApplyToNonPolicySnapshots\": false } }" gqlQuery="$(echo $gql_AssignSlaMutation)" gqlVars="$(echo $variables)" rsc_gql_query cat /tmp/rbkresponse.$$ | jq -r echo Assigned $RBK_SLA to $RBK_SID cleanup