diff --git a/oracle/standby-server-scripts/rman_backup.txt b/oracle/standby-server-scripts/rman_backup.txt index 879e45c..8e9f6d4 100644 --- a/oracle/standby-server-scripts/rman_backup.txt +++ b/oracle/standby-server-scripts/rman_backup.txt @@ -4,15 +4,25 @@ RUN { CONFIGURE COMPRESSION ALGORITHM 'BASIC'; # Full backup COMPRESSED + Archive logs (șterge logs după backup) + # FORMAT: L0____ BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0 TAG 'DAILY_FULL_COMPRESSED' + FORMAT 'L0_%d_%T_%s_%p.BKP' DATABASE - PLUS ARCHIVELOG DELETE INPUT; + PLUS ARCHIVELOG DELETE INPUT + FORMAT 'ARC_%d_%T_%s_%p.BKP'; # Backup SPFILE și Control File - BACKUP AS COMPRESSED BACKUPSET SPFILE; - BACKUP CURRENT CONTROLFILE; + BACKUP AS COMPRESSED BACKUPSET + 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) DELETE NOPROMPT OBSOLETE; diff --git a/oracle/standby-server-scripts/rman_backup_incremental.txt b/oracle/standby-server-scripts/rman_backup_incremental.txt index 7109f95..cf4e017 100644 --- a/oracle/standby-server-scripts/rman_backup_incremental.txt +++ b/oracle/standby-server-scripts/rman_backup_incremental.txt @@ -1,15 +1,25 @@ RUN { # Incremental Level 1 CUMULATIVE backup # Backup doar modificările de la ultimul Level 0 (full backup de la 02:00 AM) + # FORMAT: L1____ BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 1 CUMULATIVE TAG 'MIDDAY_INCREMENTAL' + FORMAT 'L1_%d_%T_%s_%p.BKP' DATABASE - PLUS ARCHIVELOG DELETE INPUT; + PLUS ARCHIVELOG DELETE INPUT + FORMAT 'ARC_%d_%T_%s_%p.BKP'; # Backup SPFILE și controlfile (pentru siguranță) - BACKUP AS COMPRESSED BACKUPSET SPFILE; - BACKUP CURRENT CONTROLFILE; + BACKUP AS COMPRESSED BACKUPSET + 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 } diff --git a/oracle/standby-server-scripts/rman_restore_from_zero.ps1 b/oracle/standby-server-scripts/rman_restore_from_zero.ps1 index 1f7c899..d0a066e 100644 --- a/oracle/standby-server-scripts/rman_restore_from_zero.ps1 +++ b/oracle/standby-server-scripts/rman_restore_from_zero.ps1 @@ -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_*__* (all pieces of Level 0) + # - All L1_*__* or later (incrementals from same day or after) + # - All ARC_*__* 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)