Clean up logging

This commit is contained in:
2025-10-15 10:39:19 +01:00
parent 150f065349
commit 2fed2ded69
5 changed files with 170 additions and 72 deletions

View File

@@ -23,13 +23,23 @@
# DB_CREATE_FILE_DEST=/u01/app/oracle/oradata/NEWNAME/
# AUDIT_FILE_DEST='/u01/app/oracle/admin/NEWNAME/adump'
usage() { echo "Usage: $0 -n <newname> -o <optionsfile> -h <targethost> [-s sourcehost] [-t \"YYYY-MM-DD HH:MM:SS\"] [-d] <srcdb>" 1>&2; exit 1; }
usage() { log_error "Usage: $0 -n <newname> -o <optionsfile> -h <targethost> [-s sourcehost] [-t \"YYYY-MM-DD HH:MM:SS\"] [-d] <srcdb>"; exit 1; }
MYDIR="$(dirname "$(realpath "$0")")"
# Support long option --verbose by translating to -v before getopts
for arg in "$@"; do
case "$arg" in
--verbose)
set -- "${@/--verbose/-v}"
break
;;
esac
done
source $MYDIR/rsc_ops.sh
while getopts "n:o:t:h:s:d" o; do
while getopts "n:o:t:h:s:d:v" o; do
case "${o}" in
n)
newName=${OPTARG}
@@ -49,6 +59,9 @@ while getopts "n:o:t:h:s:d" o; do
d)
dryrun=true
;;
v)
VERBOSE=1
;;
*)
usage
;;
@@ -64,7 +77,7 @@ fi
# Check if optionsFile exists
if [[ ! -f "$optionsFile" ]]; then
echo "ERROR: Options file '$optionsFile' does not exist."
log_error "Options file '$optionsFile' does not exist."
exit_with_error
fi
@@ -139,7 +152,7 @@ get_latest_pit() {
# Get latest endTime
latest_endtime=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleRecoverableRanges.data[] | .endTime' | sort -r | head -n 1)
echo "Latest PIT (ISO8601): $latest_endtime"
log_info "Latest PIT (ISO8601): $latest_endtime"
# Convert to unixtime in milliseconds
latest_unixtime_ms=$(date -d "$latest_endtime" +%s 2>/dev/null)
@@ -148,11 +161,11 @@ get_latest_pit() {
latest_unixtime_ms=$(gdate -d "$latest_endtime" +%s 2>/dev/null)
fi
if [[ -z "$latest_unixtime_ms" ]]; then
echo "ERROR: Unable to convert $latest_endtime to unixtime"
log_error "Unable to convert $latest_endtime to unixtime"
exit 5
fi
latest_unixtime_ms=$((latest_unixtime_ms * 1000))
echo "Latest PIT unixtime (ms): $latest_unixtime_ms"
log_info "Latest PIT unixtime (ms): $latest_unixtime_ms"
export latest_unixtime_ms
}
@@ -188,7 +201,7 @@ get_oracle_host_id() {
host_ids=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleTopLevelDescendants.nodes[] | .id')
host_count=$(echo "$host_ids" | grep -c .)
if [[ $host_count -ne 1 ]]; then
echo "ERROR: Multiple hosts found for '$1':"
log_error "Multiple hosts found for '$1':"
cat /tmp/rbkresponse.$$ | jq -r '.data.oracleTopLevelDescendants.nodes[] | "\(.name) \(.id)"'
exit_with_error
fi
@@ -199,7 +212,7 @@ get_oracle_host_id() {
# If $1 looks like a dbid (contains hyphens), use it directly and skip DB lookup
if [[ "$1" == *-* ]]; then
dbid="$1"
echo "INFO: Using provided dbid: $dbid"
log_info "Using provided dbid: $dbid"
gql_lookupCdmId='query OracleDatabase($fid: UUID!) {
oracleDatabase(fid: $fid) {
@@ -217,10 +230,10 @@ if [[ "$1" == *-* ]]; then
cdmId=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabase.cluster.id')
if [[ -z "$cdmId" ]]; then
echo "ERROR: Could not find CDM ID for dbid '$dbid'"
log_error "Could not find CDM ID for dbid '$dbid'"
exit 1
fi
echo "CDM ID is $cdmId"
log_info "CDM ID is $cdmId"
else
gql_DBListQuery='query OracleDatabases($filter: [Filter!]) {
@@ -268,7 +281,7 @@ oracleDatabases(filter: $filter) {
dbid_count=$(echo "$dbid" | grep -c .)
if [[ "$dbid_count" -ne 1 || -z "$dbid" ]]; then
echo "ERROR: Expected exactly one database running on node '$node_name', found $dbid_count:"
log_error "Expected exactly one database running on node '$node_name', found $dbid_count:"
cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | "\(.dbUniqueName) \(.logicalPath[0].name) \(.id)"'
cleanup
exit 4
@@ -280,7 +293,7 @@ oracleDatabases(filter: $filter) {
dbid_count=$(echo "$dbid" | grep -c .)
if [[ "$dbid_count" -ne 1 || -z "$dbid" ]]; then
echo "ERROR: Expected exactly one database with name '$1', found $dbid_count:"
log_error "Expected exactly one database with name '$1', found $dbid_count:"
cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabases.nodes[] | "\(.dbUniqueName) \(.logicalPath[0].name) \(.id)"'
cleanup
exit 4
@@ -301,7 +314,7 @@ if [[ -n "${datestring:-}" ]]; then
unixtime_ms=$((unixtime * 1000))
echo INFO: Requested time is $datestring which is $utctime in UTC, unixtime is $unixtime
else
echo INFO: No time specified, using latest PIT
log_info "No time specified, using latest PIT"
get_latest_pit
unixtime_ms=$latest_unixtime_ms
fi
@@ -310,11 +323,11 @@ fi
get_oracle_host_id "$targetHost"
if [[ -z "$targetHostId" ]]; then
echo "ERROR: Could not resolve target host ID for '$targetHost'"
log_error "Could not resolve target host ID for '$targetHost'"
exit_with_error
fi
echo Target Host ID is $targetHostId
log_info "Target Host ID is $targetHostId"
cloningOptions=$(template_to_json $optionsFile)
@@ -374,7 +387,7 @@ cat /tmp/rbkresponse.$$ | jq
# Save the id from the response
job_id=$(cat /tmp/rbkresponse.$$ | jq -r '.data.exportOracleDatabase.id')
echo "DEBUG: Job id is $job_id"
log_info "Job id is $job_id"
gqlCheckStatus='query OracleDatabaseAsyncRequestDetails($input: GetOracleAsyncRequestStatusInput!) {
oracleDatabaseAsyncRequestDetails(input: $input) {
@@ -405,25 +418,17 @@ while true; do
status=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabaseAsyncRequestDetails.status')
progress=$(cat /tmp/rbkresponse.$$ | jq -r '.data.oracleDatabaseAsyncRequestDetails.progress')
echo "Job status: $status $progress percent"
log_info "Job status: $status $progress percent"
if [[ "$status" == "FAILED" ]]; then
echo "Database clone FAILED"
log_error "Database clone FAILED"
cat /tmp/rbkresponse.$$ | jq
cleanup
exit 2
elif [[ "$status" == "CANCELLED" ]]; then
echo "Database clone CANCELLED"
log_warn "Database clone CANCELLED"
exit 3
elif [[ "$status" == "SUCCEEDED" ]]; then
echo "Database clone SUCCEEDED"
cat /tmp/rbkresponse.$$ | jq
cleanup
exit 0
fi
sleep 15
done
echo "Database clone SUCCEEDED"
log_info "Database clone SUCCEEDED"
cat /tmp/rbkresponse.$$ | jq
cleanup
exit 0
@@ -432,3 +437,4 @@ done
done