Author | Chrissy LeMaire (@cl), netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Sync-DbaAvailabilityGroup on GitHub.
Want to see the Bill Of Health for this command? Check out Sync-DbaAvailabilityGroup.
Syncs dependent objects such as jobs, logins and custom errors for availability groups
Syncs dependent objects for availability groups. Such objects include:
SpConfigure
CustomErrors
Credentials
DatabaseMail
LinkedServers
Logins
LoginPermissions
SystemTriggers
DatabaseOwner
AgentCategory
AgentOperator
AgentAlert
AgentProxy
AgentSchedule
AgentJob
Note that any of these can be excluded. For specific object exclusions (such as a single job), using the underlying Copy-Dba* command will be required.
This command does not filter by which logins are in use by the ag databases or which linked servers are used. All objects that are not excluded will be copied like hulk smash.
Sync-DbaAvailabilityGroup
[[-Primary] <DbaInstanceParameter>]
[[-PrimarySqlCredential] <PSCredential>]
[[-Secondary] <DbaInstanceParameter[]>]
[[-SecondarySqlCredential] <PSCredential>]
[[-AvailabilityGroup] <String>]
[[-Exclude] <String[]>]
[[-Login] <String[]>]
[[-ExcludeLogin] <String[]>]
[[-Job] <String[]>]
[[-ExcludeJob] <String[]>]
[-DisableJobOnDestination]
[[-InputObject] <AvailabilityGroup[]>]
[-Force]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Sync-DbaAvailabilityGroup -Primary sql2016a -AvailabilityGroup db3
Syncs the following on all replicas found in the db3 AG:
SpConfigure, CustomErrors, Credentials, DatabaseMail, LinkedServers
Logins, LoginPermissions, SystemTriggers, DatabaseOwner, AgentCategory,
AgentOperator, AgentAlert, AgentProxy, AgentSchedule, AgentJob
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sql2016a | Sync-DbaAvailabilityGroup -ExcludeType LoginPermissions, LinkedServers -ExcludeLogin login1, login2 -Job job1, job2
Syncs the following on all replicas found in all AGs on the specified instance:
SpConfigure, CustomErrors, Credentials, DatabaseMail, Logins,
SystemTriggers, DatabaseOwner, AgentCategory, AgentOperator
AgentAlert, AgentProxy, AgentSchedule, AgentJob.
Copies all logins except for login1 and login2 and only syncs job1 and job2
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sql2016a | Sync-DbaAvailabilityGroup -WhatIf
Shows what would happen if the command were to run but doesn't actually perform the action.
The primary SQL Server instance. Server version must be SQL Server version 2012 or higher.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The target SQL Server instance or instances. Server version must be SQL Server version 2012 or higher.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The name of the Availability Group.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Exclude one or more objects to export
SpConfigure
CustomErrors
Credentials
DatabaseMail
LinkedServers
Logins
LoginPermissions
SystemTriggers
DatabaseOwner
AgentCategory
AgentOperator
AgentAlert
AgentProxy
AgentSchedule
AgentJob
Alias | ExcludeType |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | AgentCategory,AgentOperator,AgentAlert,AgentProxy,AgentSchedule,AgentJob,Credentials,CustomErrors,DatabaseMail,DatabaseOwner,LinkedServers,Logins,LoginPermissions,SpConfigure,SystemTriggers |
Specific logins to sync. If unspecified, all logins will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specific logins to exclude when performing the sync. If unspecified, all logins will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specific jobs to sync. If unspecified, all jobs will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specific jobs to exclude when performing the sync. If unspecified, all jobs will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, the newly migrated job will be disabled on the destination server.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Enables piping from Get-DbaAvailabilityGroup.
Alias | |
Required | False |
Pipeline | true (ByValue) |
Default Value |
If this switch is enabled, the objects will dropped and recreated on Destination.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Shows what would happen if the command were to run. No actions are actually performed.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts you for confirmation before executing any changing operations within the command.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |