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

Address output issues on a few commands #6025

Merged
merged 3 commits into from
Sep 8, 2019
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
70 changes: 19 additions & 51 deletions functions/Restore-DbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function Restore-DbaDatabase {

if ($RestoreInstance.DatabaseEngineEdition -eq "SqlManagedInstance") {
Write-Message -Level Verbose -Message "Restore target is a Managed Instance, restricted feature set available"
$MiParams = ("DestinationDataDirectory", "DestinationLogDirectory", "DestinationFileStreamDirectoru", "XpDirTree", "FileMapping", "UseDestintionDefaultDirectories", "ReuseSourceFolderStructure", "DestinationFilePrefix", "StandbyDirecttory", "ReplaceDbNameInFile", "KeepCDC")
$MiParams = ("DestinationDataDirectory", "DestinationLogDirectory", "DestinationFileStreamDirectory", "XpDirTree", "FileMapping", "UseDestinationDefaultDirectories", "ReuseSourceFolderStructure", "DestinationFilePrefix", "StandbyDirecttory", "ReplaceDbNameInFile", "KeepCDC")
ForEach ($MiParam in $MiParams) {
if (Test-Bound $MiParam) {
# Write-Message -Level Warning "Restoring to a Managed SQL Instance, parameter $MiParm is not supported"
Expand Down Expand Up @@ -499,7 +499,7 @@ function Restore-DbaDatabase {
$bound = $PSBoundParameters
$bound['TrustDbBackupHistory'] = $true
$bound['Path'] = $bh
Restore-Dbadatabase @bound
Restore-DbaDatabase @bound
}
break
}
Expand All @@ -511,34 +511,18 @@ function Restore-DbaDatabase {
if ($TrustDbBackupHistory -or $path[0].GetType().ToString() -eq 'Sqlcollaborative.Dbatools.Database.BackupHistory') {
foreach ($f in $path) {
Write-Message -Level Verbose -Message "Trust Database Backup History Set"
if ("BackupPath" -notin $f.PSobject.Properties.name) {
if ("BackupPath" -notin $f.PSObject.Properties.name) {
Write-Message -Level Verbose -Message "adding BackupPath - $($_.FullName)"
$f = $f | Select-Object *, @{
Name = "BackupPath"; Expression = {
$_.FullName
}
}
$f = $f | Select-Object *, @{ Name = "BackupPath"; Expression = { $_.FullName } }
}
if ("DatabaseName" -notin $f.PSobject.Properties.Name) {
$f = $f | Select-Object *, @{
Name = "DatabaseName"; Expression = {
$_.Database
}
}
if ("DatabaseName" -notin $f.PSObject.Properties.Name) {
$f = $f | Select-Object *, @{ Name = "DatabaseName"; Expression = { $_.Database } }
}
if ("Database" -notin $f.PSobject.Properties.Name) {
$f = $f | Select-Object *, @{
Name = "Database"; Expression = {
$_.DatabaseName
}
}
if ("Database" -notin $f.PSObject.Properties.Name) {
$f = $f | Select-Object *, @{ Name = "Database"; Expression = { $_.DatabaseName } }
}
if ("BackupSetGUID" -notin $f.PSobject.Properties.Name) {
$f = $f | Select-Object *, @{
Name = "BackupSetGUID"; Expression = {
$_.BackupSetID
}
}
if ("BackupSetGUID" -notin $f.PSObject.Properties.Name) {
$f = $f | Select-Object *, @{ Name = "BackupSetGUID"; Expression = { $_.BackupSetID } }
}
if ($f.BackupPath -like 'http*') {
if ('' -ne $AzureCredential) {
Expand All @@ -558,15 +542,7 @@ function Restore-DbaDatabase {
}
}
}
$BackupHistory += $F | Select-Object *, @{
Name = "ServerName"; Expression = {
$_.SqlInstance
}
}, @{
Name = "BackupStartDate"; Expression = {
$_.Start -as [DateTime]
}
}
$BackupHistory += $F | Select-Object *, @{ Name = "ServerName"; Expression = { $_.SqlInstance } }, @{ Name = "BackupStartDate"; Expression = { $_.Start -as [DateTime] } }
}
} else {
$files = @()
Expand Down Expand Up @@ -595,11 +571,11 @@ function Restore-DbaDatabase {
foreach ($Database in $DatabaseName) {
if ($Database -is [object]) {
#We've got an object, try the normal options Database, DatabaseName, Name
if ("Database" -in $Database.PSobject.Properties.Name) {
if ("Database" -in $Database.PSObject.Properties.Name) {
[string]$DataBase = $Database.Database
} elseif ("DatabaseName" -in $Database.PSobject.Properties.Name) {
} elseif ("DatabaseName" -in $Database.PSObject.Properties.Name) {
[string]$DataBase = $Database.DatabaseName
} elseif ("Name" -in $Database.PSobject.Properties.Name) {
} elseif ("Name" -in $Database.PSObject.Properties.Name) {
[string]$Database = $Database.name
}
}
Expand Down Expand Up @@ -688,16 +664,10 @@ function Restore-DbaDatabase {
if ($StopAfterTestBackupInformation) {
return
}
$DbVerfied = ($FilteredBackupHistory | Where-Object {
$_.IsVerified -eq $True
} | Sort-Object -Property Database -Unique).Database -join ','
$DbVerfied = ($FilteredBackupHistory | Where-Object { $_.IsVerified -eq $True } | Sort-Object -Property Database -Unique).Database -join ','
Write-Message -Message "$DbVerfied passed testing" -Level Verbose
if ((@($FilteredBackupHistory | Where-Object {
$_.IsVerified -eq $True
})).count -lt $FilteredBackupHistory.count) {
$DbUnVerified = ($FilteredBackupHistory | Where-Object {
$_.IsVerified -eq $False
} | Sort-Object -Property Database -Unique).Database -join ','
if ((@($FilteredBackupHistory | Where-Object { $_.IsVerified -eq $True })).count -lt $FilteredBackupHistory.count) {
$DbUnVerified = ($FilteredBackupHistory | Where-Object { $_.IsVerified -eq $False } | Sort-Object -Property Database -Unique).Database -join ','
Write-Message -Level Warning -Message "Database $DbUnverified failed testing, skipping"
}
If ($PSCmdlet.ParameterSetName -eq "RestorePage") {
Expand All @@ -715,9 +685,7 @@ function Restore-DbaDatabase {
$TailBackup = Backup-DbaDatabase -SqlInstance $RestoreInstance -Database $DatabaseName -Type Log -BackupDirectory $PageRestoreTailFolder -Norecovery -CopyOnly
}
try {
$FilteredBackupHistory | Where-Object {
$_.IsVerified -eq $true
} | Invoke-DbaAdvancedRestore -SqlInstance $RestoreInstance -WithReplace:$WithReplace -RestoreTime $RestoreTime -StandbyDirectory $StandbyDirectory -NoRecovery:$NoRecovery -Continue:$Continue -OutputScriptOnly:$OutputScriptOnly -BlockSize $BlockSize -MaxTransferSize $MaxTransferSize -Buffercount $Buffercount -KeepCDC:$KeepCDC -VerifyOnly:$VerifyOnly -PageRestore $PageRestore -EnableException -AzureCredential $AzureCredential
$FilteredBackupHistory | Where-Object { $_.IsVerified -eq $true } | Invoke-DbaAdvancedRestore -SqlInstance $RestoreInstance -WithReplace:$WithReplace -RestoreTime $RestoreTime -StandbyDirectory $StandbyDirectory -NoRecovery:$NoRecovery -Continue:$Continue -OutputScriptOnly:$OutputScriptOnly -BlockSize $BlockSize -MaxTransferSize $MaxTransferSize -BufferCount $Buffercount -KeepCDC:$KeepCDC -VerifyOnly:$VerifyOnly -PageRestore $PageRestore -EnableException -AzureCredential $AzureCredential
} catch {
Stop-Function -Message "Failure" -ErrorRecord $_ -Continue -Target $RestoreInstance
}
Expand All @@ -727,7 +695,7 @@ function Restore-DbaDatabase {
$TailBackup = Backup-DbaDatabase -SqlInstance $RestoreInstance -Database $DatabaseName -Type Log -BackupDirectory $PageRestoreTailFolder -Norecovery -CopyOnly
}
Write-Message -Message "Restoring Tail log backup for page restore" -Level Verbose
$TailBackup | Restore-DbaDatabase -SqlInstance $RestoreInstance -TrustDbBackupHistory -NoRecovery -OutputScriptOnly:$OutputScriptOnly -BlockSize $BlockSize -MaxTransferSize $MaxTransferSize -Buffercount $Buffercount -Continue
$TailBackup | Restore-DbaDatabase -SqlInstance $RestoreInstance -TrustDbBackupHistory -NoRecovery -OutputScriptOnly:$OutputScriptOnly -BlockSize $BlockSize -MaxTransferSize $MaxTransferSize -BufferCount $Buffercount -Continue
Restore-DbaDatabase -SqlInstance $RestoreInstance -Recover -DatabaseName $DatabaseName -OutputScriptOnly:$OutputScriptOnly
}
}
Expand Down
6 changes: 3 additions & 3 deletions functions/Sync-DbaAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function Sync-DbaAvailabilityGroup {
try {
$server = Connect-SqlInstance -SqlInstance $Primary -SqlCredential $PrimarySqlCredential
} catch {
Stop-Function -Message "Error occurred while establishing connection to $instance" -Category ConnectionError -ErrorRecord $_ -Target $Primary
Stop-Function -Message "Error occurred while establishing connection to $Primary" -Category ConnectionError -ErrorRecord $_ -Target $Primary
return
}
}
Expand All @@ -186,7 +186,7 @@ function Sync-DbaAvailabilityGroup {
try {
$secondaries += Connect-SqlInstance -SqlInstance $computer -SqlCredential $SecondarySqlCredential
} catch {
Stop-Function -Message "Error occurred while establishing connection to $instance" -Category ConnectionError -ErrorRecord $_ -Target $Primary
Stop-Function -Message "Error occurred while establishing connection to $computer" -Category ConnectionError -ErrorRecord $_ -Target $Primary
return
}
}
Expand All @@ -197,7 +197,7 @@ function Sync-DbaAvailabilityGroup {
SecondaryServer = $secondaries
}

# In the event that someone pipes in an availability group, this will keep the syncer from running a bunch of times
# In the event that someone pipes in an availability group, this will keep the sync from running a bunch of times
$dupe = $false

foreach ($ag in $allcombos) {
Expand Down
12 changes: 4 additions & 8 deletions functions/Test-DbaLastBackup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,7 @@ function Test-DbaLastBackup {
}
$fileexists = $false
$success = $restoreresult = $dbccresult = "Skipped"
} elseif (-not ($lastbackup | Where-Object {
$_.type -eq 'Full'
})) {
} elseif (-not ($lastbackup | Where-Object { $_.type -eq 'Full' })) {
Write-Message -Level Verbose -Message "No full backup returned from lastbackup."
$lastbackup = @{
Path = "Not found"
Expand All @@ -359,9 +357,7 @@ function Test-DbaLastBackup {
Write-Message -Level Verbose -Message "Path not UNC and source does not match destination. Use -CopyFile to move the backup file."
$fileexists = $dbccresult = "Skipped"
$success = $restoreresult = "Restore not located on shared location"
} elseif (($lastbackup[0].Path | ForEach-Object {
Test-DbaPath -SqlInstance $destserver -Path $_
}) -eq $false) {
} elseif (($lastbackup[0].Path | ForEach-Object { Test-DbaPath -SqlInstance $destserver -Path $_ }) -eq $false) {
Write-Message -Level Verbose -Message "SQL Server cannot find backup."
$fileexists = $false
$success = $restoreresult = $dbccresult = "Skipped"
Expand All @@ -376,7 +372,7 @@ function Test-DbaLastBackup {
$totalsize = ($restorelist.BackupSize.Megabyte | Measure-Object -sum ).Sum

if ($MaxSize -and $MaxSize -lt $totalsize) {
$success = "The backup size for $dbname ($mb MB) exceeds the specified maximum size ($MaxSize MB)."
$success = "The backup size for $dbname ($totalsize MB) exceeds the specified maximum size ($MaxSize MB)."
$dbccresult = "Skipped"
} else {
$dbccElapsed = $restoreElapsed = $startRestore = $endRestore = $startDbcc = $endDbcc = $null
Expand Down Expand Up @@ -477,7 +473,7 @@ function Test-DbaLastBackup {
if ($CopyFile) {
Write-Message -Level Verbose -Message "Removing copied backup file from $destination."
try {
$removearray | Remove-item -ErrorAction Stop
$removearray | Remove-Item -ErrorAction Stop
} catch {
Write-Message -Level Warning -Message $_ -ErrorRecord $_ -Target $instance
}
Expand Down