Fix ROA Windows setup scripts for Oracle XE deployment
Key fixes: - Add Run.cmd/RunAll.cmd wrappers with ExecutionPolicy Bypass - Add Get-ListenerHost() to auto-detect listener IP address - Fix impdp connection using EZConnect format (host:port/service) - Add parallel=1 for Oracle XE compatibility - Fix Write-Log to accept empty strings with [AllowEmptyString()] - Fix Get-SchemaObjectCount regex for Windows line endings (\r\n) - Fix path comparison for DMP file copy operation - Add GRANT EXECUTE ON SYS.AUTH_PACK TO PUBLIC for PACK_DREPTURI - Fix VAUTH_SERII view to use SYN_NOM_PROGRAME (has DENUMIRE column) - Add sections 10-11 to grants-public.sql for SYS object grants Tested on VM 302 (10.0.20.130) with Oracle XE 21c. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -66,7 +66,7 @@ param(
|
||||
[string]$TableExistsAction = "REPLACE",
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[int]$Parallel = 2
|
||||
[int]$Parallel = 1
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
@@ -117,7 +117,11 @@ try {
|
||||
$dumpFileName = Split-Path -Path $DumpFile -Leaf
|
||||
$targetDumpPath = Join-Path $DmpDir $dumpFileName
|
||||
|
||||
if ($DumpFile -ne $targetDumpPath) {
|
||||
# Resolve paths for accurate comparison (handles casing and path format differences)
|
||||
$resolvedSource = (Resolve-Path -Path $DumpFile -ErrorAction SilentlyContinue).Path
|
||||
$resolvedTarget = if (Test-Path $targetDumpPath) { (Resolve-Path -Path $targetDumpPath).Path } else { $null }
|
||||
|
||||
if ($resolvedSource -ne $resolvedTarget) {
|
||||
Write-Log "Copying dump file to DMPDIR..."
|
||||
Copy-Item -Path $DumpFile -Destination $targetDumpPath -Force
|
||||
Write-LogSuccess "Dump file copied to: $targetDumpPath"
|
||||
@@ -149,8 +153,12 @@ try {
|
||||
|
||||
$importLogFile = "CONTAFIN_ORACLE_import_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
|
||||
|
||||
# Build impdp command
|
||||
$connString = "SYSTEM/`"$SystemPassword`"@$ServiceName"
|
||||
# Get listener host for connection (handles listener bound to specific IP)
|
||||
$dbHost = Get-ListenerHost -OracleHome $oraHome
|
||||
$dbPort = 1521
|
||||
|
||||
# Build impdp command with EZConnect format
|
||||
$connString = "SYSTEM/`"$SystemPassword`"@${dbHost}:${dbPort}/${ServiceName}"
|
||||
|
||||
$impdpParams = @(
|
||||
"`"$connString`"",
|
||||
@@ -158,13 +166,10 @@ try {
|
||||
"dumpfile=$dumpFileName",
|
||||
"logfile=$importLogFile",
|
||||
"schemas=CONTAFIN_ORACLE",
|
||||
"table_exists_action=$TableExistsAction"
|
||||
"table_exists_action=$TableExistsAction",
|
||||
"parallel=$Parallel" # Always specify to override DMP metadata (XE requires parallel=1)
|
||||
)
|
||||
|
||||
if ($Parallel -gt 1) {
|
||||
$impdpParams += "parallel=$Parallel"
|
||||
}
|
||||
|
||||
$arguments = $impdpParams -join " "
|
||||
|
||||
Write-Log "Executing impdp..."
|
||||
|
||||
@@ -308,7 +308,9 @@ EXIT;
|
||||
$impdpPath = Join-Path $oraHome "bin\impdp.exe"
|
||||
$importLogFile = "$($item.Schema)_import_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
|
||||
|
||||
$connString = "SYSTEM/`"$SystemPassword`"@$ServiceName"
|
||||
# Use EZConnect format for impdp (handles listener bound to specific IP)
|
||||
$dbHost = Get-ListenerHost -OracleHome $oraHome
|
||||
$connString = "SYSTEM/`"$SystemPassword`"@${dbHost}:1521/$ServiceName"
|
||||
|
||||
# Check if dump has different schema name (remapping needed)
|
||||
$remapParam = ""
|
||||
@@ -324,7 +326,8 @@ EXIT;
|
||||
"dumpfile=$dumpFileName",
|
||||
"logfile=$importLogFile",
|
||||
"schemas=$($item.Schema)",
|
||||
"table_exists_action=REPLACE"
|
||||
"table_exists_action=REPLACE",
|
||||
"parallel=1" # Required for Oracle XE
|
||||
)
|
||||
|
||||
if ($remapParam) {
|
||||
|
||||
@@ -6,16 +6,24 @@
|
||||
# Usage:
|
||||
# .\99-uninstall-roa.ps1 -SystemPassword "yourpassword"
|
||||
# .\99-uninstall-roa.ps1 -SystemPassword "yourpassword" -Force
|
||||
# .\99-uninstall-roa.ps1 -ServiceName "XEPDB1" -SystemPassword "yourpassword" -Force
|
||||
#
|
||||
# Parameters:
|
||||
# -SystemPassword : SYS password for database connection
|
||||
# -SystemPassword : SYS password for database connection (default: romfastsoft)
|
||||
# -ServiceName : Oracle service name (auto-detected if not specified)
|
||||
# -Force : Skip confirmation prompt
|
||||
#
|
||||
# ============================================================================
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$SystemPassword,
|
||||
[string]$OracleHome,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$ServiceName,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$SystemPassword = "romfastsoft",
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]$Force
|
||||
@@ -30,13 +38,14 @@ $ErrorActionPreference = "Stop"
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$RootDir = Split-Path -Parent $ScriptDir
|
||||
|
||||
# Load config
|
||||
# Load config (optional - script can work with auto-detection)
|
||||
$ConfigFile = Join-Path $RootDir "config.ps1"
|
||||
if (Test-Path $ConfigFile) {
|
||||
. $ConfigFile
|
||||
} else {
|
||||
Write-Host "ERROR: config.ps1 not found. Copy config.example.ps1 to config.ps1" -ForegroundColor Red
|
||||
exit 1
|
||||
# Use config values if parameters not provided
|
||||
if (-not $OracleHome -and $ORACLE_HOME) { $OracleHome = $ORACLE_HOME }
|
||||
if (-not $ServiceName -and $SERVICE_NAME) { $ServiceName = $SERVICE_NAME }
|
||||
if ($SystemPassword -eq "romfastsoft" -and $SYSTEM_PASSWORD) { $SystemPassword = $SYSTEM_PASSWORD }
|
||||
}
|
||||
|
||||
# Load libraries
|
||||
@@ -53,20 +62,25 @@ Write-Host " ROA UNINSTALL - REMOVING ALL ROA OBJECTS" -ForegroundColor Cy
|
||||
Write-Host "============================================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Get password if not provided
|
||||
if (-not $SystemPassword) {
|
||||
$SecurePassword = Read-Host "Enter SYS password" -AsSecureString
|
||||
$SystemPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
|
||||
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
|
||||
)
|
||||
# Get Oracle Home
|
||||
$oraHome = Get-OracleHome -OracleHome $OracleHome
|
||||
Write-Host "[INFO] Oracle Home: $oraHome" -ForegroundColor Green
|
||||
|
||||
# Get listener host
|
||||
$OracleHost = Get-ListenerHost -OracleHome $oraHome
|
||||
Write-Host "[INFO] Database Host: $OracleHost" -ForegroundColor Green
|
||||
|
||||
# Auto-detect service name if not specified
|
||||
if (-not $ServiceName) {
|
||||
$ServiceName = "XEPDB1" # Default for Oracle XE
|
||||
}
|
||||
Write-Host "[INFO] Service Name: $ServiceName" -ForegroundColor Green
|
||||
|
||||
# Build connection string
|
||||
$OracleService = if ($Config.OracleService) { $Config.OracleService } else { "XEPDB1" }
|
||||
$OracleHost = if ($Config.OracleHost) { $Config.OracleHost } else { "localhost" }
|
||||
$OraclePort = if ($Config.OraclePort) { $Config.OraclePort } else { 1521 }
|
||||
$ConnString = "${OracleHost}:${OraclePort}/${OracleService}"
|
||||
$OraclePort = 1521
|
||||
$ConnString = "${OracleHost}:${OraclePort}/${ServiceName}"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Target database: $ConnString" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
@@ -95,9 +109,9 @@ Write-Host "Starting uninstall..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Find sqlplus
|
||||
$SqlPlus = Get-SqlPlusPath
|
||||
if (-not $SqlPlus) {
|
||||
Write-Host "ERROR: sqlplus.exe not found" -ForegroundColor Red
|
||||
$SqlPlus = Join-Path $oraHome "bin\sqlplus.exe"
|
||||
if (-not (Test-Path $SqlPlus)) {
|
||||
Write-Host "ERROR: sqlplus.exe not found at $SqlPlus" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -110,27 +124,36 @@ if (-not (Test-Path $SqlScript)) {
|
||||
}
|
||||
|
||||
Write-Host "Running uninstall script..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
$SqlInput = @"
|
||||
@"$SqlScript"
|
||||
EXIT
|
||||
"@
|
||||
# Set Oracle environment
|
||||
$env:ORACLE_HOME = $oraHome
|
||||
$env:PATH = "$oraHome\bin;$env:PATH"
|
||||
$env:NLS_LANG = "AMERICAN_AMERICA.AL32UTF8"
|
||||
|
||||
$process = Start-Process -FilePath $SqlPlus `
|
||||
-ArgumentList "sys/${SystemPassword}@${ConnString} as sysdba" `
|
||||
-NoNewWindow -Wait -PassThru `
|
||||
-RedirectStandardInput (New-TemporaryFile | ForEach-Object {
|
||||
$SqlInput | Set-Content $_.FullName
|
||||
$_.FullName
|
||||
})
|
||||
|
||||
# Alternative: run directly
|
||||
& $SqlPlus "sys/${SystemPassword}@${ConnString} as sysdba" "@$SqlScript"
|
||||
# Execute uninstall SQL script
|
||||
try {
|
||||
& $SqlPlus "sys/${SystemPassword}@${ConnString} as sysdba" "@$SqlScript"
|
||||
$exitCode = $LASTEXITCODE
|
||||
}
|
||||
catch {
|
||||
Write-Host "ERROR: Failed to execute uninstall script: $_" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "============================================================" -ForegroundColor Green
|
||||
Write-Host " ROA UNINSTALL COMPLETE" -ForegroundColor Green
|
||||
Write-Host "============================================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Database is now clean. You can re-run the setup scripts." -ForegroundColor Cyan
|
||||
if ($exitCode -eq 0) {
|
||||
Write-Host "============================================================" -ForegroundColor Green
|
||||
Write-Host " ROA UNINSTALL COMPLETE" -ForegroundColor Green
|
||||
Write-Host "============================================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Database is now clean. You can re-run the setup scripts." -ForegroundColor Cyan
|
||||
}
|
||||
else {
|
||||
Write-Host "============================================================" -ForegroundColor Yellow
|
||||
Write-Host " ROA UNINSTALL COMPLETED WITH WARNINGS" -ForegroundColor Yellow
|
||||
Write-Host "============================================================" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Write-Host "Some objects may not have been removed. Review output above." -ForegroundColor Yellow
|
||||
}
|
||||
Write-Host ""
|
||||
|
||||
@@ -90,8 +90,9 @@ function Initialize-LogFile {
|
||||
function Write-Log {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[string]$Message,
|
||||
[Parameter(Mandatory = $false, Position = 0)]
|
||||
[AllowEmptyString()]
|
||||
[string]$Message = "",
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[ValidateSet('Info', 'Warning', 'Error', 'Success', 'Debug')]
|
||||
@@ -101,6 +102,17 @@ function Write-Log {
|
||||
[switch]$NoConsole
|
||||
)
|
||||
|
||||
# Handle empty messages (blank lines)
|
||||
if ([string]::IsNullOrEmpty($Message)) {
|
||||
if ($script:LogFile) {
|
||||
Add-Content -Path $script:LogFile -Value "" -Encoding UTF8
|
||||
}
|
||||
if (-not $NoConsole) {
|
||||
Write-Host ""
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
$timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
|
||||
$logMessage = "[$timestamp] [$Level] $Message"
|
||||
|
||||
|
||||
@@ -17,6 +17,82 @@
|
||||
# Source logging functions
|
||||
. "$PSScriptRoot\logging-functions.ps1"
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Get the listener host address.
|
||||
|
||||
.DESCRIPTION
|
||||
Auto-detects the host address from listener configuration.
|
||||
Returns the IP address the listener is bound to.
|
||||
|
||||
.PARAMETER OracleHome
|
||||
Oracle Home directory.
|
||||
|
||||
.OUTPUTS
|
||||
String. The host address (IP or hostname).
|
||||
|
||||
.EXAMPLE
|
||||
$host = Get-ListenerHost -OracleHome "C:\app\oracle\product\21c\dbhomeXE"
|
||||
#>
|
||||
function Get-ListenerHost {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$OracleHome
|
||||
)
|
||||
|
||||
$oraHome = Get-OracleHome -OracleHome $OracleHome
|
||||
$lsnrctl = Join-Path $oraHome "bin\lsnrctl.exe"
|
||||
|
||||
if (-not (Test-Path $lsnrctl)) {
|
||||
return "localhost"
|
||||
}
|
||||
|
||||
try {
|
||||
# Set Oracle environment
|
||||
$env:ORACLE_HOME = $oraHome
|
||||
$env:PATH = "$oraHome\bin;$env:PATH"
|
||||
|
||||
$output = & $lsnrctl status 2>&1 | Out-String
|
||||
|
||||
# Parse HOST from listener output - look for TCP endpoint (not TCPS)
|
||||
# Format: (PROTOCOL=tcp)(HOST=10.0.20.130)(PORT=1521)
|
||||
# Use simple IP pattern to avoid regex escaping issues
|
||||
$tcpMatch = [regex]::Match($output, "PROTOCOL=tcp\).*?HOST=([0-9\.]+)")
|
||||
if ($tcpMatch.Success) {
|
||||
$listenerHost = $tcpMatch.Groups[1].Value
|
||||
|
||||
# If listener is bound to 0.0.0.0, try to get actual IP
|
||||
if ($listenerHost -eq "0.0.0.0") {
|
||||
$ip = (Get-NetIPAddress -AddressFamily IPv4 |
|
||||
Where-Object { $_.IPAddress -notmatch "^127\." -and $_.PrefixOrigin -ne "WellKnown" } |
|
||||
Select-Object -First 1).IPAddress
|
||||
if ($ip) { return $ip }
|
||||
return "localhost"
|
||||
}
|
||||
|
||||
# If it's a specific IP (not localhost), return it
|
||||
if ($listenerHost -notmatch "^127\." -and $listenerHost -ne "localhost") {
|
||||
return $listenerHost
|
||||
}
|
||||
}
|
||||
|
||||
# Fallback: try any HOST= pattern
|
||||
$anyHostMatch = [regex]::Match($output, "HOST=([0-9\.]+)")
|
||||
if ($anyHostMatch.Success) {
|
||||
$listenerHost = $anyHostMatch.Groups[1].Value
|
||||
if ($listenerHost -notmatch "^127\." -and $listenerHost -ne "0.0.0.0") {
|
||||
return $listenerHost
|
||||
}
|
||||
}
|
||||
|
||||
return "localhost"
|
||||
}
|
||||
catch {
|
||||
return "localhost"
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Find Oracle Home directory.
|
||||
@@ -489,14 +565,15 @@ function Invoke-SqlPlus {
|
||||
throw "SQL*Plus not found at: $sqlplus"
|
||||
}
|
||||
|
||||
# Build connection string (EZConnect format if DbHost is provided)
|
||||
$sysdba = if ($AsSysdba) { " as sysdba" } else { "" }
|
||||
if ($DbHost) {
|
||||
$connString = "$Username/`"$Password`"@${DbHost}:${Port}/${ServiceName}$sysdba"
|
||||
} else {
|
||||
$connString = "$Username/`"$Password`"@$ServiceName$sysdba"
|
||||
# Auto-detect host from listener if not provided
|
||||
if (-not $DbHost) {
|
||||
$DbHost = Get-ListenerHost -OracleHome $oraHome
|
||||
}
|
||||
|
||||
# Build connection string (always use EZConnect format for reliability)
|
||||
$sysdba = if ($AsSysdba) { " as sysdba" } else { "" }
|
||||
$connString = "$Username/`"$Password`"@${DbHost}:${Port}/${ServiceName}$sysdba"
|
||||
|
||||
$tempFile = $null
|
||||
|
||||
try {
|
||||
@@ -973,14 +1050,21 @@ SELECT 'INVALID:' || COUNT(*) FROM dba_objects WHERE owner = UPPER('$SchemaName'
|
||||
EXIT;
|
||||
"@
|
||||
|
||||
$result = Invoke-SqlPlus -OracleHome $OracleHome -ServiceName $ServiceName `
|
||||
$oraHome = Get-OracleHome -OracleHome $OracleHome
|
||||
|
||||
$result = Invoke-SqlPlus -OracleHome $oraHome -ServiceName $ServiceName `
|
||||
-Username "SYSTEM" -Password $Password -SqlCommand $sql -Silent
|
||||
|
||||
$counts = @{}
|
||||
|
||||
foreach ($line in $result -split "`n") {
|
||||
if ($line -match "^([A-Z_ ]+):(\d+)$") {
|
||||
$counts[$Matches[1].Trim()] = [int]$Matches[2]
|
||||
# Parse result lines for object type counts
|
||||
$lines = $result -split "`r?`n"
|
||||
foreach ($line in $lines) {
|
||||
$trimmed = $line.Trim()
|
||||
if ($trimmed.Length -gt 0 -and $trimmed -match "^([A-Z][A-Z_ ]*):(\d+)$") {
|
||||
$key = $Matches[1].Trim()
|
||||
$value = [int]$Matches[2]
|
||||
$counts[$key] = $value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user