Oracle DR: Fix verification commands and auto-start services
weekly-dr-test-proxmox.sh: - Replace Unix commands (echo, grep) with PowerShell equivalents - Use PowerShell Select-String for database status verification - Fix table count query to work properly through SSH rman_restore_from_zero.ps1: - Set Oracle service to AUTOMATIC startup (was manual) - Set Listener service to AUTOMATIC startup - Auto-start Listener after database restore - Add fallback to lsnrctl if service start fails Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@@ -76,12 +76,12 @@ if (-not (Test-Path "C:\Users\oracle\admin\ROA\pfile\initROA.ora")) {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
& oradim -new -sid ROA -startmode manual -pfile "C:\Users\oracle\admin\ROA\pfile\initROA.ora" 2>&1 | Out-Null
|
& oradim -new -sid ROA -startmode auto -pfile "C:\Users\oracle\admin\ROA\pfile\initROA.ora" 2>&1 | Out-Null
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Host "ERROR: Failed to create Oracle service" -ForegroundColor Red
|
Write-Host "ERROR: Failed to create Oracle service" -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
Write-Host "[OK] Oracle service created successfully"
|
Write-Host "[OK] Oracle service created successfully (AUTOMATIC startup)"
|
||||||
Start-Sleep -Seconds 2
|
Start-Sleep -Seconds 2
|
||||||
|
|
||||||
# Step 2.2: Startup NOMOUNT
|
# Step 2.2: Startup NOMOUNT
|
||||||
@@ -212,12 +212,29 @@ if ($LASTEXITCODE -ne 0) {
|
|||||||
Write-Host "[OK] Service recreated with auto-start mode"
|
Write-Host "[OK] Service recreated with auto-start mode"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Register with listener
|
# Register with listener and start it
|
||||||
|
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 = @"
|
$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 ""
|
Write-Host ""
|
||||||
|
|||||||
@@ -373,11 +373,13 @@ run_dr_test() {
|
|||||||
step_start=$(date +%s)
|
step_start=$(date +%s)
|
||||||
log "STEP 5: Verifying database"
|
log "STEP 5: Verifying database"
|
||||||
|
|
||||||
|
# Use PowerShell to query database status
|
||||||
db_status=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
db_status=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
"cmd /c 'echo SELECT STATUS FROM V\$INSTANCE; | sqlplus -s / as sysdba' | findstr OPEN" || echo "")
|
"powershell -Command \"'SELECT STATUS FROM V\`\$INSTANCE;' | sqlplus -s / as sysdba | Select-String 'OPEN'\"" || echo "")
|
||||||
|
|
||||||
|
# Use PowerShell to count tables
|
||||||
tables_restored=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
tables_restored=$(ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||||
"cmd /c 'echo SELECT COUNT(*) FROM DBA_TABLES WHERE OWNER NOT IN (''SYS'',''SYSTEM''); | sqlplus -s / as sysdba' | grep -o '[0-9]*' | tail -1" || echo "0")
|
"powershell -Command \"'SELECT COUNT(*) FROM DBA_TABLES WHERE OWNER NOT IN (''SYS'',''SYSTEM'');' | sqlplus -s / as sysdba | Select-String -Pattern '[0-9]+' | ForEach-Object { \$_.Matches[0].Value } | Select-Object -Last 1\"" || echo "0")
|
||||||
tables_restored=$(echo "$tables_restored" | tr -cd '0-9')
|
tables_restored=$(echo "$tables_restored" | tr -cd '0-9')
|
||||||
[ -z "$tables_restored" ] && tables_restored=0
|
[ -z "$tables_restored" ] && tables_restored=0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user