Skip to content

Commit 828ebc3

Browse files
Get-DbaBackupInformation - Fix inconsistencies with Get-DbaDbBackupHistory (#10308)
1 parent 21e4795 commit 828ebc3

3 files changed

Lines changed: 35 additions & 14 deletions

File tree

.github/scripts/gh-s3actions.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Describe "S3 Backup Integration Tests" -Tag "IntegrationTests", "S3" {
215215

216216
$result | Should -Not -BeNullOrEmpty
217217
$result.Database | Should -Be $script:TestDbName2
218-
$result.Type | Should -Be "Database"
218+
$result.Type | Should -Be "Full"
219219
}
220220
}
221221

@@ -393,7 +393,7 @@ Describe "S3 Backup Integration Tests" -Tag "IntegrationTests", "S3" {
393393
# Should successfully read the specific file
394394
$result | Should -Not -BeNullOrEmpty
395395
$result.Database | Should -Be $script:TestDbName5
396-
$result.Type | Should -Be "Database"
396+
$result.Type | Should -Be "Full"
397397
}
398398

399399
It "Should successfully enumerate local file system paths (contrast with S3)" {

public/Get-DbaBackupInformation.ps1

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,16 @@ function Get-DbaBackupInformation {
360360
if (-not $dbLsn) {
361361
$dbLsn = 0
362362
}
363-
$description = $group.Group[0].BackupTypeDescription
363+
$description = switch ($group.Group[0].BackupTypeDescription) {
364+
"Database" { "Full" }
365+
"Database Differential" { "Differential" }
366+
"Transaction Log" { "Log" }
367+
"File or Filegroup" { "File" }
368+
"File Differential" { "Differential File" }
369+
"Partial Database" { "Partial Full" }
370+
"Partial Differential" { "Partial Differential" }
371+
default { $group.Group[0].BackupTypeDescription }
372+
}
364373
if (-not $description) {
365374
try {
366375
$header = Read-DbaBackupHeader -SqlInstance $server -Path $Path -EnableException | Select-Object -First 1
@@ -375,15 +384,24 @@ function Get-DbaBackupInformation {
375384
}
376385
$historyObject = New-Object Dataplat.Dbatools.Database.BackupHistory
377386
$historyObject.ComputerName = $group.Group[0].MachineName
378-
$historyObject.InstanceName = $group.Group[0].ServiceName
387+
$instanceName = $group.Group[0].ServiceName
388+
if (-not $instanceName -and $group.Group[0].ServerName -like "*\*") {
389+
$instanceName = $group.Group[0].ServerName.Split("\")[1]
390+
} elseif (-not $instanceName) {
391+
$instanceName = "MSSQLSERVER"
392+
}
393+
$historyObject.InstanceName = $instanceName
379394
$historyObject.SqlInstance = $group.Group[0].ServerName
380395
$historyObject.Database = $group.Group[0].DatabaseName
381396
$historyObject.UserName = $group.Group[0].UserName
382397
$historyObject.Start = [DateTime]$group.Group[0].BackupStartDate
383398
$historyObject.End = [DateTime]$group.Group[0].BackupFinishDate
384399
$historyObject.Duration = ([DateTime]$group.Group[0].BackupFinishDate - [DateTime]$group.Group[0].BackupStartDate)
385400
$historyObject.Path = [string[]]$group.Group.BackupPath
386-
$historyObject.FileList = ($group.Group.FileList | Select-Object Type, LogicalName, PhysicalName, @{
401+
$historyObject.FileList = ($group.Group.FileList | Select-Object @{
402+
Name = "FileType"
403+
Expression = { $PSItem.Type }
404+
}, LogicalName, PhysicalName, @{
387405
Name = "Size"
388406
Expression = { [dbasize]$PSItem.Size }
389407
} -Unique)
@@ -401,6 +419,9 @@ function Get-DbaBackupInformation {
401419
$historyObject.SoftwareVersionMajor = $group.Group[0].SoftwareVersionMajor
402420
$historyObject.RecoveryModel = $group.Group.RecoveryModel
403421
$historyObject.IsCopyOnly = $group.Group[0].IsCopyOnly
422+
if ($null -ne $group.Group[0].LastRecoveryForkGUID) {
423+
$historyObject.LastRecoveryForkGuid = $group.Group[0].LastRecoveryForkGUID
424+
}
404425
$groupResults += $historyObject
405426
}
406427
}
@@ -420,7 +441,7 @@ function Get-DbaBackupInformation {
420441
$group.UserName = Get-HashString -InString $group.UserName
421442
$group.Path = Get-HashString -InString $group.Path
422443
$group.FullName = Get-HashString -InString $group.FullName
423-
$group.FileList = ($group.FileList | Select-Object Type,
444+
$group.FileList = ($group.FileList | Select-Object FileType,
424445
@{Name = "LogicalName"; Expression = { Get-HashString -InString $_."LogicalName" } },
425446
@{Name = "PhysicalName"; Expression = { Get-HashString -InString $_."PhysicalName" } })
426447
}

tests/Get-DbaBackupInformation.Tests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ Describe $CommandName -Tag IntegrationTests {
129129
}
130130

131131
It "Should return 2 full backups" {
132-
($results | Where-Object Type -eq "Database").Count | Should -BeExactly 2
132+
($results | Where-Object Type -eq "Full").Count | Should -BeExactly 2
133133
}
134134

135135
It "Should return 2 log backups" {
136-
($results | Where-Object Type -eq "Transaction Log").Count | Should -BeExactly 2
136+
($results | Where-Object Type -eq "Log").Count | Should -BeExactly 2
137137
}
138138
}
139139

@@ -152,11 +152,11 @@ Describe $CommandName -Tag IntegrationTests {
152152
}
153153

154154
It "Should Be 1 full backup" {
155-
($results | Where-Object Type -eq "Database").Count | Should -BeExactly 1
155+
($results | Where-Object Type -eq "Full").Count | Should -BeExactly 1
156156
}
157157

158158
It "Should be 1 log backups" {
159-
($results | Where-Object Type -eq "Transaction Log").Count | Should -BeExactly 1
159+
($results | Where-Object Type -eq "Log").Count | Should -BeExactly 1
160160
}
161161

162162
It "Should only be backups of $dbname2" {
@@ -199,11 +199,11 @@ Describe $CommandName -Tag IntegrationTests {
199199
}
200200

201201
It "Should Be 1 full backup" {
202-
($results | Where-Object Type -eq "Database").Count | Should -BeExactly 1
202+
($results | Where-Object Type -eq "Full").Count | Should -BeExactly 1
203203
}
204204

205205
It "Should be 1 log backups" {
206-
($results | Where-Object Type -eq "Transaction Log").Count | Should -BeExactly 1
206+
($results | Where-Object Type -eq "Log").Count | Should -BeExactly 1
207207
}
208208

209209
It "Should only be backups of $dbname3" {
@@ -229,7 +229,7 @@ Describe $CommandName -Tag IntegrationTests {
229229
IgnoreLogBackup = $true
230230
}
231231
$ResultsSanLog = Get-DbaBackupInformation @splatMaintenanceNoLog
232-
($ResultsSanLog | Where-Object Type -eq "Database").Count | Should -BeExactly 1
232+
($ResultsSanLog | Where-Object Type -eq "Full").Count | Should -BeExactly 1
233233
}
234234

235235
It "Should be 0 log backups when ignoring log backups" {
@@ -240,7 +240,7 @@ Describe $CommandName -Tag IntegrationTests {
240240
IgnoreLogBackup = $true
241241
}
242242
$resultsSanLog = Get-DbaBackupInformation @splatMaintenanceNoLog
243-
($resultsSanLog | Where-Object Type -eq "Transaction Log").Count | Should -BeExactly 0
243+
($resultsSanLog | Where-Object Type -eq "Log").Count | Should -BeExactly 0
244244
}
245245

246246
It "Should Warn if IgnoreLogBackup without MaintenanceSolution" {

0 commit comments

Comments
 (0)