From 5da9a378595ca582e9ca77becb73c1a5fa7dacf6 Mon Sep 17 00:00:00 2001 From: SupraJames Date: Mon, 20 Apr 2026 15:04:21 +0100 Subject: [PATCH] List jobs script --- README.md | 6 ++ rsc_oracle_jobs.sh | 164 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100755 rsc_oracle_jobs.sh diff --git a/README.md b/README.md index 31d677f..92acd37 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,12 @@ Security note: `rsc.json` is listed in `.gitignore`. Ensure the file permissions ./rsc_log_backup.sh ``` +- Check for running Oracle backup and log-backup jobs: + +``` +./rsc_oracle_jobs.sh +``` + 1. **Parameter Validation** - Validates required parameters and options file 2. **Database Discovery** - Locates source database in RSC 3. **Host Resolution** - Resolves target host ID in RSC diff --git a/rsc_oracle_jobs.sh b/rsc_oracle_jobs.sh new file mode 100755 index 0000000..a657970 --- /dev/null +++ b/rsc_oracle_jobs.sh @@ -0,0 +1,164 @@ +#!/bin/bash +# +# Checks for running Oracle backup-related jobs for an Oracle database +# + +usage() { echo "Usage: $0 [filter]" >&2; exit 1; } + +if [[ -z "$1" ]]; then + usage +fi + +MYDIR="$(dirname "$(realpath "$0")")" + +source $MYDIR/rsc_ops.sh +trap cleanup EXIT + +pretty_job_type() { + case "$1" in + Backup) + echo "DB Snapshot" + ;; + LOG_BACKUP) + echo "Log Backup" + ;; + *) + echo "$1" + ;; + esac +} + +format_local_time() { + local timestamp="$1" + local normalized_timestamp + local epoch + + if [[ -z "$timestamp" || "$timestamp" == "null" ]]; then + echo "start time unavailable" + return + fi + + normalized_timestamp="${timestamp%%.*}Z" + + if [[ "$DATE" == "gdate" ]]; then + epoch=$(gdate -u -d "$normalized_timestamp" +%s 2>/dev/null) + else + epoch=$(TZ=UTC date -j -f "%Y-%m-%dT%H:%M:%SZ" "$normalized_timestamp" "+%s" 2>/dev/null) + fi + + if [[ -z "$epoch" ]]; then + echo "$timestamp" + return + fi + + if [[ "$DATE" == "gdate" ]]; then + gdate -d "@$epoch" "+%Y-%m-%d %H:%M:%S %Z" + else + date -r "$epoch" "+%Y-%m-%d %H:%M:%S %Z" + fi +} + +gql_DBListQuery='query OracleDatabases($filter: [Filter!]) { +oracleDatabases(filter: $filter) { + nodes { + dbUniqueName + 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') +db_name=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | .dbUniqueName') + +dbid_count=$(echo "$dbid" | grep -c .) +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' + exit 4 +fi + +log_info "DB ID is $dbid" + +gqlListJobs='query ListJobs($filters: ActivitySeriesFilter) { + activitySeriesConnection(filters: $filters) { + nodes { + fid + objectName + objectType + startTime + activitySeriesId + isOnDemand + progress + lastActivityType + } + } +}' + +variables="{ +\"filters\": { + \"objectFid\": [ + \"$dbid\" + ], + \"lastActivityStatus\": \"RUNNING\", + \"lastActivityType\": [\"LOG_BACKUP\",\"BACKUP\"] +} +}" + +gqlQuery="$(echo $gqlListJobs)" +gqlVars="$(echo $variables)" +rsc_gql_query + +job_count=$(cat /tmp/rbkresponse.$$ | jq -r '.data.activitySeriesConnection.nodes | length') + +if [[ "$job_count" -eq 0 ]]; then + echo "No running backup jobs found for $db_name" + exit 0 +fi + +echo "Running backup jobs for $db_name:" +while IFS= read -r job_json; do + if [[ -z "$job_json" ]]; then + continue + fi + + last_activity_type=$(echo "$job_json" | jq -r '.lastActivityType // empty') + progress=$(echo "$job_json" | jq -r '.progress // empty') + start_time=$(echo "$job_json" | jq -r '.startTime // empty') + + if [[ -z "$last_activity_type" ]]; then + continue + fi + + job_type=$(pretty_job_type "$last_activity_type") + local_start_time=$(format_local_time "$start_time") + if [[ -z "$progress" || "$progress" == "null" ]]; then + progress_display="progress unavailable" + else + progress_display="$progress%" + fi + + printf ' %-12s %-20s started %s\n' "$job_type" "$progress_display" "$local_start_time" +done < <(cat /tmp/rbkresponse.$$ | jq -c '.data.activitySeriesConnection.nodes[]') + +exit 1 \ No newline at end of file