diff --git a/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh b/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh index e073f9d..8f60a95 100644 --- a/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh +++ b/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh @@ -375,7 +375,7 @@ run_dr_test() { # Use PowerShell to query database status 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 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) log "Collecting restore log from DR VM..." 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 [[ "$restore_log" == *"Log not available"* ]]; then + if [ -z "$restore_log" ]; then 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 - # Still not found, check if any logs exist - if [[ "$restore_log" == *"Log not available"* ]]; then - log "Checking for any restore logs in DR VM..." - 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 + # Still not found, use fallback message + if [ -z "$restore_log" ]; then + restore_log="Restore log not available (file may not exist or was not generated)" fi # Step 6: Cleanup @@ -427,19 +422,21 @@ run_dr_test() { # Collect restore log even when restore fails log "Collecting restore log after failure..." 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" \ - "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 - # Always try to get some error output - if [[ "$restore_log" == *"Log not available"* ]]; then + # Always try to get some error output from RMAN script + if [ -z "$restore_log" ]; then 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") - if [[ "$last_error" != *"No RMAN script found"* ]]; then - restore_log="RMAN script content (last 20 lines):$last_error" + "powershell -Command \"Get-Content 'D:\\oracle\\temp\\*.rman' -Tail 20 -ErrorAction SilentlyContinue\"" 2>/dev/null || echo "") + if [ -n "$last_error" ]; then + restore_log="RMAN script content (last 20 lines):\n$last_error" + else + restore_log="No restore logs or RMAN scripts found" fi fi