Oracle DR: Fix false FAILED notification - parse database status from log

- Replace complex SSH+PowerShell query with simple log file parsing
- rman_restore_from_zero.ps1 already verifies and outputs database status
- Parse 'OPEN_MODE: READ WRITE' and 'TABLES: <count>' from LOG_FILE
- Fixes issue where successful restore was reported as FAILED
- More reliable: avoids SSH escaping issues with Select-String -Quiet

Root cause: SSH+PowerShell+sqlplus+Select-String chain was too fragile and
returned empty/false even when database was successfully opened (42625 tables).

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
Marius
2025-10-11 18:55:05 +03:00
parent a7273d1820
commit 8da1208ca7

View File

@@ -423,24 +423,21 @@ run_dr_test() {
step_start=$(date +%s) step_start=$(date +%s)
log "STEP 5: Verifying database" log "STEP 5: Verifying database"
# Use PowerShell to query database status (check if contains READ WRITE anywhere) # Parse database status from LOG_FILE (rman_restore_from_zero.ps1 already verified it)
db_status=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \ # Look for "OPEN_MODE: READ WRITE" in the captured output
"powershell -Command \"echo 'SELECT OPEN_MODE FROM V\`\$DATABASE;' | sqlplus -s / as sysdba | Out-String | Select-String -Pattern 'READ WRITE' -Quiet\"" 2>/dev/null || echo "false") if grep -q "OPEN_MODE: READ WRITE" "$LOG_FILE" 2>/dev/null; then
# Convert PowerShell True/False to bash-friendly value
if [[ "$db_status" == *"True"* ]] || [[ "$db_status" == "True" ]]; then
db_status="READ WRITE" db_status="READ WRITE"
else else
db_status="" db_status=""
fi fi
# Use PowerShell to count tables # Parse table count from LOG_FILE (already captured in STEP 3 output)
tables_restored=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \ # Look for "TABLES: <number>" in the output
"powershell -Command \"'SELECT COUNT(*) FROM DBA_TABLES WHERE OWNER NOT IN (''SYS'',''SYSTEM'');' | sqlplus -s / as sysdba | Select-String -Pattern '[0-9]+' | ForEach-Object { \$_.Matches[0].Value } | Select-Object -Last 1\"" || echo "0") tables_restored=$(grep -oP "TABLES:\s*\K\d+" "$LOG_FILE" 2>/dev/null | tail -1 || echo "0")
tables_restored=$(echo "$tables_restored" | tr -cd '0-9') tables_restored=$(echo "$tables_restored" | tr -cd '0-9')
[ -z "$tables_restored" ] && tables_restored=0 [ -z "$tables_restored" ] && tables_restored=0
if [[ "$db_status" =~ "READ WRITE" ]]; then if [[ "$db_status" == "READ WRITE" ]] && [ "$tables_restored" -gt 0 ]; then
track_step "Database Verification" true "Database OPEN, $tables_restored tables" "$step_start" track_step "Database Verification" true "Database OPEN, $tables_restored tables" "$step_start"
test_result="PASSED" test_result="PASSED"
severity="info" severity="info"