|
|
|
@@ -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"
|
|
|
|
|
|
|
|
|
|
|
|
@@ -201,40 +208,70 @@ if ($LASTEXITCODE -ne 0) {
|
|
|
|
} 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..."
|
|
|
|
|
|
|
|
|
|
|
|
# Register with listener and start it
|
|
|
|
# Shutdown database cleanly
|
|
|
|
Write-Host "[3.4] Starting Oracle Listener..."
|
|
|
|
Write-Host " Shutting down database temporarily..."
|
|
|
|
|
|
|
|
$shutdownSQL = @"
|
|
|
|
|
|
|
|
SHUTDOWN IMMEDIATE;
|
|
|
|
|
|
|
|
EXIT;
|
|
|
|
|
|
|
|
"@
|
|
|
|
|
|
|
|
$shutdownSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null
|
|
|
|
|
|
|
|
Start-Sleep -Seconds 3
|
|
|
|
|
|
|
|
|
|
|
|
# Set Listener service to AUTOMATIC and start it
|
|
|
|
# Delete and recreate service with SPFILE
|
|
|
|
Set-Service -Name "OracleOraDB19Home1TNSListener" -StartupType Automatic -ErrorAction SilentlyContinue
|
|
|
|
Write-Host " Recreating service with SPFILE..."
|
|
|
|
Start-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue
|
|
|
|
& oradim -delete -sid ROA 2>&1 | Out-Null
|
|
|
|
|
|
|
|
Start-Sleep -Seconds 2
|
|
|
|
|
|
|
|
& oradim -new -sid ROA -startmode auto -spfile 2>&1 | Out-Null
|
|
|
|
|
|
|
|
|
|
|
|
if ((Get-Service -Name "OracleOraDB19Home1TNSListener" -ErrorAction SilentlyContinue).Status -eq "Running") {
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
Write-Host "[OK] Listener started successfully"
|
|
|
|
Write-Host " WARNING: Failed to recreate service with SPFILE" -ForegroundColor Yellow
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Write-Host "WARNING: Failed to start Listener automatically, trying lsnrctl..." -ForegroundColor Yellow
|
|
|
|
Write-Host " [OK] Service now configured with SPFILE and AUTOMATIC startup"
|
|
|
|
& lsnrctl start 2>&1 | Out-Null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Start-Sleep -Seconds 2
|
|
|
|
# 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 database with listener
|
|
|
|
# Start Oracle Listener
|
|
|
|
$registerSQL = @"
|
|
|
|
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;
|
|
|
|
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 ""
|
|
|
|
|