Skip to content

Commit

Permalink
Merge pull request #4752 from sqlcollaborative/development
Browse files Browse the repository at this point in the history
0.9.705
  • Loading branch information
potatoqualitee committed Dec 3, 2018
2 parents ea3f4b0 + 1886d85 commit efdd019
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 29 deletions.
Binary file modified allcommands.zip
Binary file not shown.
20 changes: 18 additions & 2 deletions bin/dbatools-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@
"false",
""
],
[
"Secondary",
"Not required - the command will figure this out. But if you\u0027d like to be explicit about replicas, this will help.",
"",
false,
"false",
""
],
[
"SecondarySqlCredential",
"Login to the target instance using alternative credentials. Windows and SQL Authentication supported. Accepts credential objects (Get-Credential)",
"",
false,
"false",
""
],
[
"InputObject",
"Enables piping from Get-DbaDatabase, Get-DbaDbSharePoint and more.",
Expand Down Expand Up @@ -103,7 +119,7 @@
"Name": "Add-DbaAgDatabase",
"Links": "https://dbatools.io/Add-DbaAgDatabase",
"Examples": "-------------------------- EXAMPLE 1 --------------------------\nPS C:\\\u003eAdd-DbaAgDatabase -SqlInstance sql2017a -AvailabilityGroup ag1 -Database db1, db2 -Confirm\nAdds db1 and db2 to ag1 on sql2017a. Prompts for confirmation.\n-------------------------- EXAMPLE 2 --------------------------\nPS C:\\\u003eGet-DbaDatabase -SqlInstance sql2017a | Out-GridView -Passthru | Add-DbaAgDatabase -AvailabilityGroup ag1\nAdds selected databases from sql2017a to ag1\n-------------------------- EXAMPLE 3 --------------------------\nPS C:\\\u003eGet-DbaDbSharePoint -SqlInstance sqlcluster | Add-DbaAgDatabase -AvailabilityGroup SharePoint\nAdds SharePoint databases as found in SharePoint_Config on sqlcluster to ag1 on sqlcluster\n-------------------------- EXAMPLE 4 --------------------------\nPS C:\\\u003eGet-DbaDbSharePoint -SqlInstance sqlcluster -ConfigDatabase SharePoint_Config_2019 | Add-DbaAgDatabase -AvailabilityGroup SharePoint\nAdds SharePoint databases as found in SharePoint_Config_2019 on sqlcluster to ag1 on sqlcluster",
"Syntax": "Add-DbaAgDatabase [[-SqlInstance] \u003cDbaInstanceParameter[]\u003e] [[-SqlCredential] \u003cPSCredential\u003e] [-AvailabilityGroup] \u003cString\u003e [[-Database] \u003cString[]\u003e] [[-InputObject] \u003cDatabase[]\u003e] [[-SeedingMode] \u003cString\u003e] [[-SharedPath] \u003cString\u003e] [-UseLastBackup] [-EnableException] [-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]"
"Syntax": "Add-DbaAgDatabase [[-SqlInstance] \u003cDbaInstanceParameter[]\u003e] [[-SqlCredential] \u003cPSCredential\u003e] [-AvailabilityGroup] \u003cString\u003e [[-Database] \u003cString[]\u003e] [[-Secondary] \u003cDbaInstanceParameter[]\u003e] [[-SecondarySqlCredential] \u003cPSCredential\u003e] [[-InputObject] \u003cDatabase[]\u003e] [[-SeedingMode] \u003cString\u003e] [[-SharedPath] \u003cString\u003e] [-UseLastBackup] [-EnableException] [-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]"
},
{
"CommandName": "Add-DbaAgListener",
Expand Down Expand Up @@ -25518,7 +25534,7 @@
"Synopsis": "Automates the creation of availability groups.",
"Name": "New-DbaAvailabilityGroup",
"Links": "https://dbatools.io/New-DbaAvailabilityGroup",
"Examples": "-------------------------- EXAMPLE 1 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2016a -Name SharePoint\nCreates a new availability group on sql2016a named SharePoint\n-------------------------- EXAMPLE 2 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2016a -Name SharePoint -Secondary sql2016b\nCreates a new availability group on sql2016b named SharePoint with a secondary replica, sql2016b\n-------------------------- EXAMPLE 3 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2016std -Name BAG1 -Basic -Confirm:$false\nCreates a basic availability group named BAG1 on sql2016std and does not confirm when setting up\n-------------------------- EXAMPLE 4 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2016b -Name AG1 -ClusterType Wsfc -Dhcp -Database db1 -UseLastBackup\nCreates an availability group on sql2016b with the name ag1. Uses the last backups available to add the database db1 to the AG.\n-------------------------- EXAMPLE 5 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2017 -Name SharePoint -ClusterType None -FailoverMode Manual\nCreates a new availability group on sql2017 named SharePoint with a cluster type of none and a failover mode of manual\n-------------------------- EXAMPLE 6 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql1 -Secondary sql2 -Name ag1 -Database pubs -ClusterType None -SeedingMode Automatic -FailoverMode Manual\nCreates a new availability group with a primary replica on sql1 and a secondary on sql2. Automatically adds the database pubs.\n-------------------------- EXAMPLE 7 --------------------------\nPS C:\\\u003e$cred = Get-Credential sqladmin\nPS C:\\\u003e $params = @{\r\n \u003e\u003e Primary = \"sql1\"\r\n \u003e\u003e PrimarySqlCredential = $cred\r\n \u003e\u003e Secondary = \"sql2\"\r\n \u003e\u003e SecondarySqlCredential = $cred\r\n \u003e\u003e Name = \"test-ag\"\r\n \u003e\u003e Database = \"pubs\"\r\n \u003e\u003e ClusterType = \"None\"\r\n \u003e\u003e SeedingMode = \"Automatic\"\r\n \u003e\u003e FailoverMode = \"Manual\"\r\n \u003e\u003e Confirm = $false\r\n \u003e\u003e }\r\nPS C:\\\u003e New-DbaAvailabilityGroup @params\nThis exact command was used to create an availability group on docker!",
"Examples": "-------------------------- EXAMPLE 1 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2016a -Name SharePoint\nCreates a new availability group on sql2016a named SharePoint\n-------------------------- EXAMPLE 2 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2016a -Name SharePoint -Secondary sql2016b\nCreates a new availability group on sql2016b named SharePoint with a secondary replica, sql2016b\n-------------------------- EXAMPLE 3 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2016std -Name BAG1 -Basic -Confirm:$false\nCreates a basic availability group named BAG1 on sql2016std and does not confirm when setting up\n-------------------------- EXAMPLE 4 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2016b -Name AG1 -ClusterType Wsfc -Dhcp -Database db1 -UseLastBackup\nCreates an availability group on sql2016b with the name ag1. Uses the last backups available to add the database db1 to the AG.\n-------------------------- EXAMPLE 5 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql2017 -Name SharePoint -ClusterType None -FailoverMode Manual\nCreates a new availability group on sql2017 named SharePoint with a cluster type of none and a failover mode of manual\n-------------------------- EXAMPLE 6 --------------------------\nPS C:\\\u003eNew-DbaAvailabilityGroup -Primary sql1 -Secondary sql2 -Name ag1 -Database pubs -ClusterType None -SeedingMode Automatic -FailoverMode Manual\nCreates a new availability group with a primary replica on sql1 and a secondary on sql2. Automatically adds the database pubs.\n-------------------------- EXAMPLE 7 --------------------------\nPS C:\\\u003e$cred = Get-Credential sqladmin\nPS C:\\\u003e $params = @{\r\n\u003e\u003e Primary = \"sql1\"\r\n\u003e\u003e PrimarySqlCredential = $cred\r\n\u003e\u003e Secondary = \"sql2\"\r\n\u003e\u003e SecondarySqlCredential = $cred\r\n\u003e\u003e Name = \"test-ag\"\r\n\u003e\u003e Database = \"pubs\"\r\n\u003e\u003e ClusterType = \"None\"\r\n\u003e\u003e SeedingMode = \"Automatic\"\r\n\u003e\u003e FailoverMode = \"Manual\"\r\n\u003e\u003e Confirm = $false\r\n\u003e\u003e }\r\nPS C:\\\u003e New-DbaAvailabilityGroup @params\nThis exact command was used to create an availability group on docker!",
"Syntax": "New-DbaAvailabilityGroup [[-Primary] \u003cDbaInstanceParameter\u003e] [[-PrimarySqlCredential] \u003cPSCredential\u003e] [[-Secondary] \u003cDbaInstanceParameter[]\u003e] [[-SecondarySqlCredential] \u003cPSCredential\u003e] [-Name] \u003cString\u003e [-DtcSupport] [[-ClusterType] \u003cString\u003e] [[-AutomatedBackupPreference] \u003cString\u003e] [[-FailureConditionLevel] \u003cString\u003e] [[-HealthCheckTimeout] \u003cInt32\u003e] [-Basic] [-DatabaseHealthTrigger] [-Passthru] [[-Database] \u003cString[]\u003e] [[-SharedPath] \u003cString\u003e] [-UseLastBackup] [-Force] [[-AvailabilityMode] \u003cString\u003e] [[-FailoverMode] \u003cString\u003e] [[-BackupPriority] \u003cInt32\u003e] [[-ConnectionModeInPrimaryRole] \u003cString\u003e] \r\n[[-ConnectionModeInSecondaryRole] \u003cString\u003e] [[-SeedingMode] \u003cString\u003e] [[-Endpoint] \u003cString\u003e] [[-ReadonlyRoutingConnectionUrl] \u003cString\u003e] [[-Certificate] \u003cString\u003e] [[-IPAddress] \u003cIPAddress[]\u003e] [[-SubnetMask] \u003cIPAddress\u003e] [[-Port] \u003cInt32\u003e] [-Dhcp] [-EnableException] [-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]"
},
{
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.705] - 2018-12-3
### Fixed
* Docker support for AGs

## [0.9.704] - 2018-12-3
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion dbatools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '0.9.704'
ModuleVersion = '0.9.705'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
Expand Down
26 changes: 19 additions & 7 deletions functions/Add-DbaAgDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function Add-DbaAgDatabase {
.PARAMETER AvailabilityGroup
The availability group where the databases will be added.
.PARAMETER Secondary
Not required - the command will figure this out. But if you'd like to be explicit about replicas, this will help.
.PARAMETER SecondarySqlCredential
Login to the target instance using alternative credentials. Windows and SQL Authentication supported. Accepts credential objects (Get-Credential)
.PARAMETER InputObject
Enables piping from Get-DbaDatabase, Get-DbaDbSharePoint and more.
Expand Down Expand Up @@ -93,6 +99,8 @@ function Add-DbaAgDatabase {
[parameter(Mandatory)]
[string]$AvailabilityGroup,
[string[]]$Database,
[DbaInstanceParameter[]]$Secondary,
[PSCredential]$SecondarySqlCredential,
[parameter(ValueFromPipeline)]
[Microsoft.SqlServer.Management.Smo.Database[]]$InputObject,
[ValidateSet('Automatic', 'Manual')]
Expand Down Expand Up @@ -125,7 +133,11 @@ function Add-DbaAgDatabase {
Stop-Function -Message "$($db.Name) is already joined to $($ag.Name)" -Continue
}

$secondaryReplicas = $ag.AvailabilityReplicas | Where-Object Role -eq Secondary | Select-Object -Unique -ExpandProperty Name
if (-not $Secondary) {
$secondaryReplicas = $ag.AvailabilityReplicas | Where-Object Role -eq Secondary
} else {
$secondaryReplicas = Get-DbaAgReplica -SqlInstance $Secondary -SqlCredential $SecondarySqlCredential -AvailabilityGroup $ag.Name | Where-Object Role -eq Secondary
}

if ($SeedingMode -eq "Automatic") {
# first check
Expand All @@ -147,7 +159,7 @@ function Add-DbaAgDatabase {

foreach ($replica in $secondaryReplicas) {

$agreplica = Get-DbaAgReplica -SqlInstance $Primary -AvailabilityGroup $ag.name -Replica $replica
$agreplica = Get-DbaAgReplica -SqlInstance $Primary -SqlCredential $SqlCredential -AvailabilityGroup $ag.name -Replica $replica.Name

if ($SeedingMode) {
$agreplica.SeedingMode = $SeedingMode
Expand All @@ -172,21 +184,21 @@ function Add-DbaAgDatabase {
}
if ($Pscmdlet.ShouldProcess("$Secondary", "restoring full and log backups of $primarydb from $Primary")) {
# keep going to ensure output is shown even if dbs aren't added well.
$null = $allbackups[$db] | Restore-DbaDatabase -SqlInstance $replica -WithReplace -NoRecovery -TrustDbBackupHistory -EnableException
$null = $allbackups[$db] | Restore-DbaDatabase -SqlInstance $replica.Parent.Parent -WithReplace -NoRecovery -TrustDbBackupHistory -EnableException
}
} catch {
Stop-Function -Message "Failure" -ErrorRecord $_ -Continue
}
}

$replicadb = Get-DbaAgDatabase -SqlInstance $replica -SqlCredential $SqlCredential -Database $db.Name -AvailabilityGroup $ag.Name #credential of secondary !!
$replicadb = Get-DbaAgDatabase -SqlInstance $replica.Parent.Parent -Database $db.Name -AvailabilityGroup $ag.Name #credential of secondary !!

if ($replicadb -and -not ($SeedingModeReplica -eq 'Automatic')) {
if ($Pscmdlet.ShouldProcess($ag.Parent.Name, "Joining availability group $db to $($db.Parent.Name)")) {
$timeout = 1
do {
try {
Write-Message -Level Verbose -Message "Trying to add $($replicadb.Name) to $replica"
Write-Message -Level Verbose -Message "Trying to add $($replicadb.Name) to $($replica.Name)"
$timeout++
$replicadb.JoinAvailablityGroup()
$replicadb.Refresh()
Expand All @@ -199,7 +211,7 @@ function Add-DbaAgDatabase {
if ($replicadb.IsJoined) {
$replicadb
} else {
Stop-Function -Continue -Message "Could not join $($replicadb.Name) to $replica"
Stop-Function -Continue -Message "Could not join $($replicadb.Name) to $($replica.Name)"
}
}
} else {
Expand All @@ -208,4 +220,4 @@ function Add-DbaAgDatabase {
}
}
}
}
}
2 changes: 1 addition & 1 deletion functions/Get-DbaDbMirrorMonitor.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function Get-DbaDbMirrorMonitor {

foreach ($db in $InputObject) {
if (-not ($db.Parent.Databases['msdb'].Tables['dbm_monitor_data'].Name)) {
Stop-Function -Continue -Message "mdbo.dbo.dbm_monitor_data not found. Please run Add-DbaDbMirrorMonitor then you can get monitor stats."
Stop-Function -Continue -Message "msdb.dbo.dbm_monitor_data not found. Please run Add-DbaDbMirrorMonitor then you can get monitor stats."
}
try {
$sql = "msdb.dbo.sp_dbmmonitorresults $db, $rows, $updatebool"
Expand Down
34 changes: 19 additions & 15 deletions functions/New-DbaAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ function New-DbaAvailabilityGroup {
.EXAMPLE
PS C:\> $cred = Get-Credential sqladmin
PS C:\> $params = @{
>> Primary = "sql1"
>> PrimarySqlCredential = $cred
>> Secondary = "sql2"
>> SecondarySqlCredential = $cred
>> Name = "test-ag"
>> Database = "pubs"
>> ClusterType = "None"
>> SeedingMode = "Automatic"
>> FailoverMode = "Manual"
>> Confirm = $false
>> }
>> Primary = "sql1"
>> PrimarySqlCredential = $cred
>> Secondary = "sql2"
>> SecondarySqlCredential = $cred
>> Name = "test-ag"
>> Database = "pubs"
>> ClusterType = "None"
>> SeedingMode = "Automatic"
>> FailoverMode = "Manual"
>> Confirm = $false
>> }
PS C:\> New-DbaAvailabilityGroup @params
This exact command was used to create an availability group on docker!
Expand Down Expand Up @@ -480,7 +480,12 @@ function New-DbaAvailabilityGroup {
}

# Add listener
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Adding listener"
if ($IPAddress -or $Dhcp) {
$progressmsg = "Adding listener"
} else {
$progressmsg = "Joining availability group"
}
Write-ProgressHelper -StepNumber ($stepCounter++) -Message $progressmsg

if ($IPAddress) {
if ($Pscmdlet.ShouldProcess($Primary, "Adding static IP listener for $Name to the Primary replica")) {
Expand Down Expand Up @@ -571,10 +576,9 @@ function New-DbaAvailabilityGroup {
}

# Add databases

Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Adding databases"

Add-DbaAgDatabase -SqlInstance $Primary -AvailabilityGroup $Name -Database $Database -SeedingMode $SeedingMode -SharedPath $SharedPath
$null = Add-DbaAgDatabase -SqlInstance $Primary -SqlCredential $PrimarySqlCredential -AvailabilityGroup $Name -Database $Database -SeedingMode $SeedingMode -SharedPath $SharedPath -Secondary $Secondary -SecondarySqlCredential $SecondarySqlCredential

foreach ($second in $secondaries) {
if ($server.HostPlatform -ne "Linux" -and $second.HostPlatform -ne "Linux") {
Expand Down Expand Up @@ -608,4 +612,4 @@ function New-DbaAvailabilityGroup {
# Get results
Get-DbaAvailabilityGroup -SqlInstance $Primary -SqlCredential $PrimarySqlCredential -AvailabilityGroup $Name
}
}
}
4 changes: 2 additions & 2 deletions tests/Add-DbaAgDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
<#
Get commands, Default count = 11
Commands with SupportShouldProcess = 13
#>
#>
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Add-DbaAgDatabase).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Database', 'InputObject', 'EnableException', 'SeedingMode', 'SharedPath', 'UseLastBackup'
$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Database', 'InputObject', 'EnableException', 'SeedingMode', 'SharedPath', 'UseLastBackup', 'Secondary', 'SecondarySqlCredential'
$paramCount = $knownParameters.Count
It "Should contain our specific parameters" {
((Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $paramCount
Expand Down
2 changes: 1 addition & 1 deletion tests/New-DbaAvailabilityGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' {
<#
Get commands, Default count = 11
Commands with SupportShouldProcess = 13
#>
#>
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\New-DbaAvailabilityGroup).Parameters.Keys
$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', 'ReadonlyRoutingConnectionUrl', 'Certificate', 'IPAddress', 'SubnetMask', 'Port', 'Dhcp', 'EnableException'
Expand Down

0 comments on commit efdd019

Please sign in to comment.