Oracle DR: Convert restore scripts to PowerShell for SSH compatibility
- Add cleanup_database.ps1: PowerShell version without input redirection issues - Add rman_restore_from_zero.ps1: PowerShell version with inline SQL commands - Update weekly-dr-test-proxmox.sh: Call .ps1 scripts via PowerShell PowerShell scripts resolve SSH 'Input redirection not supported' errors All SQL commands are piped directly to sqlplus (no temp files needed) Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
131
oracle/standby-server-scripts/cleanup_database.ps1
Normal file
131
oracle/standby-server-scripts/cleanup_database.ps1
Normal file
@@ -0,0 +1,131 @@
|
||||
# Oracle Database Complete Cleanup Script (PowerShell)
|
||||
# Purpose: Remove all database files and services to restore DR VM to clean state
|
||||
# Run as: Administrator
|
||||
# Location: D:\oracle\scripts\cleanup_database.ps1
|
||||
|
||||
$ErrorActionPreference = "Continue"
|
||||
|
||||
$env:ORACLE_HOME = "C:\Users\Administrator\Downloads\WINDOWS.X64_193000_db_home"
|
||||
$env:ORACLE_SID = "ROA"
|
||||
$env:PATH = "$env:ORACLE_HOME\bin;$env:PATH"
|
||||
|
||||
Write-Host "============================================"
|
||||
Write-Host "Oracle Database Cleanup Script"
|
||||
Write-Host "============================================"
|
||||
Write-Host ""
|
||||
Write-Host "This script will:"
|
||||
Write-Host " 1. Stop and delete Oracle service"
|
||||
Write-Host " 2. Delete all database files (datafiles, control files, redo logs)"
|
||||
Write-Host " 3. Delete local FRA (backups are on F:\, safe to delete)"
|
||||
Write-Host " 4. Delete trace files"
|
||||
Write-Host " 5. Leave VM in completely clean state (no service, no DB files)"
|
||||
Write-Host ""
|
||||
|
||||
# Check if running in non-interactive mode
|
||||
$silent = $args -contains "/SILENT" -or $args -contains "/AUTO"
|
||||
|
||||
if (-not $silent) {
|
||||
Write-Host "WARNING: This will DELETE the entire database!" -ForegroundColor Red
|
||||
Write-Host "Starting cleanup in 3 seconds... (Press Ctrl+C to cancel)"
|
||||
Start-Sleep -Seconds 3
|
||||
}
|
||||
|
||||
# Create directories
|
||||
New-Item -ItemType Directory -Path "D:\oracle\temp" -Force | Out-Null
|
||||
New-Item -ItemType Directory -Path "D:\oracle\logs" -Force | Out-Null
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "[1/6] Shutting down database (if running)..."
|
||||
|
||||
# Check if Oracle service exists
|
||||
$service = Get-Service -Name "OracleServiceROA" -ErrorAction SilentlyContinue
|
||||
if ($service) {
|
||||
Write-Host " Oracle service found, attempting shutdown..."
|
||||
|
||||
# Try to shutdown database using SQL*Plus with inline command
|
||||
$shutdownSQL = "SHUTDOWN ABORT;`nEXIT;"
|
||||
try {
|
||||
$shutdownSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null
|
||||
Start-Sleep -Seconds 2
|
||||
} catch {
|
||||
Write-Host " Shutdown command sent (errors ignored)"
|
||||
}
|
||||
|
||||
# Force kill any Oracle processes
|
||||
Get-Process -Name "sqlplus" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Get-Process -Name "oracle" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
Write-Host " Oracle service not found, skipping shutdown"
|
||||
}
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
Write-Host "[2/6] Stopping and deleting Oracle service + registry + instance..."
|
||||
|
||||
# Method 1: Use oradim to delete Oracle instance
|
||||
$env:ORACLE_HOME = "C:\Users\Administrator\Downloads\WINDOWS.X64_193000_db_home"
|
||||
$env:PATH = "$env:ORACLE_HOME\bin;$env:PATH"
|
||||
& oradim -delete -sid ROA 2>&1 | Out-Null
|
||||
Write-Host " Oracle instance deleted with oradim"
|
||||
|
||||
# Method 2: Delete service directly (backup method)
|
||||
$service = Get-Service -Name "OracleServiceROA" -ErrorAction SilentlyContinue
|
||||
if ($service) {
|
||||
Stop-Service -Name "OracleServiceROA" -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
& sc.exe delete OracleServiceROA 2>&1 | Out-Null
|
||||
Write-Host " Oracle service deleted with sc"
|
||||
}
|
||||
|
||||
# Method 3: Delete Oracle registry keys
|
||||
$regPath = "HKLM:\SOFTWARE\ORACLE\KEY_OraDB19Home1"
|
||||
Remove-ItemProperty -Path $regPath -Name "ORA_ROA_PFILE" -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path $regPath -Name "ORA_ROA_AUTOSTART" -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path $regPath -Name "ORA_ROA_SHUTDOWN" -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path $regPath -Name "ORA_ROA_SHUTDOWNTYPE" -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path $regPath -Name "ORA_ROA_SHUTDOWN_TIMEOUT" -ErrorAction SilentlyContinue
|
||||
Write-Host " Registry keys cleaned"
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
Write-Host "[3/6] Deleting database files..."
|
||||
Write-Host " Deleting datafiles..."
|
||||
Remove-Item "C:\Users\oracle\oradata\ROA\*.dbf" -Force -ErrorAction SilentlyContinue
|
||||
Write-Host " Deleting control files..."
|
||||
Remove-Item "C:\Users\oracle\oradata\ROA\*.ctl" -Force -ErrorAction SilentlyContinue
|
||||
Write-Host " Deleting redo logs..."
|
||||
Remove-Item "C:\Users\oracle\oradata\ROA\*.log" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host "[4/6] Deleting local FRA (backups are on F:\)..."
|
||||
if (Test-Path "C:\Users\oracle\recovery_area\ROA") {
|
||||
Remove-Item "C:\Users\oracle\recovery_area\ROA" -Recurse -Force -ErrorAction SilentlyContinue
|
||||
New-Item -ItemType Directory -Path "C:\Users\oracle\recovery_area\ROA" -Force | Out-Null
|
||||
Write-Host " FRA cleared"
|
||||
} else {
|
||||
New-Item -ItemType Directory -Path "C:\Users\oracle\recovery_area\ROA" -Force | Out-Null
|
||||
Write-Host " FRA directory created"
|
||||
}
|
||||
|
||||
Write-Host "[5/6] Deleting trace files (to save space)..."
|
||||
Remove-Item "C:\Users\oracle\diag\rdbms\roa\ROA\trace\*.trc" -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item "C:\Users\oracle\diag\rdbms\roa\ROA\trace\*.trm" -Force -ErrorAction SilentlyContinue
|
||||
Write-Host " Trace files deleted"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "============================================"
|
||||
Write-Host "Database Cleanup Complete!"
|
||||
Write-Host "============================================"
|
||||
Write-Host ""
|
||||
Write-Host "Current state:"
|
||||
Write-Host " [YES] Oracle software installed"
|
||||
Write-Host " [YES] PFILE exists (C:\Users\oracle\admin\ROA\pfile\initROA.ora)"
|
||||
Write-Host " [NO] Oracle service (will be created during restore)"
|
||||
Write-Host " [NO] Database files (will be restored from backups)"
|
||||
Write-Host " [NO] Control files (will be restored from backups)"
|
||||
Write-Host " [NO] Datafiles (will be restored from backups)"
|
||||
Write-Host ""
|
||||
Write-Host "VM is now in COMPLETELY CLEAN STATE!"
|
||||
Write-Host ""
|
||||
Write-Host "Next step: Run D:\oracle\scripts\rman_restore_from_zero.ps1"
|
||||
Write-Host " (It will create the Oracle service and restore the database)"
|
||||
Write-Host ""
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user