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:
Marius
2025-10-11 16:12:41 +03:00
parent f1002d6e4a
commit 62848e635d
3 changed files with 75 additions and 24 deletions

View File

@@ -4,15 +4,25 @@ RUN {
CONFIGURE COMPRESSION ALGORITHM 'BASIC'; CONFIGURE COMPRESSION ALGORITHM 'BASIC';
# Full backup COMPRESSED + Archive logs (șterge logs după backup) # Full backup COMPRESSED + Archive logs (șterge logs după backup)
# FORMAT: L0_<dbname>_<YYYYMMDD>_<set#>_<piece#>
BACKUP AS COMPRESSED BACKUPSET BACKUP AS COMPRESSED BACKUPSET
INCREMENTAL LEVEL 0 INCREMENTAL LEVEL 0
TAG 'DAILY_FULL_COMPRESSED' TAG 'DAILY_FULL_COMPRESSED'
FORMAT 'L0_%d_%T_%s_%p.BKP'
DATABASE DATABASE
PLUS ARCHIVELOG DELETE INPUT; PLUS ARCHIVELOG DELETE INPUT
FORMAT 'ARC_%d_%T_%s_%p.BKP';
# Backup SPFILE și Control File # Backup SPFILE și Control File
BACKUP AS COMPRESSED BACKUPSET SPFILE; BACKUP AS COMPRESSED BACKUPSET
BACKUP CURRENT CONTROLFILE; TAG 'SPFILE_BACKUP'
FORMAT 'SPFILE_%d_%T_%s_%p.BKP'
SPFILE;
BACKUP
TAG 'CONTROLFILE_BACKUP'
FORMAT 'CF_%d_%T_%s_%p.BKP'
CURRENT CONTROLFILE;
# Cleanup old backups (păstrează ultimele 2 - REDUNDANCY 2) # Cleanup old backups (păstrează ultimele 2 - REDUNDANCY 2)
DELETE NOPROMPT OBSOLETE; DELETE NOPROMPT OBSOLETE;

View File

@@ -1,15 +1,25 @@
RUN { RUN {
# Incremental Level 1 CUMULATIVE backup # Incremental Level 1 CUMULATIVE backup
# Backup doar modificările de la ultimul Level 0 (full backup de la 02:00 AM) # Backup doar modificările de la ultimul Level 0 (full backup de la 02:00 AM)
# FORMAT: L1_<dbname>_<YYYYMMDD>_<set#>_<piece#>
BACKUP AS COMPRESSED BACKUPSET BACKUP AS COMPRESSED BACKUPSET
INCREMENTAL LEVEL 1 CUMULATIVE INCREMENTAL LEVEL 1 CUMULATIVE
TAG 'MIDDAY_INCREMENTAL' TAG 'MIDDAY_INCREMENTAL'
FORMAT 'L1_%d_%T_%s_%p.BKP'
DATABASE DATABASE
PLUS ARCHIVELOG DELETE INPUT; PLUS ARCHIVELOG DELETE INPUT
FORMAT 'ARC_%d_%T_%s_%p.BKP';
# Backup SPFILE și controlfile (pentru siguranță) # Backup SPFILE și controlfile (pentru siguranță)
BACKUP AS COMPRESSED BACKUPSET SPFILE; BACKUP AS COMPRESSED BACKUPSET
BACKUP CURRENT CONTROLFILE; TAG 'SPFILE_BACKUP'
FORMAT 'SPFILE_%d_%T_%s_%p.BKP'
SPFILE;
BACKUP
TAG 'CONTROLFILE_BACKUP'
FORMAT 'CF_%d_%T_%s_%p.BKP'
CURRENT CONTROLFILE;
# NU ștergem obsolete aici - se face la full backup # NU ștergem obsolete aici - se face la full backup
} }

View File

@@ -250,29 +250,60 @@ if ($TestMode) {
# Select backup files based on mode (TestMode vs Standalone) # Select backup files based on mode (TestMode vs Standalone)
try { try {
if ($TestMode) { if ($TestMode) {
# TEST MODE: Copy only latest full backup + everything after it (optimal for weekly testing) # TEST MODE: Copy latest L0 backup set + all incrementals/archives
Write-Host "[INFO] TEST MODE: Selecting latest full backup + incrementals for faster restore..." -ForegroundColor Cyan Write-Host "[INFO] TEST MODE: Selecting latest backup set using naming convention..." -ForegroundColor Cyan
# Find latest full backup (Level 0 - DAILY_FULL_COMPRESSED) # Check if new naming convention is in use (L0_*, L1_*, etc.)
$fullBackups = Get-ChildItem "F:\ROA\autobackup\*DAILY_FULL*.BKP" -ErrorAction Continue | $l0Backups = Get-ChildItem "F:\ROA\autobackup\L0_*.BKP" -ErrorAction Continue |
Sort-Object LastWriteTime -Descending Sort-Object LastWriteTime -Descending
if ($fullBackups.Count -eq 0) { if ($l0Backups.Count -gt 0) {
Write-Host "ERROR: No full backup found on F: drive!" -ForegroundColor Red # New naming convention detected - use smart selection
Write-Host " Cannot proceed with restore - need at least one full backup" Write-Host "[INFO] Using naming convention for optimized backup selection" -ForegroundColor Cyan
exit 1
$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] Write-Host "[INFO] Total files selected: $($backupFiles.Count)" -ForegroundColor Cyan
$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
} else { } else {
# STANDALONE MODE: Copy ALL backups (disaster recovery - maximum safety with fallback) # STANDALONE MODE: Copy ALL backups (disaster recovery - maximum safety with fallback)