Get-DbaAgBackupHistory - Fix single replica discovery and honor EnableException - #10632
Merged
potatoqualitee merged 1 commit intoSep 1, 2026
Merged
Conversation
…eException Two defects, both found while sweeping issue #10621 into this command: The single-server branch assigned the replica names to the server list as-is. With exactly one replica, SMO returns a scalar string, so indexing the list yielded the first character of the replica name and the DbaInstanceParameter binder turned that into null - the command failed with "Cannot bind argument to parameter SqlInstance because it is null" for every single replica availability group queried without -Database. The list is now forced to an array. The -Last branch piped into Select-DbaBackupInformation without passing EnableException on, so a chain without a full backup degraded the stop to a warning and the command returned nothing even when the caller asked for exceptions. EnableException now flows into that call; without the switch nothing changes. The command had no integration tests at all - the old comment said no availability group runs in AppVeyor, which predates the HADR lane. New tests build a single replica ClusterType NONE availability group, verify the healthy chain, and pin both EnableException behaviors via a -Since window that holds only a log backup. We use -Since instead of wiping msdb history because Backup-DbaDatabase refuses a log backup for a database whose history holds no full backup. Verified in the lab on SQL04\SQL2025: 4 integration tests passed, lab left clean; the unfixed code failed the same tests with the null bind. References #10621 (do Get-DbaAgBackupHistory) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
potatoqualitee
approved these changes
Aug 30, 2026
potatoqualitee
left a comment
Member
There was a problem hiding this comment.
Reviewed the complete current head, single-replica scalar handling, exception propagation, integration coverage, and exact-head HADR CI evidence. No material correctness or compatibility issues found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion to #10631, sweeping issue #10621 into the one other caller of
Select-DbaBackupInformation- and the new tests immediately exposed a second, harder defect in the same command.Defect 1: single replica availability groups fail outright
The single-server branch assigns
.AvailabilityReplicas.Nameto$serverListas-is. With exactly one replica, SMO returns a scalar string, so$serverList[0]indexes the string and yields its first character (S), which theDbaInstanceParameterbinder turns into null: every query of a single replica AG without-Databasefailed with "Cannot bind argument to parameter 'SqlInstance' because it is null". Fixed by forcing the list to an array, with a comment stating the constraint.Defect 2: the -Last branch ignored -EnableException
$AgResults | Select-DbaBackupInformation -ServerName $AvailabilityGroupnever passedEnableExceptionon, so a backup chain without a full to anchor it degraded the stop to a warning and the command returned nothing even when the caller asked for exceptions.EnableExceptionnow flows into that call. Without the switch nothing changes - the identical warning is written and nothing is returned, as before.Tests
The command had no integration tests at all; the old comment ("no availability group running in AppVeyor") predates the HADR lane. The new tests build a single replica ClusterType NONE availability group with a full+log chain and verify:
-Sincewindow that holds only a log backup,-EnableExceptionthrowsFullname property not foundand the default path warns and returns nothing.-Sinceis used instead of wiping msdb history becauseBackup-DbaDatabaserefuses a log backup for a database whose msdb history holds no full backup - found out the hard way in the lab.Verified via the lab harness on SQL04\SQL2025: 4 integration tests passed, lab left clean; the unfixed code failed the same tests with the null bind.
created by Claude and reviewed by Andreas Jordan
🤖 Generated with Claude Code