-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
New Support for Contained Availability Groups #9345
Changes from 5 commits
3011556
353cef1
d97d972
21d786c
611ac24
0fd3d62
e2678a4
c981d1c
adda53f
fc183c9
4861320
1941dbe
df8afc2
847fa22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
function New-DbaAvailabilityGroup { | ||
function New-DbaAvailabilityGroup { | ||
<# | ||
.SYNOPSIS | ||
Automates the creation of availability groups. | ||
|
@@ -56,6 +56,14 @@ function New-DbaAvailabilityGroup { | |
.PARAMETER Name | ||
The name of the Availability Group. | ||
|
||
.PARAMETER IsContained | ||
Builds the Availability Group as contained. Only supported in SQL Server 2022 or higher. | ||
|
||
https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/contained-availability-groups-overview?view=sql-server-ver16 | ||
|
||
.PARAMETER ReuseSystemDatabases | ||
Used when rebuilding a cluster where system databases already exist for the contained availability group. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not use the term "cluster" here. Quote from the documentation: "This option is only valid for contained AGs, and specifies that the newly created AG should reuse existing contained system databases for a previous contained AG of the same name. For example, if you had a contained AG with the name MyContainedAG, and wanted to drop and recreate it, you could use this option to reuse the contents of the original contained system databases." |
||
.PARAMETER DtcSupport | ||
Indicates whether the DtcSupport is enabled | ||
|
||
|
@@ -219,6 +227,11 @@ function New-DbaAvailabilityGroup { | |
|
||
Creates a basic availability group named BAG1 on sql2016std and does not confirm when setting up | ||
|
||
.EXAMPLE | ||
PS C:\> New-DbaAvailabilityGroup -Primary sql2022n01 -Secondary sql2022n02 -Name AgContained -IsContained | ||
|
||
Creates a contained availability group named AgContained on sql2022 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of "sql2022" (which is your cluster name?) we should name the nodes: "sql2022n01 and sql2022n02". |
||
.EXAMPLE | ||
PS C:\> New-DbaAvailabilityGroup -Primary sql2016b -Name AG1 -Dhcp -Database db1 -UseLastBackup | ||
|
||
|
@@ -268,6 +281,8 @@ function New-DbaAvailabilityGroup { | |
|
||
[parameter(Mandatory)] | ||
[string]$Name, | ||
[switch]$IsContained, | ||
[switch]$ReuseSystemDatabases, | ||
[switch]$DtcSupport, | ||
[ValidateSet('Wsfc', 'External', 'None')] | ||
[string]$ClusterType = (Get-DbatoolsConfigValue -FullName 'AvailabilityGroups.Default.ClusterType' -Fallback 'Wsfc'), | ||
|
@@ -366,6 +381,14 @@ function New-DbaAvailabilityGroup { | |
return | ||
} | ||
|
||
if ($IsContained -and $server.VersionMajor -lt 16) { | ||
Stop-Function -Level Warning -Message "Contained availability groups are only supported in SQL Server 2022 and above" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aa you can see some lines above, we need an additional "return" in case Stop-Function only issues a warning and not an exception (this depends on -EnableException). And please remove the |
||
|
||
if ($ReuseSystemDatabases -and $IsContained -eq $false) { | ||
Write-Message -Level Warning -Message "Reuse system databases is only applicable in contained availability groups test " | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does "test" mean? And there is a space at the end of the string. |
||
|
||
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Checking requirements" | ||
$requirementsFailed = $false | ||
|
||
|
@@ -488,6 +511,7 @@ function New-DbaAvailabilityGroup { | |
$ag.AutomatedBackupPreference = [Microsoft.SqlServer.Management.Smo.AvailabilityGroupAutomatedBackupPreference]::$AutomatedBackupPreference | ||
$ag.FailureConditionLevel = [Microsoft.SqlServer.Management.Smo.AvailabilityGroupFailureConditionLevel]::$FailureConditionLevel | ||
$ag.HealthCheckTimeout = $HealthCheckTimeout | ||
$ag.ReuseSystemDatabases = $ReuseSystemDatabases | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it is saver (and better to read) if we move this line after the new line 527 ($ag.IsContained = $IsContained). This way, the two new parameters are used only on 2022 and newer. This way, the code does not change for older versions of sql server. |
||
if ($server.VersionMajor -ge 13) { | ||
$ag.BasicAvailabilityGroup = $Basic | ||
|
@@ -499,6 +523,10 @@ function New-DbaAvailabilityGroup { | |
$ag.ClusterType = $ClusterType | ||
} | ||
|
||
if ($server.VersionMajor -ge 16) { | ||
$ag.IsContained = $IsContained | ||
} | ||
|
||
if ($PassThru) { | ||
$defaults = 'LocalReplicaRole', 'Name as AvailabilityGroup', 'PrimaryReplicaServerName as PrimaryReplica', 'AutomatedBackupPreference', 'AvailabilityReplicas', 'AvailabilityDatabases', 'AvailabilityGroupListeners' | ||
return (Select-DefaultView -InputObject $ag -Property $defaults) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan | |
Describe "$commandname Unit Tests" -Tag 'UnitTests' { | ||
Context "Validate parameters" { | ||
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } | ||
[object[]]$knownParameters = 'Primary', 'PrimarySqlCredential', 'Secondary', 'SecondarySqlCredential', 'Name', 'DtcSupport', 'ClusterType', 'AutomatedBackupPreference', 'FailureConditionLevel', 'HealthCheckTimeout', 'Basic', 'DatabaseHealthTrigger', 'Passthru', 'Database', 'SharedPath', 'UseLastBackup', 'Force', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'Endpoint', 'EndpointUrl', 'Certificate', 'ConfigureXESession', 'IPAddress', 'SubnetMask', 'Port', 'Dhcp', 'EnableException' | ||
[object[]]$knownParameters = 'Primary', 'PrimarySqlCredential', 'Secondary', 'SecondarySqlCredential', 'Name', 'DtcSupport', 'ClusterType', 'AutomatedBackupPreference', 'FailureConditionLevel', 'HealthCheckTimeout', 'Basic', 'DatabaseHealthTrigger', 'Passthru', 'Database', 'SharedPath', 'UseLastBackup', 'Force', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'Endpoint', 'EndpointUrl', 'Certificate', 'ConfigureXESession', 'IPAddress', 'SubnetMask', 'Port', 'Dhcp', 'EnableException', 'ReuseSystemDatabases', 'IsContained' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to have the order of parameters in this list in the order of the param block. So after "name" in this case. |
||
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters | ||
It "Should only contain our specific parameters" { | ||
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would exclude the "?view=sql-server-ver16" to always point to the latest version.