Compare commits

..

2 Commits

Author SHA1 Message Date
Marius
9ed0ee9e0e 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>
2025-10-11 02:33:43 +03:00
Marius
f79331f7cc Oracle DR: Fix service recreation causing SSH disconnect
Remove service delete/recreate at step 3.3 that was causing 'Broken pipe' error
Service is already configured with auto-start at step 2.1 - no need to recreate

Issue: oradim -delete was killing running database and breaking SSH connection
Solution: Skip recreation, service already has correct auto-start configuration

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2025-10-11 02:29:38 +03:00
2 changed files with 68 additions and 31 deletions

View File

@@ -2,6 +2,13 @@
# Backups are on F:\ (NFS mount from Proxmox host) # Backups are on F:\ (NFS mount from Proxmox host)
# Run as: Administrator # Run as: Administrator
# Location: D:\oracle\scripts\rman_restore_from_zero.ps1 # 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" $ErrorActionPreference = "Continue"
@@ -200,41 +207,71 @@ if ($LASTEXITCODE -ne 0) {
Write-Host "WARNING: Failed to create SPFILE - database may not persist after connections close" -ForegroundColor Yellow Write-Host "WARNING: Failed to create SPFILE - database may not persist after connections close" -ForegroundColor Yellow
} else { } else {
Write-Host "[OK] SPFILE created successfully" Write-Host "[OK] SPFILE created successfully"
# Recreate service with auto-start and SPFILE # Check if running in TestMode (weekly DR test)
Write-Host "[3.3] Recreating Oracle service with auto-start mode..." if ($TestMode) {
& oradim -delete -sid ROA 2>&1 | Out-Null Write-Host "[3.3] Running in TEST MODE - skipping service reconfiguration"
Start-Sleep -Seconds 2 Write-Host " Database is OPEN and ready for verification"
& oradim -new -sid ROA -startmode auto -spfile 2>&1 | Out-Null Write-Host " Service will remain configured with PFILE (OK for testing)"
if ($LASTEXITCODE -ne 0) {
Write-Host "WARNING: Failed to recreate service with auto-start" -ForegroundColor Yellow
} else { } else {
Write-Host "[OK] Service recreated with auto-start mode" # 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"
# Register with listener and start it # Start Oracle Listener
Write-Host "[3.4] Starting Oracle Listener..." Write-Host "[3.4] Starting Oracle Listener..."
# Set Listener service to AUTOMATIC and start it # Set Listener service to AUTOMATIC and start it
Set-Service -Name "OracleOraDB19Home1TNSListener" -StartupType Automatic -ErrorAction SilentlyContinue Set-Service -Name "OracleOraDB19Home1TNSListener" -StartupType Automatic -ErrorAction SilentlyContinue
Start-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue Start-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue
if ((Get-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue).Status -eq "Running") { if ((Get-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue).Status -eq "Running") {
Write-Host "[OK] Listener started successfully" Write-Host "[OK] Listener started successfully"
} else { } else {
Write-Host "WARNING: Failed to start Listener automatically, trying lsnrctl..." -ForegroundColor Yellow Write-Host "WARNING: Failed to start Listener automatically, trying lsnrctl..." -ForegroundColor Yellow
& lsnrctl start 2>&1 | Out-Null & lsnrctl start 2>&1 | Out-Null
} }
Start-Sleep -Seconds 2 Start-Sleep -Seconds 2
# Register database with listener # Register database with listener
$registerSQL = @" $registerSQL = @"
ALTER SYSTEM REGISTER; ALTER SYSTEM REGISTER;
EXIT; EXIT;
"@ "@
$registerSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null $registerSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null
Write-Host "[OK] Database registered with Listener" Write-Host "[OK] Database registered with Listener"
}
} }
Write-Host "" Write-Host ""

View File

@@ -362,7 +362,7 @@ run_dr_test() {
log "STEP 4: Running database restore" log "STEP 4: Running database restore"
if ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \ 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) local restore_end=$(date +%s)
restore_duration=$(( (restore_end - restore_start) / 60 )) restore_duration=$(( (restore_end - restore_start) / 60 ))