Skip to content
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
8 changes: 8 additions & 0 deletions public/Restore-DbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,14 @@ function Restore-DbaDatabase {
if ($StopAfterSelectBackupInformation) {
return
}
if (-not $FilteredBackupHistory) {
# Without -EnableException, Select-DbaBackupInformation only warns when nothing restorable is left - no
# full backup anchors the chain, or nothing is newer than the continue point - and used to hand an empty
# selection on to the restore, which then returned nothing and looked like success (#10657). Say plainly
# that nothing was restored; the warning before this one names the reason.
Stop-Function -Message "Nothing to restore: the backup information selected no restorable backups for $($BackupHistory.Database | Sort-Object -Unique) on $RestoreInstance. A full backup has to anchor the chain (or -Continue has to point at a database restored with -NoRecovery), see the warning above for what was missing."
return
}
try {
Write-Message -Level Verbose -Message "VerifyOnly = $VerifyOnly"
$parms = @{
Expand Down
21 changes: 20 additions & 1 deletion tests/Restore-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,14 @@ Describe $CommandName -Tag IntegrationTests {
WarningAction = "SilentlyContinue"
}
$results = Restore-DbaDatabase @splatRestore
$WarnVar | Should -BeLike "*Fullname property not found*"
$results | Should -BeNullOrEmpty
# Two warnings: the selection names what is missing, and the command says that nothing was
# restored because of it (#10657). Before, the second one did not exist and the empty result
# looked like a successful restore.
$warnings = @($WarnVar) -join " "
$warnings | Should -BeLike "*Fullname property not found*"
$warnings | Should -BeLike "*Nothing to restore*"
$warnings | Should -BeLike "*$chainDbName*"
}

It "Throws when the path holds no backups at all with EnableException" {
Expand All @@ -239,6 +245,19 @@ Describe $CommandName -Tag IntegrationTests {
}
{ Restore-DbaDatabase @splatRestore } | Should -Throw "*No backups passed through*"
}

It "Warns that no backups passed through and returns nothing without EnableException" {
$splatRestore = @{
SqlInstance = $TestConfig.InstanceSingle
Path = $emptyBackupDir
DatabaseName = $chainDbName
WithReplace = $true
WarningAction = "SilentlyContinue"
}
$results = Restore-DbaDatabase @splatRestore
$results | Should -BeNullOrEmpty
@($WarnVar) -join " " | Should -BeLike "*No backups passed through*"
}
}


Expand Down