Skip to content

Restore-DbaDatabase - Honor EnableException in the backup information pipeline - #10631

Open
andreasjordan wants to merge 1 commit into
developmentfrom
fix-restoredbadatabase-enableexception
Open

Restore-DbaDatabase - Honor EnableException in the backup information pipeline#10631
andreasjordan wants to merge 1 commit into
developmentfrom
fix-restoredbadatabase-enableexception

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Summary

Fixes #10621. When Restore-DbaDatabase is given backups without a full to anchor the chain, Select-DbaBackupInformation correctly calls Stop-Function - but the splat Restore-DbaDatabase builds for it never passed EnableException on, so under -EnableException the stop degraded to a warning, control returned, and the restore proceeded over an empty $FilteredBackupHistory to a successful-looking no-op. A caller relying on the promised exception (a test fixture, or any script that restores and then uses the database) continued as if the restore had happened - exactly how Get-DbaDbRestoreHistory.Tests.ps1 was flaky for years (#10620).

What changed

  • EnableException = $EnableException added to the Select-DbaBackupInformation splat and the Get-DbaBackupInformation splat, and to the per-file Get-DbaBackupInformation call on the SQL Server 2000 path (now a splat, since it grew to three parameters).
  • The "No backups passed through" bail-out is now a Stop-Function instead of a plain Write-Message -Level Warning, so it too honors -EnableException.

What deliberately did not change

  • Without -EnableException nothing changes: Stop-Function writes the identical warning and returns, so the default warn-and-return behavior is untouched. The open behavior question from Restore-DbaDatabase -EnableException restores nothing with only a warning when no full backup anchors the chain #10621 - whether an empty selection should also stop the non-exception path - is left for a maintainer decision.
  • The Test-DbaBackupInformation call already passed EnableException = $true inside try/catch and stays as it is.
  • Format-DbaBackupInformation contains no Stop-Function at all, so there is nothing to propagate.
  • Get-DbaAgBackupHistory has the same gap on its Select-DbaBackupInformation call and gets its own pull request, one command per PR.

Tests

Three regression tests in a new context, each backup written to its own file so the minute-resolution default name cannot hide the missing full by merging it into the diff's file:

  • diff+log without the full throws *Fullname property not found* with -EnableException (the exact repro from the issue),
  • the same input still warns and returns nothing without it,
  • an existing directory with no backups throws *No backups passed through* with -EnableException.

Full file verified via the lab harness on SQL03\SQL2019: 84 tests, 76 passed, 0 failed, 7 skipped (the documented StopAt and Azure skips), lab left clean.

created by Claude and reviewed by Andreas Jordan

🤖 Generated with Claude Code

… pipeline

The splats for Get-DbaBackupInformation and Select-DbaBackupInformation
never passed EnableException on, so with -EnableException a missing full
backup (or a failed scan) degraded to a warning inside the callee,
control returned, and the restore continued as a successful-looking
no-op over an empty backup history. The empty-history bail-out was a
plain warning for the same reason. This is how a test fixture could
restore diff+log without their full for years and only fail on a minute
boundary (#10620).

EnableException now flows into both splats and into the per-file
Get-DbaBackupInformation call of the SQL Server 2000 path, and the
"No backups passed through" bail-out is a Stop-Function. Without
-EnableException nothing changes: Stop-Function writes the identical
warning and returns. The Test-DbaBackupInformation call already ran
with EnableException inside try/catch and stays as it is, and
Format-DbaBackupInformation has no failure path to propagate.

Verified in the lab on SQL03\SQL2019: 84 tests, 76 passed, 0 failed,
7 skipped, including three new regression tests - diff+log without the
full throws with EnableException, still warns and returns nothing
without it, and an empty directory throws instead of warning.

Fixes #10621

(do Restore-DbaDatabase)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@potatoqualitee potatoqualitee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete current head, all backup-information propagation paths, empty-history behavior, regression coverage, and exact-head SQL CI evidence. No material correctness or compatibility issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restore-DbaDatabase -EnableException restores nothing with only a warning when no full backup anchors the chain

2 participants