Skip to content

New-DbaDbSnapshot: Add Basic Availability Group Support #9632

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

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

ReeceGoding
Copy link
Contributor

@ReeceGoding ReeceGoding commented Mar 25, 2025

Should close #9631... In theory. This is just my quick best guess made in the GitHub GUI. I don't have PowerShell installed on this machine and, to be embarrassingly honest, I don't think that I ever learned how to build dbatools correctly even on my proper machine.

Type of Change

  • Bug fix (non-breaking change, fixes # )
  • New feature (non-breaking change, adds functionality, fixes New-DbaDbSnapshot: Support Basic Availability Group Secondaries #9631 )
  • Breaking change (affects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (Invoke-ManualPester)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/dataplat/appveyor-lab ?
  • Unit test is included
  • Documentation
  • Build system

Purpose

Test for BAGs, then snapshot if so.

Approach

As above.

Commands to test

Just New-DbaDbSnapshot. However, once this is working, I should see if the other snapshot commands support BAGs.

Screenshots

N/A

Learning

N/A

@@ -188,6 +188,9 @@ function New-DbaDbSnapshot {
Write-Message -Level Warning -Message "$($db.name) is a snapshot, skipping"
} elseif ($db.name -in $NoSupportForSnap) {
Write-Message -Level Warning -Message "$($db.name) snapshots are prohibited"
} elseif ($db.IsAccessible -ne $true -and EngineEdition -eq "Standard" -and -not [string]::IsNullOrEmpty($db.AvailabilityGroupName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

mmmh, this "EngineEdition" doesn't exist

Copy link
Contributor

Choose a reason for hiding this comment

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

also, why checking for the edition if the point is that if it's part of a group is allowed ?
also, the fact that it's part of an availability group suffices or MUST be a secondary, too ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mmmh, this "EngineEdition" doesn't exist

Oh. That was careless. Thanks @niphlod

also, why checking for the edition if the point is that if it's part of a group is allowed ?
also, the fact that it's part of an availability group suffices or MUST be a secondary, too ?

I'm only trying to address the part that I know is broken. I haven't thought to check if this is also broken on normal AGs. If it is, then I'm stunned that I was the first to find it.

I'm worried that, if I'm not too lenient, I'll be making databases that ought to have been treated as truly unaccessible instead fall on to my new branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

to be fair, the whole "ordeal" is just a "correct-er" filtering of databases, so you can test it just with (pseudo-code)

$server = Connect-DbaInstance -SqlInstance <yourinstance> -MinimumVersion 9
$dbs = $server.Databases
....
$theListOfMyDbs = @() 
foreach ($db in $dbs) {
                if ($db.IsMirroringEnabled) {
                    $theListOfMyDbs += $db
                } elseif ($db.IsDatabaseSnapshot) {
                    Write-Message -Level Warning -Message "$($db.name) is a snapshot, skipping"
                } elseif ($db.name -in $NoSupportForSnap) {
                    Write-Message -Level Warning -Message "$($db.name) snapshots are prohibited"
                ... add your own filters
                } elseif ($db.IsAccessible -ne $true) {
                    Write-Message -Level Verbose -Message "$($db.name) is not accessible, skipping"
                } else {
                    $theListOfMyDbs += $db
                }
            }
$theListOfMyDbs

so you don't even need to be able to get the source code and run your own version of new-dbadbsnapshot.

I'm worried that, if I'm not too lenient, I'll be making databases that ought to have been treated as truly unaccessible instead fall on to my new branch.

Given the issue is that "I want to run on SECONDARIES" I'd expect the filter to account for that, too.

@niphlod
Copy link
Contributor

niphlod commented Mar 25, 2025

@ReeceGoding , nothing to build. Just clone the repo or download the zip and import-module dbatools.psd1 from there .
Alter the function, reimport via import-module dbatools.psd1 -Force, should work out of the box.

@ReeceGoding
Copy link
Contributor Author

ReeceGoding commented Mar 25, 2025

reimport via import-module dbatools.psd1 -Force, should work out of the box.

Oh. It's that easy? I'll have to try it, but not tonight. I've been looking for an excuse to get PowerShell working on my Linux machine.

@ReeceGoding ReeceGoding force-pushed the patch-6 branch 2 times, most recently from 5f75481 to 1c924ee Compare April 12, 2025 20:55
@ReeceGoding
Copy link
Contributor Author

@niphlod Thanks for the massive tips. I think this finally works. As you suspected, there's nothing special about BAGs. Any AG database that isn't considered readable was impacted by this.

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.

New-DbaDbSnapshot: Support Basic Availability Group Secondaries
2 participants