Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove or hide MB in Backup/Restore commands #4624

Merged
merged 6 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions functions/Invoke-DbaAdvancedRestore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function Invoke-DbaAdvancedRestore {

.NOTES
Tags: Restore, Backup
Author: Chrissy LeMaire (@cl), netnerds.net
Author: Stuart Moore (@napalmgram - http://stuart-moore.com)

Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
Expand All @@ -101,7 +101,7 @@ function Invoke-DbaAdvancedRestore {
First generates just the T-SQL restore scripts so they can be sanity checked, and then if they are good perform the full restore.
By reusing the BackupHistory object there is no need to rescan all the backup files again

#>
#>
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "Low")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "AzureCredential", Justification = "For Parameter AzureCredential")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseOutputTypeCorrectly", "", Justification = "PSSA Rule Ignored by BOH")]
Expand Down Expand Up @@ -325,14 +325,14 @@ function Invoke-DbaAdvancedRestore {
RestoredFile = $((Split-Path $backup.FileList.PhysicalName -Leaf) | Sort-Object -Unique) -Join ','
RestoredFileFull = ($backup.Filelist.PhysicalName -Join ',')
RestoreDirectory = $RestoreDirectory
BackupSize = if ([bool]($backup.psobject.Properties.Name -contains 'TotalSize')) { ($backup | Measure-Object -Property TotalSize -Sum).Sum } else { $null }
CompressedBackupSize = if ([bool]($backup.psobject.Properties.Name -contains 'CompressedBackupSize')) { ($backup | Measure-Object -Property CompressedBackupSize -Sum).Sum } else { $null }
BackupSize = if ([bool]($backup.psobject.Properties.Name -contains 'TotalSize')) { [dbasize](($backup | Measure-Object -Property TotalSize -Sum).Sum) } else { $null }
CompressedBackupSize = if ([bool]($backup.psobject.Properties.Name -contains 'CompressedBackupSize')) { [dbasize](($backup | Measure-Object -Property CompressedBackupSize -Sum).Sum) } else { $null }
Script = $script
BackupFileRaw = ($backups.Fullname)
FileRestoreTime = New-TimeSpan -Seconds ((Get-Date) - $FileRestoreStartTime).TotalSeconds
DatabaseRestoreTime = New-TimeSpan -Seconds ((Get-Date) - $DatabaseRestoreStartTime).TotalSeconds
ExitError = $ExitError
} | Select-DefaultView -ExcludeProperty BackupSize, CompressedBackupSize, ExitError, BackupFileRaw, RestoredFileFull
} | Select-DefaultView -ExcludeProperty BackupSizeMB, CompressedBackupSizeMB, ExitError, BackupFileRaw, RestoredFileFull
} else {
$script
}
Expand Down
38 changes: 15 additions & 23 deletions functions/Read-DbaBackupHeader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ function Read-DbaBackupHeader {
Also returns detailed information about each of the datafiles contained in the backupset.

.EXAMPLE
PS C:\> "C:\temp\myfile.bak", "\backupserver\backups\myotherfile.bak" | Read-DbaBackupHeader -SqlInstance sql2016
PS C:\> "C:\temp\myfile.bak", "\backupserver\backups\myotherfile.bak" | Read-DbaBackupHeader -SqlInstance sql2016 | Where-Object { $_.BackupSize.Megabyte -gt 100 }

Similar to running Read-DbaBackupHeader -SqlInstance sql2016 -Path "C:\temp\myfile.bak", "\backupserver\backups\myotherfile.bak"
Reads the two files and returns only backups larger than 100 MB

.EXAMPLE
PS C:\> Get-ChildItem \\nas\sql\*.bak | Read-DbaBackupHeader -SqlInstance sql2016
Expand All @@ -83,7 +83,7 @@ function Read-DbaBackupHeader {

Gets the backup header information from the SQL Server backup file stored at https://dbatoolsaz.blob.core.windows.net/azbackups/restoretime/restoretime_201705131850.bak on Azure

#>
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", 'AzureCredential', Justification = "For Parameter AzureCredential")]
[CmdletBinding()]
param (
Expand Down Expand Up @@ -132,31 +132,23 @@ function Read-DbaBackupHeader {
$device = New-Object Microsoft.SqlServer.Management.Smo.BackupDeviceItem $Path, $DeviceType
$restore.Devices.Add($device)
$dataTable = $restore.ReadBackupHeader($server)

$null = $dataTable.Columns.Add("FileList", [object])

$mb = $dataTable.Columns.Add("BackupSizeMB", [int])
$mb.Expression = "BackupSize / 1024 / 1024"
$gb = $dataTable.Columns.Add("BackupSizeGB")
$gb.Expression = "BackupSizeMB / 1024"

if ($null -eq $dataTable.Columns['CompressedBackupSize']) {
$formula = "0"
} else {
$formula = "CompressedBackupSize / 1024 / 1024"
}

$cmb = $dataTable.Columns.Add("CompressedBackupSizeMB", [int])
$cmb.Expression = $formula
$cgb = $dataTable.Columns.Add("CompressedBackupSizeGB")
$cgb.Expression = "CompressedBackupSizeMB / 1024"

$null = $dataTable.Columns.Add("SqlVersion")

$null = $dataTable.Columns.Add("BackupPath")

foreach ($row in $dataTable) {
$row.BackupPath = $Path

$backupsize = $row.BackupSize
$null = $dataTable.Columns.Remove("BackupSize")
$null = $dataTable.Columns.Add("BackupSize", [dbasize])
$row.BackupSize = [dbasize]$backupsize

$cbackupsize = $row.CompressedBackupSize
$null = $dataTable.Columns.Remove("CompressedBackupSize")
$null = $dataTable.Columns.Add("CompressedBackupSize", [dbasize])
$row.CompressedBackupSize = [dbasize]$cbackupsize

$restore.FileNumber = $row.Position
<# Select-Object does a quick and dirty conversion from datatable to PS object #>
$row.FileList = $restore.ReadFileList($server) | Select-Object *
Expand Down Expand Up @@ -262,7 +254,7 @@ function Read-DbaBackupHeader {
}
}
if ($Simple) {
$dataTable | Select-Object DatabaseName, BackupFinishDate, RecoveryModel, BackupSizeMB, CompressedBackupSizeMB, DatabaseCreationDate, UserName, ServerName, SqlVersion, BackupPath
$dataTable | Select-Object DatabaseName, BackupFinishDate, RecoveryModel, BackupSize, CompressedBackupSize, DatabaseCreationDate, UserName, ServerName, SqlVersion, BackupPath
} elseif ($FileList) {
$dataTable.filelist
} else {
Expand Down