Skip to content

Commit 91972b4

Browse files
Test-DbaLsnChain: Fix bug when reading history from file (#10201)
1 parent 861b0db commit 91972b4

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

private/functions/Test-DbaLsnChain.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ function Test-DbaLsnChain {
7474
$FullDBAnchor = ($FullDBAnchor | Select-Object -First 1)
7575

7676
#Via LSN chain:
77-
[BigInt]$CheckPointLSN = $FullDBAnchor.CheckPointLSN.ToString()
78-
[BigInt]$FullDBLastLSN = $FullDBAnchor.LastLSN.ToString()
79-
$BackupWrongLSN = $FilteredRestoreFiles | Where-Object { $_.DatabaseBackupLSN -ne $CheckPointLSN }
77+
[BigInt]$CheckPointLsn = $FullDBAnchor.CheckPointLsn.ToString()
78+
[BigInt]$FullDBLastLsn = $FullDBAnchor.LastLsn.ToString()
79+
$BackupWrongLSN = $FilteredRestoreFiles | Where-Object { [BigInt]$_.DatabaseBackupLsn.ToString() -ne $CheckPointLsn }
8080
#Should be 0 in there, if not, lets check that they're from during the full backup
8181
if ($BackupWrongLSN.count -gt 0 ) {
82-
if (($BackupWrongLSN | Where-Object { [BigInt]$_.LastLSN.ToString() -lt $FullDBLastLSN }).count -gt 0) {
82+
if (($BackupWrongLSN | Where-Object { [BigInt]$_.LastLSN.ToString() -lt $FullDBLastLsn }).count -gt 0) {
8383
Write-Message -Level Warning -Message "We have non matching LSNs - not supported"
8484
return $false
8585
break;
@@ -102,24 +102,24 @@ function Test-DbaLsnChain {
102102
#Check T-log LSNs form a chain.
103103
$TranLogBackups = $TestHistory | Where-Object {
104104
$isLogBackup = $_.$TypeName -in ('Transaction Log', 'Log')
105-
$isBasedOnAnchor = $_.DatabaseBackupLsn -eq $FullDBAnchor.CheckPointLsn
106-
$hasGreaterLastLsn = $_.LastLsn -gt $FullDBAnchor.CheckPointLsn
105+
$isBasedOnAnchor = [BigInt]$_.DatabaseBackupLsn.ToString() -eq $CheckPointLsn
106+
$hasGreaterLastLsn = [BigInt]$_.LastLsn.ToString() -gt $CheckPointLsn
107107

108108
Write-Message -Level Verbose -Message "Checking $($_.FullName) - isLogBackup $isLogBackup, isBasedOnAnchor $isBasedOnAnchor, hasGreaterLastLsn $hasGreaterLastLsn, FullDBAnchor.CheckPointLsn $($FullDBAnchor.CheckPointLsn), DatabaseBackupLsn $($_.DatabaseBackupLsn), FirstLsn $($_.FirstLsn) LastLsn $($_.LastLsn)"
109109
$isLogBackup -and ($isBasedOnAnchor -or $hasGreaterLastLsn)
110110
} | Sort-Object -Property LastLsn, FirstLsn
111111

112-
for ($i = 0; $i -lt ($TranLogBackups.count)) {
112+
for ($i = 0; $i -lt ($TranLogBackups.Count)) {
113113
Write-Message -Level Debug -Message "looping t logs"
114114
if ($i -eq 0) {
115-
if ($TranLogBackups[$i].FirstLSN.ToString() -gt $TlogAnchor.LastLSN) {
115+
if ([BigInt]$TranLogBackups[$i].FirstLsn.ToString() -gt [BigInt]$TlogAnchor.LastLsn.ToString()) {
116116
Write-Message -Level Warning -Message "Break in LSN Chain between $($TlogAnchor.FullName) and $($TranLogBackups[($i)].FullName) "
117-
Write-Message -Level Verbose -Message "Anchor $($TlogAnchor.LastLSN) - FirstLSN $($TranLogBackups[$i].FirstLSN)"
117+
Write-Message -Level Verbose -Message "Anchor $($TlogAnchor.LastLsn) - FirstLSN $($TranLogBackups[$i].FirstLsn)"
118118
return $false
119119
break
120120
}
121121
} else {
122-
if ($TranLogBackups[($i - 1)].LastLsn -ne $TranLogBackups[($i)].FirstLSN -and ($TranLogBackups[($i)] -ne $TranLogBackups[($i - 1)])) {
122+
if ([BigInt]$TranLogBackups[($i - 1)].LastLsn.ToString() -ne [BigInt]$TranLogBackups[($i)].FirstLsn.ToString() -and ($TranLogBackups[($i)] -ne $TranLogBackups[($i - 1)])) {
123123
Write-Message -Level Warning -Message "Break in transaction log between $($TranLogBackups[($i-1)].FullName) and $($TranLogBackups[($i)].FullName) "
124124
return $false
125125
break

tests/Test-DbaBackupInformation.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ Describe $CommandName -Tag IntegrationTests {
6868
}
6969
}
7070
Mock New-DbaDirectory { $True }
71-
$output = $BackupHistory | Test-DbaBackupInformation -SqlInstance NotExist -WarningVariable warnvar -WarningAction SilentlyContinue
72-
($output.Count) -gt 0 | Should -Be $true
73-
"False" -in ($Output.IsVerified) | Should -Be $False
74-
($null -ne $WarnVar) | Should -Be $True
71+
$output = $BackupHistory | Test-DbaBackupInformation -SqlInstance NotExist -WarningAction SilentlyContinue
72+
$WarnVar | Should -BeNullOrEmpty
73+
$output | Should -Not -BeNullOrEmpty
74+
$output.IsVerified | Should -Not -Contain $false
7575
}
7676
}
7777
Context "Not being able to see backups is bad" {

0 commit comments

Comments
 (0)