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:
@@ -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: <number>" 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"
|
||||
|
||||
Reference in New Issue
Block a user