Compare commits
4 Commits
839f1b6b82
...
6accd1f996
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6accd1f996 | ||
|
|
026b0436ba | ||
|
|
2f8c927bbe | ||
|
|
3c0beda819 |
@@ -1,102 +0,0 @@
|
||||
@echo off
|
||||
REM Oracle Database Complete Cleanup Script
|
||||
REM Purpose: Remove all database files and services to restore DR VM to clean state
|
||||
REM Run as: Administrator
|
||||
REM Location: D:\oracle\scripts\cleanup_database.cmd
|
||||
|
||||
set ORACLE_HOME=C:\Users\Administrator\Downloads\WINDOWS.X64_193000_db_home
|
||||
set ORACLE_SID=ROA
|
||||
set PATH=%ORACLE_HOME%\bin;%PATH%
|
||||
|
||||
echo ============================================
|
||||
echo Oracle Database Cleanup Script
|
||||
echo ============================================
|
||||
echo.
|
||||
echo This script will:
|
||||
echo 1. Stop and delete Oracle service
|
||||
echo 2. Delete all database files (datafiles, control files, redo logs)
|
||||
echo 3. Delete local FRA (backups are on F:\, safe to delete)
|
||||
echo 4. Delete trace files
|
||||
echo 5. Leave VM in completely clean state (no service, no DB files)
|
||||
echo.
|
||||
echo WARNING: This will DELETE the entire database!
|
||||
echo Starting cleanup in 3 seconds... (Press Ctrl+C to cancel)
|
||||
timeout /t 3 /nobreak > nul
|
||||
|
||||
REM Create temp directory
|
||||
if not exist D:\oracle\temp mkdir D:\oracle\temp
|
||||
if not exist D:\oracle\logs mkdir D:\oracle\logs
|
||||
|
||||
echo.
|
||||
echo [1/6] Shutting down database (if running)...
|
||||
echo SHUTDOWN ABORT; > D:\oracle\temp\cleanup_shutdown.sql
|
||||
echo EXIT; >> D:\oracle\temp\cleanup_shutdown.sql
|
||||
sqlplus -s / as sysdba @D:\oracle\temp\cleanup_shutdown.sql > nul 2>&1
|
||||
timeout /t 3 /nobreak > nul
|
||||
|
||||
echo [2/6] Stopping and deleting Oracle service + registry + instance...
|
||||
REM Method 1: Use oradim to delete Oracle instance (recommended)
|
||||
set ORACLE_HOME=C:\Users\Administrator\Downloads\WINDOWS.X64_193000_db_home
|
||||
set PATH=%ORACLE_HOME%\bin;%PATH%
|
||||
oradim -delete -sid ROA >nul 2>&1
|
||||
echo Oracle instance deleted with oradim
|
||||
|
||||
REM Method 2: Delete service directly (backup method)
|
||||
sc query OracleServiceROA > nul 2>&1
|
||||
if %errorlevel% equ 0 (
|
||||
sc stop OracleServiceROA > nul 2>&1
|
||||
timeout /t 2 /nobreak > nul
|
||||
sc delete OracleServiceROA > nul 2>&1
|
||||
echo Oracle service deleted with sc
|
||||
)
|
||||
|
||||
REM Method 3: Delete Oracle registry keys (ensures clean state)
|
||||
reg delete "HKLM\SOFTWARE\ORACLE\KEY_OraDB19Home1" /v ORA_ROA_PFILE /f >nul 2>&1
|
||||
reg delete "HKLM\SOFTWARE\ORACLE\KEY_OraDB19Home1" /v ORA_ROA_AUTOSTART /f >nul 2>&1
|
||||
reg delete "HKLM\SOFTWARE\ORACLE\KEY_OraDB19Home1" /v ORA_ROA_SHUTDOWN /f >nul 2>&1
|
||||
reg delete "HKLM\SOFTWARE\ORACLE\KEY_OraDB19Home1" /v ORA_ROA_SHUTDOWNTYPE /f >nul 2>&1
|
||||
reg delete "HKLM\SOFTWARE\ORACLE\KEY_OraDB19Home1" /v ORA_ROA_SHUTDOWN_TIMEOUT /f >nul 2>&1
|
||||
echo Registry keys cleaned
|
||||
timeout /t 2 /nobreak > nul
|
||||
|
||||
echo [3/6] Deleting database files...
|
||||
echo Deleting datafiles...
|
||||
del /Q C:\Users\oracle\oradata\ROA\*.dbf 2>nul
|
||||
echo Deleting control files...
|
||||
del /Q C:\Users\oracle\oradata\ROA\*.ctl 2>nul
|
||||
echo Deleting redo logs...
|
||||
del /Q C:\Users\oracle\oradata\ROA\*.log 2>nul
|
||||
|
||||
echo [4/6] Deleting local FRA (backups are on F:\)...
|
||||
if exist C:\Users\oracle\recovery_area\ROA (
|
||||
rmdir /S /Q C:\Users\oracle\recovery_area\ROA 2>nul
|
||||
mkdir C:\Users\oracle\recovery_area\ROA
|
||||
echo FRA cleared
|
||||
) else (
|
||||
mkdir C:\Users\oracle\recovery_area\ROA 2>nul
|
||||
echo FRA directory created
|
||||
)
|
||||
|
||||
echo [5/6] Deleting trace files (to save space)...
|
||||
del /Q C:\Users\oracle\diag\rdbms\roa\ROA\trace\*.trc 2>nul
|
||||
del /Q C:\Users\oracle\diag\rdbms\roa\ROA\trace\*.trm 2>nul
|
||||
echo Trace files deleted
|
||||
|
||||
echo.
|
||||
echo ============================================
|
||||
echo Database Cleanup Complete!
|
||||
echo ============================================
|
||||
echo.
|
||||
echo Current state:
|
||||
echo [YES] Oracle software installed
|
||||
echo [YES] PFILE exists (C:\Users\oracle\admin\ROA\pfile\initROA.ora)
|
||||
echo [NO] Oracle service (will be created during restore)
|
||||
echo [NO] Database files (will be restored from backups)
|
||||
echo [NO] Control files (will be restored from backups)
|
||||
echo [NO] Datafiles (will be restored from backups)
|
||||
echo.
|
||||
echo VM is now in COMPLETELY CLEAN STATE!
|
||||
echo.
|
||||
echo Next step: Run D:\oracle\scripts\rman_restore_from_zero.cmd
|
||||
echo (It will create the Oracle service and restore the database)
|
||||
echo.
|
||||
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
|
||||
34
oracle/standby-server-scripts/initROA.ora
Normal file
34
oracle/standby-server-scripts/initROA.ora
Normal file
@@ -0,0 +1,34 @@
|
||||
# Initialization Parameters for ROA Database - DR VM
|
||||
# Generated: 2025-10-09 04:07:45
|
||||
|
||||
# Database Identification
|
||||
db_name=ROA
|
||||
db_unique_name=ROA
|
||||
|
||||
# Memory Configuration
|
||||
memory_target=1024M
|
||||
memory_max_target=1024M
|
||||
|
||||
# File Locations
|
||||
control_files=('C:\Users\oracle\oradata\ROA\control01.ctl', 'C:\Users\oracle\recovery_area\ROA\control02.ctl')
|
||||
db_recovery_file_dest='C:\Users\oracle\recovery_area'
|
||||
db_recovery_file_dest_size=20G
|
||||
audit_file_dest='C:\Users\oracle\admin\ROA\adump'
|
||||
|
||||
# Redo and Archive Log
|
||||
log_archive_format=%t_%s_%r.dbf
|
||||
|
||||
# Compatibility
|
||||
compatible=19.0.0
|
||||
|
||||
# Character Set
|
||||
nls_language=AMERICAN
|
||||
nls_territory=AMERICA
|
||||
|
||||
# Processes and Sessions
|
||||
processes=300
|
||||
sessions=472
|
||||
|
||||
# Miscellaneous
|
||||
diagnostic_dest='C:\Users\oracle'
|
||||
_allow_resetlogs_corruption=TRUE
|
||||
43
oracle/standby-server-scripts/rman_backup.bat
Normal file
43
oracle/standby-server-scripts/rman_backup.bat
Normal file
@@ -0,0 +1,43 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM ===================================================================
|
||||
REM Oracle RMAN FULL Backup with Logging
|
||||
REM Runs at: 02:30 AM (scheduled task)
|
||||
REM Duration: ~30 minutes
|
||||
REM ===================================================================
|
||||
|
||||
REM Get script directory (where this .bat file is located)
|
||||
set SCRIPTDIR=%~dp0
|
||||
set LOGDIR=%SCRIPTDIR%logs
|
||||
set TIMESTAMP=%date:~-4,4%%date:~-7,2%%date:~-10,2%_%time:~0,2%%time:~3,2%%time:~6,2%
|
||||
set TIMESTAMP=%TIMESTAMP: =0%
|
||||
set LOGFILE=%LOGDIR%\backup_full_%TIMESTAMP%.log
|
||||
|
||||
REM Create log directory if not exists
|
||||
if not exist "%LOGDIR%" mkdir "%LOGDIR%"
|
||||
|
||||
echo ========================================= >> "%LOGFILE%" 2>&1
|
||||
echo Oracle RMAN FULL Backup Started >> "%LOGFILE%" 2>&1
|
||||
echo Date: %date% %time% >> "%LOGFILE%" 2>&1
|
||||
echo Script Directory: %SCRIPTDIR% >> "%LOGFILE%" 2>&1
|
||||
echo ========================================= >> "%LOGFILE%" 2>&1
|
||||
echo. >> "%LOGFILE%" 2>&1
|
||||
|
||||
REM Run RMAN backup - show in console AND save to log (using PowerShell tee)
|
||||
powershell -Command "& cmd.exe /c 'rman target sys/romfastsoft@roa cmdfile=\"%SCRIPTDIR%rman_backup.txt\"' 2>&1 | Tee-Object -FilePath '%LOGFILE%' -Append"
|
||||
|
||||
set EXITCODE=%ERRORLEVEL%
|
||||
|
||||
echo. >> "%LOGFILE%" 2>&1
|
||||
echo ========================================= >> "%LOGFILE%" 2>&1
|
||||
echo Oracle RMAN FULL Backup Completed >> "%LOGFILE%" 2>&1
|
||||
echo Date: %date% %time% >> "%LOGFILE%" 2>&1
|
||||
echo Exit Code: %EXITCODE% >> "%LOGFILE%" 2>&1
|
||||
echo ========================================= >> "%LOGFILE%" 2>&1
|
||||
|
||||
REM Print summary to console
|
||||
echo [%date% %time%] RMAN FULL backup completed with exit code: %EXITCODE%
|
||||
echo [%date% %time%] Log file: %LOGFILE%
|
||||
|
||||
exit /b %EXITCODE%
|
||||
19
oracle/standby-server-scripts/rman_backup.txt
Normal file
19
oracle/standby-server-scripts/rman_backup.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
RUN {
|
||||
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
|
||||
CONFIGURE CONTROLFILE AUTOBACKUP ON;
|
||||
CONFIGURE COMPRESSION ALGORITHM 'BASIC';
|
||||
|
||||
# Full backup COMPRESSED + Archive logs (șterge logs după backup)
|
||||
BACKUP AS COMPRESSED BACKUPSET
|
||||
INCREMENTAL LEVEL 0
|
||||
TAG 'DAILY_FULL_COMPRESSED'
|
||||
DATABASE
|
||||
PLUS ARCHIVELOG DELETE INPUT;
|
||||
|
||||
# Backup SPFILE și Control File
|
||||
BACKUP AS COMPRESSED BACKUPSET SPFILE;
|
||||
BACKUP CURRENT CONTROLFILE;
|
||||
|
||||
# Cleanup old backups (păstrează ultimele 2 - REDUNDANCY 2)
|
||||
DELETE NOPROMPT OBSOLETE;
|
||||
}
|
||||
43
oracle/standby-server-scripts/rman_backup_incremental.bat
Normal file
43
oracle/standby-server-scripts/rman_backup_incremental.bat
Normal file
@@ -0,0 +1,43 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM ===================================================================
|
||||
REM Oracle RMAN INCREMENTAL/CUMULATIVE Backup with Logging
|
||||
REM Runs at: 13:00 and 18:00 (scheduled tasks)
|
||||
REM Duration: ~5-10 minutes
|
||||
REM ===================================================================
|
||||
|
||||
REM Get script directory (where this .bat file is located)
|
||||
set SCRIPTDIR=%~dp0
|
||||
set LOGDIR=%SCRIPTDIR%logs
|
||||
set TIMESTAMP=%date:~-4,4%%date:~-7,2%%date:~-10,2%_%time:~0,2%%time:~3,2%%time:~6,2%
|
||||
set TIMESTAMP=%TIMESTAMP: =0%
|
||||
set LOGFILE=%LOGDIR%\backup_incremental_%TIMESTAMP%.log
|
||||
|
||||
REM Create log directory if not exists
|
||||
if not exist "%LOGDIR%" mkdir "%LOGDIR%"
|
||||
|
||||
echo ========================================= >> "%LOGFILE%" 2>&1
|
||||
echo Oracle RMAN INCREMENTAL Backup Started >> "%LOGFILE%" 2>&1
|
||||
echo Date: %date% %time% >> "%LOGFILE%" 2>&1
|
||||
echo Script Directory: %SCRIPTDIR% >> "%LOGFILE%" 2>&1
|
||||
echo ========================================= >> "%LOGFILE%" 2>&1
|
||||
echo. >> "%LOGFILE%" 2>&1
|
||||
|
||||
REM Run RMAN backup - show in console AND save to log (using PowerShell tee)
|
||||
powershell -Command "& cmd.exe /c 'rman target sys/romfastsoft@roa cmdfile=\"%SCRIPTDIR%rman_backup_incremental.txt\"' 2>&1 | Tee-Object -FilePath '%LOGFILE%' -Append"
|
||||
|
||||
set EXITCODE=%ERRORLEVEL%
|
||||
|
||||
echo. >> "%LOGFILE%" 2>&1
|
||||
echo ========================================= >> "%LOGFILE%" 2>&1
|
||||
echo Oracle RMAN INCREMENTAL Backup Completed >> "%LOGFILE%" 2>&1
|
||||
echo Date: %date% %time% >> "%LOGFILE%" 2>&1
|
||||
echo Exit Code: %EXITCODE% >> "%LOGFILE%" 2>&1
|
||||
echo ========================================= >> "%LOGFILE%" 2>&1
|
||||
|
||||
REM Print summary to console
|
||||
echo [%date% %time%] RMAN INCREMENTAL backup completed with exit code: %EXITCODE%
|
||||
echo [%date% %time%] Log file: %LOGFILE%
|
||||
|
||||
exit /b %EXITCODE%
|
||||
15
oracle/standby-server-scripts/rman_backup_incremental.txt
Normal file
15
oracle/standby-server-scripts/rman_backup_incremental.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
RUN {
|
||||
# Incremental Level 1 CUMULATIVE backup
|
||||
# Backup doar modificările de la ultimul Level 0 (full backup de la 02:00 AM)
|
||||
BACKUP AS COMPRESSED BACKUPSET
|
||||
INCREMENTAL LEVEL 1 CUMULATIVE
|
||||
TAG 'MIDDAY_INCREMENTAL'
|
||||
DATABASE
|
||||
PLUS ARCHIVELOG DELETE INPUT;
|
||||
|
||||
# Backup SPFILE și controlfile (pentru siguranță)
|
||||
BACKUP AS COMPRESSED BACKUPSET SPFILE;
|
||||
BACKUP CURRENT CONTROLFILE;
|
||||
|
||||
# NU ștergem obsolete aici - se face la full backup
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
@echo off
|
||||
REM RMAN Restore Database - FINAL VERSION
|
||||
REM Backups are in FRA - RMAN will find them automatically
|
||||
REM Run this script as Administrator on DR VM (10.0.20.37)
|
||||
|
||||
set ORACLE_HOME=C:\Users\Administrator\Downloads\WINDOWS.X64_193000_db_home
|
||||
set ORACLE_SID=ROA
|
||||
set PATH=%ORACLE_HOME%\bin;%PATH%
|
||||
|
||||
echo ============================================
|
||||
echo RMAN Database Restore - DR VM (FINAL)
|
||||
echo ============================================
|
||||
echo.
|
||||
echo Database: ROA
|
||||
echo DBID: 1363569330
|
||||
echo Backups: F:\ROA\autobackup (NFS mount from Proxmox)
|
||||
echo.
|
||||
|
||||
REM Verify F:\ mount is accessible
|
||||
if not exist F:\ROA\autobackup (
|
||||
echo ERROR: F:\ROA\autobackup not accessible!
|
||||
echo Make sure NFS mount is active: mount -o rw,nolock,mtype=hard,timeout=60 10.0.20.202:/mnt/pve/oracle-backups F:
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Create temp directory
|
||||
if not exist D:\oracle\temp mkdir D:\oracle\temp
|
||||
|
||||
REM Step 1: Shutdown database if running
|
||||
echo [1/5] Shutting down database if running...
|
||||
echo SHUTDOWN ABORT; > D:\oracle\temp\shutdown.sql
|
||||
echo EXIT; >> D:\oracle\temp\shutdown.sql
|
||||
sqlplus -s / as sysdba @D:\oracle\temp\shutdown.sql > nul 2>&1
|
||||
timeout /t 2 /nobreak > nul
|
||||
|
||||
REM Step 2: Startup NOMOUNT
|
||||
echo [2/5] Starting database in NOMOUNT mode...
|
||||
echo STARTUP NOMOUNT PFILE='C:\Users\oracle\admin\ROA\pfile\initROA.ora'; > D:\oracle\temp\nomount.sql
|
||||
echo EXIT; >> D:\oracle\temp\nomount.sql
|
||||
sqlplus / as sysdba @D:\oracle\temp\nomount.sql
|
||||
timeout /t 3 /nobreak > nul
|
||||
|
||||
REM Step 3: Create simplified RMAN script
|
||||
echo [3/5] Creating RMAN restore script...
|
||||
set RMAN_SCRIPT=D:\oracle\temp\restore_final.rman
|
||||
|
||||
echo SET DBID 1363569330; > %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo RUN { >> %RMAN_SCRIPT%
|
||||
echo ALLOCATE CHANNEL ch1 DEVICE TYPE DISK; >> %RMAN_SCRIPT%
|
||||
echo SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'F:/ROA/autobackup/%%F'; >> %RMAN_SCRIPT%
|
||||
echo RESTORE CONTROLFILE FROM AUTOBACKUP; >> %RMAN_SCRIPT%
|
||||
echo RELEASE CHANNEL ch1; >> %RMAN_SCRIPT%
|
||||
echo } >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo ALTER DATABASE MOUNT; >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo CATALOG START WITH 'F:/ROA/autobackup' NOPROMPT; >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo RUN { >> %RMAN_SCRIPT%
|
||||
echo ALLOCATE CHANNEL ch1 DEVICE TYPE DISK; >> %RMAN_SCRIPT%
|
||||
echo ALLOCATE CHANNEL ch2 DEVICE TYPE DISK; >> %RMAN_SCRIPT%
|
||||
echo RESTORE DATABASE; >> %RMAN_SCRIPT%
|
||||
echo RELEASE CHANNEL ch1; >> %RMAN_SCRIPT%
|
||||
echo RELEASE CHANNEL ch2; >> %RMAN_SCRIPT%
|
||||
echo } >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo RUN { >> %RMAN_SCRIPT%
|
||||
echo ALLOCATE CHANNEL ch1 DEVICE TYPE DISK; >> %RMAN_SCRIPT%
|
||||
echo RECOVER DATABASE NOREDO; >> %RMAN_SCRIPT%
|
||||
echo RELEASE CHANNEL ch1; >> %RMAN_SCRIPT%
|
||||
echo } >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo ALTER DATABASE OPEN RESETLOGS; >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo ALTER TABLESPACE TEMP ADD TEMPFILE 'C:\Users\oracle\oradata\ROA\temp01.dbf' SIZE 567M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE 32767M; >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo EXIT; >> %RMAN_SCRIPT%
|
||||
|
||||
REM Step 4: Run RMAN restore
|
||||
echo [4/5] Running RMAN restore (this will take 10-20 minutes)...
|
||||
rman target / cmdfile=%RMAN_SCRIPT% log=D:\oracle\logs\rman_restore_final.log
|
||||
|
||||
REM Step 5: Verify database status
|
||||
echo.
|
||||
echo [5/5] Verifying database status...
|
||||
echo SET PAGESIZE 100 LINESIZE 200 > D:\oracle\temp\verify.sql
|
||||
echo SELECT 'DB_NAME: ' ^|^| NAME ^|^| ', OPEN_MODE: ' ^|^| OPEN_MODE FROM V$DATABASE; >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'INSTANCE: ' ^|^| INSTANCE_NAME ^|^| ', STATUS: ' ^|^| STATUS FROM V$INSTANCE; >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'TABLESPACES: ' ^|^| COUNT(*) FROM DBA_TABLESPACES; >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'DATAFILES: ' ^|^| COUNT(*) FROM DBA_DATA_FILES; >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'TABLES: ' ^|^| COUNT(*) FROM DBA_TABLES WHERE OWNER NOT IN ('SYS','SYSTEM'); >> D:\oracle\temp\verify.sql
|
||||
echo EXIT; >> D:\oracle\temp\verify.sql
|
||||
|
||||
sqlplus -s / as sysdba @D:\oracle\temp\verify.sql
|
||||
|
||||
echo.
|
||||
echo ============================================
|
||||
echo Database Restore Complete!
|
||||
echo ============================================
|
||||
echo.
|
||||
echo Log: D:\oracle\logs\rman_restore_final.log
|
||||
echo.
|
||||
echo Next steps:
|
||||
echo 1. Test database connectivity
|
||||
echo 2. Verify application tables
|
||||
echo 3. Configure RMAN retention
|
||||
echo 4. Shutdown DR VM to conserve resources
|
||||
echo.
|
||||
@@ -1,226 +0,0 @@
|
||||
@echo off
|
||||
REM RMAN Restore Database FROM ZERO - Clean State
|
||||
REM Backups are on F:\ (NFS mount from Proxmox host)
|
||||
REM This script:
|
||||
REM 1. Cleans up any existing database (calls cleanup_database.cmd)
|
||||
REM 2. Restores from F:\ backups
|
||||
REM 3. Verifies database
|
||||
REM Run this script as Administrator on DR VM (10.0.20.37)
|
||||
REM Location: D:\oracle\scripts\rman_restore_from_zero.cmd
|
||||
|
||||
set ORACLE_HOME=C:\Users\Administrator\Downloads\WINDOWS.X64_193000_db_home
|
||||
set ORACLE_SID=ROA
|
||||
set PATH=%ORACLE_HOME%\bin;%PATH%
|
||||
|
||||
echo ============================================
|
||||
echo RMAN Database Restore FROM ZERO
|
||||
echo ============================================
|
||||
echo.
|
||||
echo Database: ROA
|
||||
echo DBID: 1363569330
|
||||
echo Backups: F:\ROA\autobackup (NFS mount from Proxmox)
|
||||
echo.
|
||||
echo This script will:
|
||||
echo 1. CLEANUP: Delete any existing database files
|
||||
echo 2. RESTORE: Restore from F:\ backups
|
||||
echo 3. VERIFY: Check database is working
|
||||
echo.
|
||||
|
||||
REM Verify F:\ mount is accessible
|
||||
if not exist F:\ROA\autobackup (
|
||||
echo ERROR: F:\ROA\autobackup not accessible!
|
||||
echo.
|
||||
echo Please verify:
|
||||
echo 1. F:\ drive is mounted: dir F:\
|
||||
echo 2. NFS mount command: mount -o rw,nolock,mtype=hard,timeout=60 10.0.20.202:/mnt/pve/oracle-backups F:
|
||||
echo 3. Proxmox host is reachable: ping 10.0.20.202
|
||||
echo.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [OK] F:\ROA\autobackup is accessible
|
||||
echo.
|
||||
|
||||
REM Create directories
|
||||
if not exist D:\oracle\temp mkdir D:\oracle\temp
|
||||
if not exist D:\oracle\logs mkdir D:\oracle\logs
|
||||
|
||||
echo ============================================
|
||||
echo STEP 1: CLEANUP - Delete existing database
|
||||
echo ============================================
|
||||
echo.
|
||||
echo Calling cleanup_database.cmd...
|
||||
echo.
|
||||
|
||||
REM Call cleanup script (same directory)
|
||||
call D:\oracle\scripts\cleanup_database.cmd
|
||||
if %errorlevel% neq 0 (
|
||||
echo.
|
||||
echo ERROR: Cleanup failed!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [OK] Cleanup complete - VM is in clean state
|
||||
echo.
|
||||
echo Starting restore in 2 seconds...
|
||||
timeout /t 2 /nobreak > nul
|
||||
|
||||
echo ============================================
|
||||
echo STEP 2: RESTORE - Restore from F:\ backups
|
||||
echo ============================================
|
||||
echo.
|
||||
|
||||
REM Step 2.1: Create Oracle service (needed for sqlplus to connect)
|
||||
echo [2.1] Creating Oracle service from PFILE...
|
||||
if not exist C:\Users\oracle\admin\ROA\pfile\initROA.ora (
|
||||
echo ERROR: PFILE not found at C:\Users\oracle\admin\ROA\pfile\initROA.ora
|
||||
echo Cannot create Oracle service without PFILE!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
oradim -new -sid ROA -startmode manual -pfile C:\Users\oracle\admin\ROA\pfile\initROA.ora
|
||||
if %errorlevel% neq 0 (
|
||||
echo ERROR: Failed to create Oracle service
|
||||
exit /b 1
|
||||
)
|
||||
echo [OK] Oracle service created successfully
|
||||
timeout /t 2 /nobreak > nul
|
||||
|
||||
REM Step 2.2: Startup NOMOUNT
|
||||
echo [2.2] Starting database in NOMOUNT mode...
|
||||
echo STARTUP NOMOUNT PFILE='C:\Users\oracle\admin\ROA\pfile\initROA.ora'; > D:\oracle\temp\nomount.sql
|
||||
echo EXIT; >> D:\oracle\temp\nomount.sql
|
||||
sqlplus / as sysdba @D:\oracle\temp\nomount.sql
|
||||
if %errorlevel% neq 0 (
|
||||
echo ERROR: Failed to startup NOMOUNT
|
||||
exit /b 1
|
||||
)
|
||||
echo [OK] Database started in NOMOUNT mode
|
||||
timeout /t 3 /nobreak > nul
|
||||
|
||||
REM Step 2.3: Create RMAN restore script
|
||||
echo [2.3] Creating RMAN restore script...
|
||||
set RMAN_SCRIPT=D:\oracle\temp\restore_from_zero.rman
|
||||
set LOG_FILE=D:\oracle\logs\restore_from_zero.log
|
||||
|
||||
REM Copy ALL backups from F:\ to recovery area (RMAN works best with backups in recovery area)
|
||||
if not exist C:\Users\oracle\recovery_area\ROA\autobackup mkdir C:\Users\oracle\recovery_area\ROA\autobackup
|
||||
echo [INFO] Copying all backups from F:\ROA\autobackup to recovery area...
|
||||
echo This may take 1-2 minutes for ~6.7 GB of backups...
|
||||
xcopy /Y /Q "F:\ROA\autobackup\*.BKP" "C:\Users\oracle\recovery_area\ROA\autobackup\" > nul
|
||||
if %errorlevel% neq 0 (
|
||||
echo ERROR: Failed to copy backups from F:\
|
||||
exit /b 1
|
||||
)
|
||||
echo [OK] All backups copied to recovery area
|
||||
|
||||
echo SET DBID 1363569330; > %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo RUN { >> %RMAN_SCRIPT%
|
||||
echo ALLOCATE CHANNEL ch1 DEVICE TYPE DISK; >> %RMAN_SCRIPT%
|
||||
echo RESTORE CONTROLFILE FROM AUTOBACKUP; >> %RMAN_SCRIPT%
|
||||
echo RELEASE CHANNEL ch1; >> %RMAN_SCRIPT%
|
||||
echo } >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo ALTER DATABASE MOUNT; >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo CATALOG START WITH 'F:/ROA/autobackup' NOPROMPT; >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo RUN { >> %RMAN_SCRIPT%
|
||||
echo ALLOCATE CHANNEL ch1 DEVICE TYPE DISK; >> %RMAN_SCRIPT%
|
||||
echo ALLOCATE CHANNEL ch2 DEVICE TYPE DISK; >> %RMAN_SCRIPT%
|
||||
echo RESTORE DATABASE; >> %RMAN_SCRIPT%
|
||||
echo RELEASE CHANNEL ch1; >> %RMAN_SCRIPT%
|
||||
echo RELEASE CHANNEL ch2; >> %RMAN_SCRIPT%
|
||||
echo } >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo RUN { >> %RMAN_SCRIPT%
|
||||
echo ALLOCATE CHANNEL ch1 DEVICE TYPE DISK; >> %RMAN_SCRIPT%
|
||||
echo RECOVER DATABASE NOREDO; >> %RMAN_SCRIPT%
|
||||
echo RELEASE CHANNEL ch1; >> %RMAN_SCRIPT%
|
||||
echo } >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
echo ALTER DATABASE OPEN RESETLOGS; >> %RMAN_SCRIPT%
|
||||
echo. >> %RMAN_SCRIPT%
|
||||
REM Note: TEMP tablespace is automatically restored - no need to add manually
|
||||
echo EXIT; >> %RMAN_SCRIPT%
|
||||
|
||||
echo [OK] RMAN script created: %RMAN_SCRIPT%
|
||||
|
||||
REM Step 2.4: Run RMAN restore
|
||||
echo [2.4] Running RMAN restore (this will take 10-20 minutes)...
|
||||
echo Log file: %LOG_FILE%
|
||||
echo.
|
||||
rman target / cmdfile=%RMAN_SCRIPT% log=%LOG_FILE%
|
||||
|
||||
if %errorlevel% neq 0 (
|
||||
echo.
|
||||
echo ERROR: RMAN restore failed!
|
||||
echo Check log: %LOG_FILE%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [OK] RMAN restore completed successfully!
|
||||
echo.
|
||||
|
||||
echo ============================================
|
||||
echo STEP 3: VERIFY - Check database status
|
||||
echo ============================================
|
||||
echo.
|
||||
echo [3.1] Verifying database...
|
||||
|
||||
echo SET PAGESIZE 100 LINESIZE 200 > D:\oracle\temp\verify.sql
|
||||
echo COLUMN info FORMAT A80 >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'DB_NAME: ' ^|^| NAME ^|^| ', OPEN_MODE: ' ^|^| OPEN_MODE AS info FROM V$DATABASE; >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'INSTANCE: ' ^|^| INSTANCE_NAME ^|^| ', STATUS: ' ^|^| STATUS AS info FROM V$INSTANCE; >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'TABLESPACES: ' ^|^| COUNT(*) AS info FROM DBA_TABLESPACES; >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'DATAFILES: ' ^|^| COUNT(*) AS info FROM DBA_DATA_FILES; >> D:\oracle\temp\verify.sql
|
||||
echo SELECT 'TABLES: ' ^|^| COUNT(*) AS info FROM DBA_TABLES WHERE OWNER NOT IN ('SYS','SYSTEM'); >> D:\oracle\temp\verify.sql
|
||||
echo EXIT; >> D:\oracle\temp\verify.sql
|
||||
|
||||
sqlplus -s / as sysdba @D:\oracle\temp\verify.sql
|
||||
|
||||
echo.
|
||||
echo [3.2] Creating SPFILE for database persistence...
|
||||
echo CREATE SPFILE FROM PFILE='C:\Users\oracle\admin\ROA\pfile\initROA.ora'; > D:\oracle\temp\create_spfile.sql
|
||||
echo EXIT; >> D:\oracle\temp\create_spfile.sql
|
||||
sqlplus / as sysdba @D:\oracle\temp\create_spfile.sql
|
||||
if %errorlevel% neq 0 (
|
||||
echo WARNING: Failed to create SPFILE - database may not persist after connections close
|
||||
) else (
|
||||
echo [OK] SPFILE created successfully
|
||||
|
||||
REM Recreate service with auto-start and SPFILE
|
||||
echo [3.3] Recreating Oracle service with auto-start mode...
|
||||
oradim -delete -sid ROA 2>nul
|
||||
timeout /t 2 /nobreak > nul
|
||||
oradim -new -sid ROA -startmode auto -spfile
|
||||
if %errorlevel% neq 0 (
|
||||
echo WARNING: Failed to recreate service with auto-start
|
||||
) else (
|
||||
echo [OK] Service recreated with auto-start mode
|
||||
)
|
||||
|
||||
REM Register with listener
|
||||
echo ALTER SYSTEM REGISTER; > D:\oracle\temp\register.sql
|
||||
echo EXIT; >> D:\oracle\temp\register.sql
|
||||
sqlplus / as sysdba @D:\oracle\temp\register.sql
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ============================================
|
||||
echo Database Restore FROM ZERO Complete!
|
||||
echo ============================================
|
||||
echo.
|
||||
echo Restore log: %LOG_FILE%
|
||||
echo.
|
||||
echo Database is OPEN and ready for testing!
|
||||
echo.
|
||||
echo Next steps:
|
||||
echo 1. Test application connectivity
|
||||
echo 2. Verify data integrity
|
||||
echo 3. Run cleanup_database.cmd to remove database after test
|
||||
echo 4. Shutdown DR VM to conserve resources
|
||||
echo.
|
||||
256
oracle/standby-server-scripts/rman_restore_from_zero.ps1
Normal file
256
oracle/standby-server-scripts/rman_restore_from_zero.ps1
Normal file
@@ -0,0 +1,256 @@
|
||||
# RMAN Restore Database FROM ZERO - Clean State (PowerShell)
|
||||
# Backups are on F:\ (NFS mount from Proxmox host)
|
||||
# Run as: Administrator
|
||||
# Location: D:\oracle\scripts\rman_restore_from_zero.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 "RMAN Database Restore FROM ZERO"
|
||||
Write-Host "============================================"
|
||||
Write-Host ""
|
||||
Write-Host "Database: ROA"
|
||||
Write-Host "DBID: 1363569330"
|
||||
Write-Host "Backups: F:\ROA\autobackup (NFS mount from Proxmox)"
|
||||
Write-Host ""
|
||||
Write-Host "This script will:"
|
||||
Write-Host " 1. CLEANUP: Delete any existing database files"
|
||||
Write-Host " 2. RESTORE: Restore from F:\ backups"
|
||||
Write-Host " 3. VERIFY: Check database is working"
|
||||
Write-Host ""
|
||||
|
||||
# Verify F:\ mount is accessible
|
||||
if (-not (Test-Path "F:\ROA\autobackup")) {
|
||||
Write-Host "ERROR: F:\ROA\autobackup not accessible!" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Write-Host "Please verify:"
|
||||
Write-Host " 1. F:\ drive is mounted: dir F:\"
|
||||
Write-Host " 2. NFS mount command: mount -o rw,nolock,mtype=hard,timeout=60 10.0.20.202:/mnt/pve/oracle-backups F:"
|
||||
Write-Host " 3. Proxmox host is reachable: ping 10.0.20.202"
|
||||
Write-Host ""
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "[OK] F:\ROA\autobackup is accessible"
|
||||
Write-Host ""
|
||||
|
||||
# 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 "STEP 1: CLEANUP - Delete existing database"
|
||||
Write-Host "============================================"
|
||||
Write-Host ""
|
||||
Write-Host "Calling cleanup_database.ps1..."
|
||||
Write-Host ""
|
||||
|
||||
# Call cleanup script with /SILENT flag
|
||||
& "D:\oracle\scripts\cleanup_database.ps1" /SILENT
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host ""
|
||||
Write-Host "ERROR: Cleanup failed!" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "[OK] Cleanup complete - VM is in clean state"
|
||||
Write-Host ""
|
||||
Write-Host "Starting restore in 2 seconds..."
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
Write-Host "============================================"
|
||||
Write-Host "STEP 2: RESTORE - Restore from F:\ backups"
|
||||
Write-Host "============================================"
|
||||
Write-Host ""
|
||||
|
||||
# Step 2.1: Create Oracle service
|
||||
Write-Host "[2.1] Creating Oracle service from PFILE..."
|
||||
if (-not (Test-Path "C:\Users\oracle\admin\ROA\pfile\initROA.ora")) {
|
||||
Write-Host "ERROR: PFILE not found at C:\Users\oracle\admin\ROA\pfile\initROA.ora" -ForegroundColor Red
|
||||
Write-Host "Cannot create Oracle service without PFILE!"
|
||||
exit 1
|
||||
}
|
||||
|
||||
& oradim -new -sid ROA -startmode auto -pfile "C:\Users\oracle\admin\ROA\pfile\initROA.ora" 2>&1 | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "ERROR: Failed to create Oracle service" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Write-Host "[OK] Oracle service created successfully (AUTOMATIC startup)"
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
# Step 2.2: Startup NOMOUNT
|
||||
Write-Host "[2.2] Starting database in NOMOUNT mode..."
|
||||
$nomountSQL = @"
|
||||
STARTUP NOMOUNT PFILE='C:\Users\oracle\admin\ROA\pfile\initROA.ora';
|
||||
EXIT;
|
||||
"@
|
||||
|
||||
$nomountSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "ERROR: Failed to startup NOMOUNT" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Write-Host "[OK] Database started in NOMOUNT mode"
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
# Step 2.3: Copy backups and create RMAN script
|
||||
Write-Host "[2.3] Preparing RMAN restore..."
|
||||
$rmanScript = "D:\oracle\temp\restore_from_zero.rman"
|
||||
$logFile = "D:\oracle\logs\restore_from_zero.log"
|
||||
|
||||
# Copy ALL backups from F:\ to recovery area
|
||||
New-Item -ItemType Directory -Path "C:\Users\oracle\recovery_area\ROA\autobackup" -Force | Out-Null
|
||||
Write-Host "[INFO] Copying all backups from F:\ROA\autobackup to recovery area..."
|
||||
Write-Host " This may take 1-2 minutes for ~10 GB of backups..."
|
||||
Copy-Item "F:\ROA\autobackup\*.BKP" "C:\Users\oracle\recovery_area\ROA\autobackup\" -Force -ErrorAction Stop
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "ERROR: Failed to copy backups from F:\" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Write-Host "[OK] All backups copied to recovery area"
|
||||
|
||||
# Create RMAN script
|
||||
$rmanContent = @"
|
||||
SET DBID 1363569330;
|
||||
|
||||
RUN {
|
||||
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK;
|
||||
RESTORE CONTROLFILE FROM AUTOBACKUP;
|
||||
RELEASE CHANNEL ch1;
|
||||
}
|
||||
|
||||
ALTER DATABASE MOUNT;
|
||||
|
||||
CATALOG START WITH 'F:/ROA/autobackup' NOPROMPT;
|
||||
|
||||
RUN {
|
||||
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK;
|
||||
ALLOCATE CHANNEL ch2 DEVICE TYPE DISK;
|
||||
RESTORE DATABASE;
|
||||
RELEASE CHANNEL ch1;
|
||||
RELEASE CHANNEL ch2;
|
||||
}
|
||||
|
||||
RUN {
|
||||
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK;
|
||||
RECOVER DATABASE NOREDO;
|
||||
RELEASE CHANNEL ch1;
|
||||
}
|
||||
|
||||
ALTER DATABASE OPEN RESETLOGS;
|
||||
|
||||
EXIT;
|
||||
"@
|
||||
|
||||
$rmanContent | Out-File -FilePath $rmanScript -Encoding ASCII
|
||||
Write-Host "[OK] RMAN script created: $rmanScript"
|
||||
|
||||
# Step 2.4: Run RMAN restore
|
||||
Write-Host "[2.4] Running RMAN restore (this will take 10-20 minutes)..."
|
||||
Write-Host " Log file: $logFile"
|
||||
Write-Host ""
|
||||
|
||||
& rman target / cmdfile=$rmanScript log=$logFile
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host ""
|
||||
Write-Host "ERROR: RMAN restore failed!" -ForegroundColor Red
|
||||
Write-Host "Check log: $logFile"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "[OK] RMAN restore completed successfully!"
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "============================================"
|
||||
Write-Host "STEP 3: VERIFY - Check database status"
|
||||
Write-Host "============================================"
|
||||
Write-Host ""
|
||||
Write-Host "[3.1] Verifying database..."
|
||||
|
||||
$verifySQL = @"
|
||||
SET PAGESIZE 100 LINESIZE 200
|
||||
COLUMN info FORMAT A80
|
||||
SELECT 'DB_NAME: ' || NAME || ', OPEN_MODE: ' || OPEN_MODE AS info FROM V`$DATABASE;
|
||||
SELECT 'INSTANCE: ' || INSTANCE_NAME || ', STATUS: ' || STATUS AS info FROM V`$INSTANCE;
|
||||
SELECT 'TABLESPACES: ' || COUNT(*) AS info FROM DBA_TABLESPACES;
|
||||
SELECT 'DATAFILES: ' || COUNT(*) AS info FROM DBA_DATA_FILES;
|
||||
SELECT 'TABLES: ' || COUNT(*) AS info FROM DBA_TABLES WHERE OWNER NOT IN ('SYS','SYSTEM');
|
||||
EXIT;
|
||||
"@
|
||||
|
||||
$verifySQL | & sqlplus -S / as sysdba
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "[3.2] Creating SPFILE for database persistence..."
|
||||
$spfileSQL = @"
|
||||
CREATE SPFILE FROM PFILE='C:\Users\oracle\admin\ROA\pfile\initROA.ora';
|
||||
EXIT;
|
||||
"@
|
||||
|
||||
$spfileSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "WARNING: Failed to create SPFILE - database may not persist after connections close" -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "[OK] SPFILE created successfully"
|
||||
|
||||
# Recreate service with auto-start and SPFILE
|
||||
Write-Host "[3.3] Recreating Oracle service with auto-start mode..."
|
||||
& oradim -delete -sid ROA 2>&1 | Out-Null
|
||||
Start-Sleep -Seconds 2
|
||||
& oradim -new -sid ROA -startmode auto -spfile 2>&1 | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "WARNING: Failed to recreate service with auto-start" -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "[OK] Service recreated with auto-start mode"
|
||||
}
|
||||
|
||||
# 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 = @"
|
||||
ALTER SYSTEM REGISTER;
|
||||
EXIT;
|
||||
"@
|
||||
$registerSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null
|
||||
Write-Host "[OK] Database registered with Listener"
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "============================================"
|
||||
Write-Host "Database Restore FROM ZERO Complete!"
|
||||
Write-Host "============================================"
|
||||
Write-Host ""
|
||||
Write-Host "Restore log: $logFile"
|
||||
Write-Host ""
|
||||
Write-Host "Database is OPEN and ready for testing!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Next steps:"
|
||||
Write-Host " 1. Test application connectivity"
|
||||
Write-Host " 2. Verify data integrity"
|
||||
Write-Host " 3. Run cleanup_database.ps1 to remove database after test"
|
||||
Write-Host " 4. Shutdown DR VM to conserve resources"
|
||||
Write-Host ""
|
||||
|
||||
exit 0
|
||||
@@ -362,7 +362,7 @@ run_dr_test() {
|
||||
log "STEP 4: Running database restore"
|
||||
|
||||
if ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||
"D:\\oracle\\scripts\\rman_restore_from_zero.cmd" 2>&1 | tee -a "$LOG_FILE"; then
|
||||
"powershell -ExecutionPolicy Bypass -File D:\\oracle\\scripts\\rman_restore_from_zero.ps1" 2>&1 | tee -a "$LOG_FILE"; then
|
||||
|
||||
local restore_end=$(date +%s)
|
||||
restore_duration=$(( (restore_end - restore_start) / 60 ))
|
||||
@@ -373,11 +373,13 @@ run_dr_test() {
|
||||
step_start=$(date +%s)
|
||||
log "STEP 5: Verifying database"
|
||||
|
||||
# Use PowerShell to query database status
|
||||
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" \
|
||||
"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')
|
||||
[ -z "$tables_restored" ] && tables_restored=0
|
||||
|
||||
@@ -400,7 +402,7 @@ run_dr_test() {
|
||||
log "STEP 6: Running cleanup"
|
||||
|
||||
ssh -p "$DR_VM_PORT" "$DR_VM_USER@$DR_VM_IP" \
|
||||
"D:\\oracle\\scripts\\cleanup_database.cmd" 2>/dev/null
|
||||
"powershell -ExecutionPolicy Bypass -File D:\\oracle\\scripts\\cleanup_database.ps1 /SILENT" 2>/dev/null
|
||||
|
||||
cleanup_freed=8
|
||||
track_step "Cleanup" true "Database cleaned, ~${cleanup_freed}GB freed" "$step_start"
|
||||
|
||||
Reference in New Issue
Block a user