Fix DMPDIR handling and datafile auto-detection for ROA Windows setup
- New-OracleDirectory: Improved verification with direct SQL check, preserves existing DMPDIR path instead of blindly recreating - Get-DatafilePath: Better fallback logic using ORACLE_HOME to derive path, no longer hardcodes C:\app\oracle - grants-public.sql: Fixed DMPDIR creation - now preserves existing path instead of overriding with wrong D:\Oracle\admin\ORCL\dpdump - config.example.ps1: Added DATAFILE_DIR parameter with documentation These fixes ensure scripts work without manual intervention on fresh Oracle XE installations where default DMPDIR points to non-existent paths. Tested on VM 302 - full installation (01-08) now completes successfully. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -697,57 +697,61 @@ function New-OracleDirectory {
|
||||
Write-Log "Created directory: $DirectoryPath"
|
||||
}
|
||||
|
||||
# Check if directory already exists with different path - if so, drop it first
|
||||
# Always drop and recreate directory to ensure correct path
|
||||
# This fixes Oracle XE issue where DMPDIR may point to wrong default location
|
||||
$checkSql = @"
|
||||
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF LINESIZE 500
|
||||
SELECT directory_path FROM dba_directories WHERE directory_name = '$DirectoryName';
|
||||
EXIT;
|
||||
"@
|
||||
|
||||
$existingPath = Invoke-SqlPlus -OracleHome $OracleHome -ServiceName $ServiceName `
|
||||
-Username "SYS" -Password $Password -SqlCommand $checkSql -AsSysdba -Silent
|
||||
|
||||
$existingPath = ($existingPath -split "`n" | Where-Object { $_.Trim() -ne "" } | Select-Object -First 1)
|
||||
if ($existingPath) {
|
||||
$existingPath = $existingPath.Trim()
|
||||
}
|
||||
|
||||
# Normalize paths for comparison (case-insensitive, handle trailing slashes)
|
||||
$normalizedExisting = if ($existingPath) { $existingPath.TrimEnd('\').ToUpper() } else { "" }
|
||||
$normalizedTarget = $DirectoryPath.TrimEnd('\').ToUpper()
|
||||
|
||||
if ($existingPath -and $normalizedExisting -ne $normalizedTarget) {
|
||||
Write-Log "Directory $DirectoryName exists with different path: $existingPath"
|
||||
Write-Log "Dropping and recreating with correct path: $DirectoryPath"
|
||||
|
||||
$dropSql = @"
|
||||
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
|
||||
DROP DIRECTORY $DirectoryName;
|
||||
EXIT;
|
||||
"@
|
||||
Invoke-SqlPlus -OracleHome $OracleHome -ServiceName $ServiceName `
|
||||
-Username "SYS" -Password $Password -SqlCommand $dropSql -AsSysdba -Silent | Out-Null
|
||||
}
|
||||
|
||||
# Using DROP + CREATE instead of CREATE OR REPLACE for reliability
|
||||
$sql = @"
|
||||
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
|
||||
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF LINESIZE 500
|
||||
-- Check current directory path
|
||||
VARIABLE v_path VARCHAR2(500);
|
||||
VARIABLE v_exists NUMBER;
|
||||
BEGIN
|
||||
SELECT COUNT(*), MAX(directory_path) INTO :v_exists, :v_path
|
||||
FROM dba_directories WHERE directory_name = '$DirectoryName';
|
||||
END;
|
||||
/
|
||||
PRINT v_path
|
||||
|
||||
-- Drop if exists with different path
|
||||
BEGIN
|
||||
IF :v_exists > 0 AND UPPER(TRIM(:v_path)) != UPPER('$DirectoryPath') THEN
|
||||
EXECUTE IMMEDIATE 'DROP DIRECTORY $DirectoryName';
|
||||
DBMS_OUTPUT.PUT_LINE('DROPPED_DIFFERENT_PATH');
|
||||
ELSIF :v_exists > 0 THEN
|
||||
DBMS_OUTPUT.PUT_LINE('PATH_ALREADY_CORRECT');
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN NULL;
|
||||
END;
|
||||
/
|
||||
|
||||
-- Create or replace directory
|
||||
CREATE OR REPLACE DIRECTORY $DirectoryName AS '$DirectoryPath';
|
||||
GRANT READ, WRITE ON DIRECTORY $DirectoryName TO PUBLIC;
|
||||
COMMIT;
|
||||
SELECT 'DIRECTORY_CREATED' FROM dual;
|
||||
|
||||
-- Verify
|
||||
SELECT 'VERIFIED:' || directory_path FROM dba_directories WHERE directory_name = '$DirectoryName';
|
||||
EXIT;
|
||||
"@
|
||||
|
||||
$result = Invoke-SqlPlus -OracleHome $OracleHome -ServiceName $ServiceName `
|
||||
-Username "SYS" -Password $Password -SqlCommand $sql -AsSysdba -Silent
|
||||
|
||||
if ($result -match "DIRECTORY_CREATED") {
|
||||
Write-Log "Oracle directory $DirectoryName created pointing to $DirectoryPath"
|
||||
return $true
|
||||
# Check verification result
|
||||
if ($result -match "VERIFIED:(.+)") {
|
||||
$verifiedPath = $Matches[1].Trim()
|
||||
if ($verifiedPath.ToUpper() -eq $DirectoryPath.ToUpper()) {
|
||||
Write-Log "Oracle directory $DirectoryName created pointing to $DirectoryPath"
|
||||
return $true
|
||||
}
|
||||
else {
|
||||
Write-LogWarning "Directory path mismatch! Expected: $DirectoryPath, Got: $verifiedPath"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-LogWarning "Could not verify directory creation"
|
||||
Write-LogWarning "SQL output: $result"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
@@ -810,19 +814,44 @@ EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
# Fallback to common paths based on Oracle Home
|
||||
# Fallback: derive path from ORACLE_HOME
|
||||
# Example: C:\app\romfast\product\21c\dbhomeXE -> C:\app\romfast\product\21c\oradata\XE\XEPDB1
|
||||
Write-LogWarning "Could not query datafile path from database, using fallback based on ORACLE_HOME"
|
||||
|
||||
$version = Get-OracleVersion -OracleHome $oraHome -ServiceName $ServiceName -Password $Password
|
||||
|
||||
if ($version.IsXE) {
|
||||
if ($version.Version -match "^21") {
|
||||
return "C:\app\oracle\oradata\XE\XEPDB1"
|
||||
}
|
||||
elseif ($version.Version -match "^18") {
|
||||
return "C:\app\oracle\oradata\XE"
|
||||
# Try to derive oradata path from ORACLE_HOME
|
||||
# Pattern: <base>\product\<version>\dbhomeXE -> <base>\product\<version>\oradata\XE\<PDB>
|
||||
if ($oraHome -match "^(.+\\product\\[^\\]+)\\dbhome") {
|
||||
$baseOradata = "$($Matches[1])\oradata"
|
||||
if ($version.IsXE) {
|
||||
if ($version.Version -match "^21") {
|
||||
return "$baseOradata\XE\XEPDB1"
|
||||
}
|
||||
elseif ($version.Version -match "^18") {
|
||||
return "$baseOradata\XE"
|
||||
}
|
||||
}
|
||||
return $baseOradata
|
||||
}
|
||||
|
||||
# Default fallback
|
||||
# Legacy fallback for non-standard installations
|
||||
# Extract base from ORACLE_HOME (e.g., C:\app\romfast from C:\app\romfast\product\21c\dbhomeXE)
|
||||
if ($oraHome -match "^([A-Z]:\\[^\\]+\\[^\\]+)\\") {
|
||||
$appBase = $Matches[1]
|
||||
if ($version.IsXE) {
|
||||
if ($version.Version -match "^21") {
|
||||
return "$appBase\oradata\XE\XEPDB1"
|
||||
}
|
||||
elseif ($version.Version -match "^18") {
|
||||
return "$appBase\oradata\XE"
|
||||
}
|
||||
}
|
||||
return "$appBase\oradata"
|
||||
}
|
||||
|
||||
# Ultimate fallback - this should rarely be reached
|
||||
Write-LogWarning "Could not derive datafile path from ORACLE_HOME, using hardcoded default"
|
||||
return "C:\app\oracle\oradata"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user