From 8da1208ca7d1e8f9bfca005a966bb531f5cba324 Mon Sep 17 00:00:00 2001 From: Marius Date: Sat, 11 Oct 2025 18:55:05 +0300 Subject: [PATCH] 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: ' 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> --- .../weekly-dr-test-proxmox.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh b/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh index b9cc586..15b6d4e 100644 --- a/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh +++ b/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh @@ -423,24 +423,21 @@ run_dr_test() { step_start=$(date +%s) log "STEP 5: Verifying database" - # Use PowerShell to query database status (check if contains READ WRITE anywhere) - db_status=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \ - "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") - - # Convert PowerShell True/False to bash-friendly value - if [[ "$db_status" == *"True"* ]] || [[ "$db_status" == "True" ]]; then + # Parse database status from LOG_FILE (rman_restore_from_zero.ps1 already verified it) + # Look for "OPEN_MODE: READ WRITE" in the captured output + if grep -q "OPEN_MODE: READ WRITE" "$LOG_FILE" 2>/dev/null; then db_status="READ WRITE" else db_status="" fi - # Use PowerShell to count tables - tables_restored=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \ - "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") + # Parse table count from LOG_FILE (already captured in STEP 3 output) + # Look for "TABLES: " in the output + 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') [ -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" test_result="PASSED" severity="info"