Improve LSN gap check

This commit is contained in:
2026-06-24 14:49:18 +01:00
parent ab12c29244
commit bbbc824916
+18 -1
View File
@@ -577,7 +577,24 @@ function Print-BackupSummary {
Write-Host " Point-in-Time Range: $(([datetime]$firstLog.BackupStartDate).ToString([System.Globalization.CultureInfo]::CurrentCulture)) to $(([datetime]$lastLog.BackupFinishDate).ToString([System.Globalization.CultureInfo]::CurrentCulture))"
Write-Host " LSN Range: $($firstLog.FirstLSN) - $($lastLog.LastLSN)"
# Check for gaps
# Check that the first LOG connects to the most recent FULL (or DIFF if one exists).
$baseLastLsn = $null
$baseLabel = $null
if ($Headers.ContainsKey('DIFF') -and $Headers['DIFF'].Count -gt 0) {
$latestDiff = @($Headers['DIFF'] | Sort-Object { $_.Key })[-1]
$dh = @($latestDiff.Header)[0]
if ($dh) { $baseLastLsn = $dh.LastLSN; $baseLabel = "DIFF $($latestDiff.Key)" }
}
if (-not $baseLastLsn -and $Headers.ContainsKey('FULL') -and $Headers['FULL'].Count -gt 0) {
$latestFull = @($Headers['FULL'] | Sort-Object { $_.Key })[-1]
$fh = @($latestFull.Header)[0]
if ($fh) { $baseLastLsn = $fh.LastLSN; $baseLabel = "FULL $($latestFull.Key)" }
}
if ($baseLastLsn -and [decimal]$firstLog.FirstLSN -gt [decimal]$baseLastLsn) {
Write-Host " *** LSN GAP: first LOG (LSN $($firstLog.FirstLSN)) does not connect to $baseLabel (ends LSN $baseLastLsn) — point-in-time restore will fail ***"
}
# Check for gaps within the LOG sequence
$gaps = @()
for ($i = 1; $i -lt $logItems.Count; $i++) {
$prevHeader = @($logItems[$i-1].Header)[0]