diff --git a/oracle/standby-server-scripts/rman_restore_from_zero.ps1 b/oracle/standby-server-scripts/rman_restore_from_zero.ps1 index 1b7e7eb..3c9e0a2 100644 --- a/oracle/standby-server-scripts/rman_restore_from_zero.ps1 +++ b/oracle/standby-server-scripts/rman_restore_from_zero.ps1 @@ -2,6 +2,13 @@ # Backups are on F:\ (NFS mount from Proxmox host) # Run as: Administrator # Location: D:\oracle\scripts\rman_restore_from_zero.ps1 +# +# Parameters: +# -TestMode: Skip service reconfiguration and Listener startup (for weekly DR tests) + +param( + [switch]$TestMode +) $ErrorActionPreference = "Continue" @@ -200,31 +207,71 @@ if ($LASTEXITCODE -ne 0) { Write-Host "WARNING: Failed to create SPFILE - database may not persist after connections close" -ForegroundColor Yellow } else { Write-Host "[OK] SPFILE created successfully" - Write-Host "[3.3] Oracle service already configured with AUTOMATIC startup (from step 2.1)" - - # Start Oracle Listener - Write-Host "[3.4] Starting Oracle Listener..." - # Set Listener service to AUTOMATIC and start it - Set-Service -Name "OracleOraDB19Home1TNSListener" -StartupType Automatic -ErrorAction SilentlyContinue - Start-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue - - if ((Get-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue).Status -eq "Running") { - Write-Host "[OK] Listener started successfully" + # Check if running in TestMode (weekly DR test) + if ($TestMode) { + Write-Host "[3.3] Running in TEST MODE - skipping service reconfiguration" + Write-Host " Database is OPEN and ready for verification" + Write-Host " Service will remain configured with PFILE (OK for testing)" } else { - Write-Host "WARNING: Failed to start Listener automatically, trying lsnrctl..." -ForegroundColor Yellow - & lsnrctl start 2>&1 | Out-Null - } - - Start-Sleep -Seconds 2 - - # Register database with listener - $registerSQL = @" + # Full configuration for standalone/production use + Write-Host "[3.3] Reconfiguring Oracle service to use SPFILE..." + + # Shutdown database cleanly + Write-Host " Shutting down database temporarily..." + $shutdownSQL = @" +SHUTDOWN IMMEDIATE; +EXIT; +"@ + $shutdownSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null + Start-Sleep -Seconds 3 + + # Delete and recreate service with SPFILE + Write-Host " Recreating service with SPFILE..." + & oradim -delete -sid ROA 2>&1 | Out-Null + Start-Sleep -Seconds 2 + & oradim -new -sid ROA -startmode auto -spfile 2>&1 | Out-Null + + if ($LASTEXITCODE -ne 0) { + Write-Host " WARNING: Failed to recreate service with SPFILE" -ForegroundColor Yellow + } else { + Write-Host " [OK] Service now configured with SPFILE and AUTOMATIC startup" + } + + # Restart database + Write-Host " Starting database with SPFILE..." + $startupSQL = @" +STARTUP; +EXIT; +"@ + $startupSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null + Start-Sleep -Seconds 3 + Write-Host "[OK] Database restarted with SPFILE configuration" + + # Start Oracle Listener + Write-Host "[3.4] Starting Oracle Listener..." + + # Set Listener service to AUTOMATIC and start it + Set-Service -Name "OracleOraDB19Home1TNSListener" -StartupType Automatic -ErrorAction SilentlyContinue + Start-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue + + if ((Get-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue).Status -eq "Running") { + Write-Host "[OK] Listener started successfully" + } else { + Write-Host "WARNING: Failed to start Listener automatically, trying lsnrctl..." -ForegroundColor Yellow + & lsnrctl start 2>&1 | Out-Null + } + + Start-Sleep -Seconds 2 + + # Register database with listener + $registerSQL = @" ALTER SYSTEM REGISTER; EXIT; "@ - $registerSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null - Write-Host "[OK] Database registered with Listener" + $registerSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null + Write-Host "[OK] Database registered with Listener" + } } Write-Host "" diff --git a/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh b/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh index e03f3f1..46ba35f 100644 --- a/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh +++ b/oracle/standby-server-scripts/weekly-dr-test-proxmox.sh @@ -362,7 +362,7 @@ run_dr_test() { log "STEP 4: Running database restore" if ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \ - "powershell -ExecutionPolicy Bypass -File D:\\oracle\\scripts\\rman_restore_from_zero.ps1" 2>&1 | tee -a "$LOG_FILE"; then + "powershell -ExecutionPolicy Bypass -File D:\\oracle\\scripts\\rman_restore_from_zero.ps1 -TestMode" 2>&1 | tee -a "$LOG_FILE"; then local restore_end=$(date +%s) restore_duration=$(( (restore_end - restore_start) / 60 ))