first commit
This commit is contained in:
134
rsc_log_backup.sh
Executable file
134
rsc_log_backup.sh
Executable file
@@ -0,0 +1,134 @@
|
||||
#!/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]" 1>&2; exit 1; }
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
MYDIR="$(dirname "$(realpath "$0")")"
|
||||
|
||||
# source $MYDIR/rbk_api.conf
|
||||
source $MYDIR/oracle_funcs.sh
|
||||
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
|
||||
echo "ERROR: Expected exactly one database match! found:"
|
||||
cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | .dbUniqueName'
|
||||
cleanup
|
||||
exit 4
|
||||
fi
|
||||
|
||||
echo "DEBUG: 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_backup_id=$(cat /tmp/rbkresponse.$$ | jq -r '.data.takeOnDemandOracleLogSnapshot.id')
|
||||
echo "DEBUG: Job id is $log_backup_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')
|
||||
|
||||
echo "Job status: $status $progress percent"
|
||||
if [[ "$status" == "FAILED" ]]; then
|
||||
echo "Log backup FAILED"
|
||||
cat /tmp/rbkresponse.$$ | jq
|
||||
cleanup
|
||||
exit 2
|
||||
elif [[ "$status" == "CANCELLED" ]]; then
|
||||
echo "Log backup CANCELLED"
|
||||
exit 3
|
||||
elif [[ "$status" == "SUCCEEDED" ]]; then
|
||||
echo "Log backup SUCCEEDED"
|
||||
cat /tmp/rbkresponse.$$ | jq
|
||||
cleanup
|
||||
exit 0
|
||||
fi
|
||||
sleep 15
|
||||
|
||||
done
|
||||
Reference in New Issue
Block a user