Reorganize oracle/ and chatbot/ into proxmox/ per LXC/VM structure
- Move oracle/migration-scripts/ to proxmox/lxc108-oracle/migration/ - Move oracle/roa/ and oracle/roa-romconstruct/ to proxmox/lxc108-oracle/sql/ - Move oracle/standby-server-scripts/ to proxmox/vm109-windows-dr/ - Move chatbot/ to proxmox/lxc104-flowise/ - Update proxmox/README.md with new structure and navigation - Update all documentation with correct directory references - Remove unused input/claude-agent-sdk/ files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
133
proxmox/vm109-windows-dr/scripts/cleanup_database.ps1
Normal file
133
proxmox/vm109-windows-dr/scripts/cleanup_database.ps1
Normal file
@@ -0,0 +1,133 @@
|
||||
# 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
|
||||
#
|
||||
# Parameters:
|
||||
# /SILENT - Non-interactive mode
|
||||
# /AFTER - Cleanup AFTER restore (shutdown instance + stop service before deleting files)
|
||||
|
||||
$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 parameters
|
||||
$silent = $args -contains "/SILENT" -or $args -contains "/AUTO"
|
||||
$afterRestore = $args -contains "/AFTER"
|
||||
|
||||
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 and stopping service..."
|
||||
|
||||
# Check if Oracle service exists
|
||||
$service = Get-Service -Name "OracleServiceROA" -ErrorAction SilentlyContinue
|
||||
if ($service) {
|
||||
Write-Host " Oracle service found, ensuring clean shutdown..."
|
||||
|
||||
# Shutdown instance using SQL*Plus (always, not just /AFTER)
|
||||
$shutdownSQL = "WHENEVER SQLERROR CONTINUE`nSHUTDOWN ABORT;`nEXIT;"
|
||||
try {
|
||||
$shutdownSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null
|
||||
Start-Sleep -Seconds 2
|
||||
Write-Host " Instance shut down (ABORT for fast cleanup)"
|
||||
} catch {
|
||||
Write-Host " Shutdown command sent (errors ignored)"
|
||||
}
|
||||
|
||||
# ALWAYS stop Oracle service to ensure clean state
|
||||
if ($service.Status -eq "Running") {
|
||||
Write-Host " Stopping Oracle service to ensure clean state..."
|
||||
try {
|
||||
Stop-Service -Name "OracleServiceROA" -Force -ErrorAction Stop
|
||||
Start-Sleep -Seconds 3
|
||||
Write-Host " Service stopped successfully"
|
||||
} catch {
|
||||
Write-Host " WARNING: Failed to stop service: $_" -ForegroundColor Yellow
|
||||
}
|
||||
} else {
|
||||
Write-Host " Service already stopped"
|
||||
}
|
||||
|
||||
# Force kill any remaining Oracle processes to ensure clean state
|
||||
Write-Host " Cleaning up any remaining Oracle processes..."
|
||||
Get-Process -Name "sqlplus" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Get-Process -Name "oracle" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
Write-Host " All Oracle processes terminated"
|
||||
} else {
|
||||
Write-Host " Oracle service not found, will be created during restore"
|
||||
}
|
||||
|
||||
Write-Host "[2/6] Oracle service stopped (clean state for restore)"
|
||||
Write-Host " Service will be started fresh during restore"
|
||||
Write-Host " This ensures no state inconsistencies (prevents ORA-00600)"
|
||||
|
||||
Write-Host "[3/6] Deleting database files + SPFILE..."
|
||||
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 " Deleting SPFILE (ensures PFILE-based startup)..."
|
||||
Remove-Item "$env:ORACLE_HOME\database\SPFILE*.ORA" -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 " [YES] Oracle service (STOPPED for clean restore)"
|
||||
Write-Host " [NO] SPFILE (deleted to ensure PFILE startup)"
|
||||
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 CLEAN STATE (service stopped, ready for fresh start)!"
|
||||
Write-Host ""
|
||||
Write-Host "Next step: Run D:\oracle\scripts\rman_restore_from_zero.ps1"
|
||||
Write-Host " (It will start the service fresh and restore the database)"
|
||||
Write-Host ""
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user