Skip to content

Get-DbaAgBackupHistory - Fix single replica discovery and honor EnableException - #10632

Merged
potatoqualitee merged 1 commit into
developmentfrom
fix-getdbaagbackuphistory-enableexception
Sep 1, 2026
Merged

Get-DbaAgBackupHistory - Fix single replica discovery and honor EnableException#10632
potatoqualitee merged 1 commit into
developmentfrom
fix-getdbaagbackuphistory-enableexception

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

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.Name to $serverList as-is. With exactly one replica, SMO returns a scalar string, so $serverList[0] indexes the string and yields its first character (S), which the DbaInstanceParameter binder turns into null: every query of a single replica AG without -Database failed 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 $AvailabilityGroup never passed EnableException on, 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. EnableException now 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:

  • the healthy chain comes back warning-free with Full and Log tagged with the AG name (this test alone catches defect 1),
  • with a -Since window that holds only a log backup, -EnableException throws Fullname property not found and the default path warns and returns nothing.

-Since is used instead of wiping msdb history because Backup-DbaDatabase refuses 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

…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 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, single-replica scalar handling, exception propagation, integration coverage, and exact-head HADR CI evidence. No material correctness or compatibility issues found.

@potatoqualitee
potatoqualitee merged commit ac0260e into development Sep 1, 2026
22 checks passed
@potatoqualitee
potatoqualitee deleted the fix-getdbaagbackuphistory-enableexception branch September 1, 2026 05:12
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.

2 participants