Oracle DR: Add naming convention to RMAN backups for smart restore selection
- Add FORMAT to rman_backup.txt: L0_*, ARC_*, SPFILE_*, CF_* - Add FORMAT to rman_backup_incremental.txt: L1_*, ARC_*, SPFILE_*, CF_* - Update rman_restore_from_zero.ps1 TestMode to select files by naming convention - Select only latest L0 backup set + all L1 incrementals/archives (faster DR tests) - Backward compatible with old autobackup naming (fallback to copy all) - Fixes missing datafiles issue (previously only copied 8 files, now copies full backup set) Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@@ -250,29 +250,60 @@ if ($TestMode) {
|
||||
# Select backup files based on mode (TestMode vs Standalone)
|
||||
try {
|
||||
if ($TestMode) {
|
||||
# TEST MODE: Copy only latest full backup + everything after it (optimal for weekly testing)
|
||||
Write-Host "[INFO] TEST MODE: Selecting latest full backup + incrementals for faster restore..." -ForegroundColor Cyan
|
||||
# TEST MODE: Copy latest L0 backup set + all incrementals/archives
|
||||
Write-Host "[INFO] TEST MODE: Selecting latest backup set using naming convention..." -ForegroundColor Cyan
|
||||
|
||||
# Find latest full backup (Level 0 - DAILY_FULL_COMPRESSED)
|
||||
$fullBackups = Get-ChildItem "F:\ROA\autobackup\*DAILY_FULL*.BKP" -ErrorAction Continue |
|
||||
# Check if new naming convention is in use (L0_*, L1_*, etc.)
|
||||
$l0Backups = Get-ChildItem "F:\ROA\autobackup\L0_*.BKP" -ErrorAction Continue |
|
||||
Sort-Object LastWriteTime -Descending
|
||||
|
||||
if ($fullBackups.Count -eq 0) {
|
||||
Write-Host "ERROR: No full backup found on F: drive!" -ForegroundColor Red
|
||||
Write-Host " Cannot proceed with restore - need at least one full backup"
|
||||
exit 1
|
||||
if ($l0Backups.Count -gt 0) {
|
||||
# New naming convention detected - use smart selection
|
||||
Write-Host "[INFO] Using naming convention for optimized backup selection" -ForegroundColor Cyan
|
||||
|
||||
$latestL0 = $l0Backups[0]
|
||||
# Extract date from filename: L0_ROA_20251011_123_1.BKP -> 20251011
|
||||
if ($latestL0.Name -match 'L0_\w+_(\d{8})_') {
|
||||
$backupDate = $Matches[1]
|
||||
Write-Host "[INFO] Latest Level 0 backup date: $backupDate" -ForegroundColor Cyan
|
||||
Write-Host " Base file: $($latestL0.Name)" -ForegroundColor Cyan
|
||||
|
||||
# Select all files from this backup set:
|
||||
# - All L0_*_<date>_* (all pieces of Level 0)
|
||||
# - All L1_*_<date>_* or later (incrementals from same day or after)
|
||||
# - All ARC_*_<date>_* or later (archive logs)
|
||||
# - All SPFILE_* and CF_* (needed for restore)
|
||||
|
||||
$backupFiles = Get-ChildItem "F:\ROA\autobackup\*.BKP" -ErrorAction Continue |
|
||||
Where-Object {
|
||||
$_.Name -match "^L0_\w+_${backupDate}_" -or # Level 0 pieces
|
||||
$_.Name -match "^L1_\w+_\d{8}_" -or # All Level 1 incrementals
|
||||
$_.Name -match "^ARC_\w+_\d{8}_" -or # All archive logs
|
||||
$_.Name -match "^SPFILE_\w+_${backupDate}_" -or # SPFILE from same day
|
||||
$_.Name -match "^CF_\w+_${backupDate}_" -or # Controlfile from same day
|
||||
$_.Name -match "^O1_MF_S_" # Autobackup control files (always needed)
|
||||
}
|
||||
|
||||
Write-Host "[INFO] Selected $($backupFiles.Count) files for restore:" -ForegroundColor Cyan
|
||||
Write-Host " - Level 0 pieces for date $backupDate" -ForegroundColor Cyan
|
||||
Write-Host " - All Level 1 incrementals" -ForegroundColor Cyan
|
||||
Write-Host " - All archive logs" -ForegroundColor Cyan
|
||||
Write-Host " - SPFILE and Control file backups" -ForegroundColor Cyan
|
||||
|
||||
} else {
|
||||
Write-Host "WARNING: Cannot parse date from L0 filename, using ALL L0/L1/ARC files" -ForegroundColor Yellow
|
||||
$backupFiles = Get-ChildItem "F:\ROA\autobackup\*.BKP" -ErrorAction Continue |
|
||||
Where-Object { $_.Name -match "^(L0_|L1_|ARC_|SPFILE_|CF_)" }
|
||||
}
|
||||
|
||||
} else {
|
||||
# Old naming convention (autobackup format) - fallback to copying all
|
||||
Write-Host "[INFO] Old naming convention detected - copying ALL backups for safety" -ForegroundColor Yellow
|
||||
Write-Host " (New naming convention will be used after next backup runs)" -ForegroundColor Yellow
|
||||
$backupFiles = Get-ChildItem "F:\ROA\autobackup\*.BKP" -ErrorAction Continue
|
||||
}
|
||||
|
||||
$latestFull = $fullBackups[0]
|
||||
$cutoffTime = $latestFull.LastWriteTime
|
||||
|
||||
# Get all backups >= latest full backup timestamp (includes incrementals, controlfiles, SPFILE backups)
|
||||
$backupFiles = Get-ChildItem "F:\ROA\autobackup\*.BKP" -ErrorAction Continue |
|
||||
Where-Object { $_.LastWriteTime -ge $cutoffTime }
|
||||
|
||||
Write-Host "[INFO] Latest full backup: $($latestFull.Name)" -ForegroundColor Cyan
|
||||
Write-Host " Timestamp: $($latestFull.LastWriteTime)" -ForegroundColor Cyan
|
||||
Write-Host " Selected $($backupFiles.Count) files from latest backup set (saves ~60-70% copy time)" -ForegroundColor Cyan
|
||||
Write-Host "[INFO] Total files selected: $($backupFiles.Count)" -ForegroundColor Cyan
|
||||
|
||||
} else {
|
||||
# STANDALONE MODE: Copy ALL backups (disaster recovery - maximum safety with fallback)
|
||||
|
||||
Reference in New Issue
Block a user