Files
llb-oracle/rsc_log_backup.sh
2025-10-15 17:33:29 +01:00

135 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
#
# Example RSC API call script
# v0.1 - James Pattinson - June 2024
#
# Performs a log backup for an Oracle database
#
# usage: rsc_log_backup.sh [filter]
usage() { echo "Usage: $0 [filter]" >&2; exit 1; }
if [[ -z "$1" ]]; then
usage
fi
MYDIR="$(dirname "$(realpath "$0")")"
# log_info prints by default now; no verbose flag
# source $MYDIR/rbk_api.conf
source $MYDIR/rsc_ops.sh
gql_DBListQuery='query OracleDatabases($filter: [Filter!]) {
oracleDatabases(filter: $filter) {
nodes {
dbUniqueName
id
cluster {
id
}
}
}
}'
variables="{
\"filter\": [
{
\"texts\": [\"$1\"],
\"field\": \"NAME_EXACT_MATCH\"
},
{
\"texts\": [\"false\"],
\"field\": \"IS_RELIC\"
},
{
\"texts\": [\"false\"],
\"field\": \"IS_REPLICATED\"
}
]
}"
gqlQuery="$(echo $gql_DBListQuery)"
gqlVars="$(echo $variables)"
rsc_gql_query
dbid=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | .id')
cdmId=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | .cluster.id')
# Check for multiple dbids
dbid_count=$(echo "$dbid" | wc -l)
if [[ "$dbid_count" -ne 1 || -z "$dbid" ]]; then
log_error "Expected exactly one database match! found:"
cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | .dbUniqueName'
cleanup
exit 4
fi
log_info "DB ID is $dbid"
variables="{
\"input\": {
\"id\": \"$dbid\"
}
}"
gqlLogBackup='mutation TakeLogBackupOracleMutation($input: TakeOnDemandOracleLogSnapshotInput!) {
takeOnDemandOracleLogSnapshot(input: $input) {
id
__typename
}
}'
gqlQuery="$(echo $gqlLogBackup)"
gqlVars="$(echo $variables)"
rsc_gql_query
# Save the id from the response
log_info "Log backup job id: $(cat /tmp/rbkresponse.$$ | jq -r '.data.takeOnDemandOracleLogSnapshot.id')"
log_backup_id=$(cat /tmp/rbkresponse.$$ | jq -r '.data.takeOnDemandOracleLogSnapshot.id')
gqlCheckStatus='query OracleDatabaseAsyncRequestDetails($input: GetOracleAsyncRequestStatusInput!) {
oracleDatabaseAsyncRequestDetails(input: $input) {
id
nodeId
status
startTime
endTime
progress
error {
message
}
}
}'
variables="{
\"input\": {
\"id\": \"$log_backup_id\",
\"clusterUuid\": \"$cdmId\"
}
}"
gqlQuery="$(echo $gqlCheckStatus)"
gqlVars="$(echo $variables)"
while true; do
rsc_gql_query
status=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabaseAsyncRequestDetails.status')
progress=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabaseAsyncRequestDetails.progress')
log_info "Job status: $status $progress percent"
if [[ "$status" == "FAILED" ]]; then
log_error "Log backup FAILED"
cat /tmp/rbkresponse.$$ | jq
cleanup
exit 2
elif [[ "$status" == "CANCELLED" ]]; then
log_warn "Log backup CANCELLED"
exit 3
elif [[ "$status" == "SUCCEEDED" ]]; then
log_info "Log backup SUCCEEDED"
cat /tmp/rbkresponse.$$ | jq
cleanup
exit 0
fi
sleep 15
done