Oracle DR: Add TestMode parameter for dual behavior

rman_restore_from_zero.ps1:
- Add -TestMode switch parameter
- TestMode (weekly DR test): Skip service/listener config, only verify restore works
- Standalone mode: Full config with SPFILE + Listener for production use

weekly-dr-test-proxmox.sh:
- Call restore script with -TestMode flag
- Avoids service recreation and SSH disconnect during tests

Benefits:
- Weekly tests are faster and cleaner (no service restart)
- Manual restore prepares system for production use
- No more 'Broken pipe' errors during tests

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
Marius
2025-10-11 02:33:43 +03:00
parent f79331f7cc
commit 9ed0ee9e0e
2 changed files with 68 additions and 21 deletions

View File

@@ -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 ""

View File

@@ -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 ))