Oracle DR: Fix database verification and restore log collection
Critical fixes for false negatives in DR test reporting: 1. Database verification fix: - Changed from 'findstr' (CMD) to 'Select-String' (PowerShell native) - findstr was failing in PowerShell context causing db_status to be empty - Result: DB with 42,625 tables was incorrectly reported as FAILED 2. Restore log collection fix: - Changed from 'type' (CMD) to 'Get-Content' (PowerShell native) - type command doesn't work through SSH PowerShell context - Added -ErrorAction SilentlyContinue for cleaner error handling - Simplified fallback logic using [-z] instead of string matching Both issues were caused by mixing CMD commands in PowerShell context. Now uses PowerShell-native commands throughout for consistency. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@@ -375,7 +375,7 @@ run_dr_test() {
|
|||||||
|
|
||||||
# Use PowerShell to query database status
|
# Use PowerShell to query database status
|
||||||
db_status=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
db_status=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
"powershell -Command \"'SELECT OPEN_MODE FROM V\\\$DATABASE;' | sqlplus -s / as sysdba | findstr 'READ WRITE'\"" || echo "")
|
"powershell -Command \"echo 'SELECT OPEN_MODE FROM V\`\$DATABASE;' | sqlplus -s / as sysdba | Select-String 'READ WRITE'\"" 2>/dev/null || echo "")
|
||||||
|
|
||||||
# Use PowerShell to count tables
|
# Use PowerShell to count tables
|
||||||
tables_restored=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
tables_restored=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
@@ -395,22 +395,17 @@ run_dr_test() {
|
|||||||
# Collect restore log from VM (always attempt collection)
|
# Collect restore log from VM (always attempt collection)
|
||||||
log "Collecting restore log from DR VM..."
|
log "Collecting restore log from DR VM..."
|
||||||
restore_log=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
restore_log=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
"type D:\\oracle\\logs\\restore_from_zero.log 2>nul" | head -200 || echo "Log not available")
|
"powershell -Command \"Get-Content 'D:\\oracle\\logs\\restore_from_zero.log' -Head 200 -ErrorAction SilentlyContinue\"" 2>/dev/null || echo "")
|
||||||
|
|
||||||
# If not found, try alternate locations
|
# If not found, try alternate locations
|
||||||
if [[ "$restore_log" == *"Log not available"* ]]; then
|
if [ -z "$restore_log" ]; then
|
||||||
restore_log=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
restore_log=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
"type D:\\oracle\\temp\\restore_from_zero.log 2>nul" | head -200 || echo "Log not available")
|
"powershell -Command \"Get-Content 'D:\\oracle\\temp\\restore_from_zero.log' -Head 200 -ErrorAction SilentlyContinue\"" 2>/dev/null || echo "")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Still not found, check if any logs exist
|
# Still not found, use fallback message
|
||||||
if [[ "$restore_log" == *"Log not available"* ]]; then
|
if [ -z "$restore_log" ]; then
|
||||||
log "Checking for any restore logs in DR VM..."
|
restore_log="Restore log not available (file may not exist or was not generated)"
|
||||||
log_check=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
|
||||||
"dir D:\\oracle\\logs\\*.log 2>nul || dir D:\\oracle\\temp\\*.log 2>nul || echo 'No logs found'" 2>/dev/null || echo "Connection error")
|
|
||||||
if [[ "$log_check" != *"No logs found"* ]]; then
|
|
||||||
restore_log="Log files found but could not be read. Available files: $log_check"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 6: Cleanup
|
# Step 6: Cleanup
|
||||||
@@ -427,19 +422,21 @@ run_dr_test() {
|
|||||||
# Collect restore log even when restore fails
|
# Collect restore log even when restore fails
|
||||||
log "Collecting restore log after failure..."
|
log "Collecting restore log after failure..."
|
||||||
restore_log=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
restore_log=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
"type D:\\oracle\\logs\\restore_from_zero.log 2>nul" | head -200 || echo "Log not available")
|
"powershell -Command \"Get-Content 'D:\\oracle\\logs\\restore_from_zero.log' -Head 200 -ErrorAction SilentlyContinue\"" 2>/dev/null || echo "")
|
||||||
|
|
||||||
if [[ "$restore_log" == *"Log not available"* ]]; then
|
if [ -z "$restore_log" ]; then
|
||||||
restore_log=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
restore_log=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
"type D:\\oracle\\temp\\restore_from_zero.log 2>nul" | head -200 || echo "Log not available")
|
"powershell -Command \"Get-Content 'D:\\oracle\\temp\\restore_from_zero.log' -Head 200 -ErrorAction SilentlyContinue\"" 2>/dev/null || echo "")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Always try to get some error output
|
# Always try to get some error output from RMAN script
|
||||||
if [[ "$restore_log" == *"Log not available"* ]]; then
|
if [ -z "$restore_log" ]; then
|
||||||
last_error=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
last_error=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
"powershell -Command 'Get-Content D:\\oracle\\temp\\*.rman -Tail 20 || echo \"No RMAN script found\"'" 2>/dev/null || echo "Cannot access RMAN script")
|
"powershell -Command \"Get-Content 'D:\\oracle\\temp\\*.rman' -Tail 20 -ErrorAction SilentlyContinue\"" 2>/dev/null || echo "")
|
||||||
if [[ "$last_error" != *"No RMAN script found"* ]]; then
|
if [ -n "$last_error" ]; then
|
||||||
restore_log="RMAN script content (last 20 lines):$last_error"
|
restore_log="RMAN script content (last 20 lines):\n$last_error"
|
||||||
|
else
|
||||||
|
restore_log="No restore logs or RMAN scripts found"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user