Azure SQL Managed Instance – Sync Agent Jobs and Logins in Failover Groups

Published Oct 21 2021 01:09 PM 1,583 Views
Microsoft

Introduction

In an Azure SQL Managed Instance setup with Failover Group, the schema, data, and database-level users will always be synced between primary and secondary instance. As of October 2021, there is no sync mechanism for SQL Server Agent Jobs or Server Logins/Roles because the functionality of replicating system databases does not exist. This blog provides guidance and scripts to implement a workaround solution to have the Agent Jobs and Server Logins/Roles synced between primary and secondary instances.

 

Sync Agent Jobs

The objective of syncing Agent jobs is achieved by having a custom database named “AgentDB” in the MI instance which stores the latest job definitions from primary. There will be a SQL Agent Job that runs in both primary and secondary which will monitor on a schedule for failover events.

In the event of a failover, the jobs from the primary managed instance will be automatically created in a secondary managed instance by using the definition stored in the AgentDB.

The reason for choosing the AgentDB as the main information holder is due to the following:

  1. It avoids the need for a Linked Server between the managed instances.
  2. To isolate the objects required for the sync mechanism which else may have led to interfering with other user databases and schemas. If this is not wished then the scripts can be modified to use an existing user database.

Limitations

There are certain limitations in the workaround which should be noted before using the scripts.

  1. If a job is in-progress during failover, all the progress made will be lost. The secondary jobs will start only from the first step.
  2. When job switching occurs between primary and secondary, the history will be lost as the jobs are deleted and created.
  3. Instant specific jobs like primary only jobs and secondary only jobs is not available and can be extended based on the available scripts.

Solution Components

The solution contains two major components, A user database “AgentDB” and a scheduled job “SyncLoginsAndAgentJobs”.

Custom Database - AgentDB

The AgentDB contains the following supporting tables and procedures for syncing the jobs:

  1. Tables:
    1. Syscategories: Stores the job categories
    2. Sysfailoverhistory: Stores cluster failover history information
    3. Sysjobs: Stores agent job details
    4. Sysjobschedules: Stores job and schedule relation details
    5. Sysjobservers: stores job servers’ information
    6. Sysjobsteps: Stores all job step details
    7. Sysschedules: Stores all available schedules for the agent
  2. Procedures:
    1. SyncAgentJobs: This is the main procedure that acts as an entry point for Syncing Agent jobs across primary and secondary managed instances.
    2. BackupAgentJobs: This procedure copies the job definitions from msdb system tables to AgentDB tables with a similar structure. 
    3. CreateJobsInNewPrimary: This procedure creates new jobs in secondary after the primary failover to secondary.
    4. DisableJobsInSecondary: This procedure is used to disable all the common jobs on the secondary instance which were created as part of the failover process when the primary is available and takes over the primary role.

Sync Scenarios

The default setup in two managed instances, Instance A and Instance B.

  1. Instance A – Primary
  2. Instance B – Secondary

Scenario 1: Instance A is Primary

When Instance A is primary, SQL Agent job contents from msdb will be copied from the local MSDB to the AgentDB and into the respective tables.

image002.png

Scenario 2: Instance B is Primary after Failover

When Instance B becomes primary after failover happens, the SQL agent job contents from AgentDB are used to create or sync jobs in the SQL Agent running in Instance B.

image003.png

Agent DB databases will be kept in sync between Instance A and Instance B by using the standard database replication feature of failover groups.

 

Sync Server Logins/Roles

Ensure AgentDB is fully synced between primary and secondary before continuing with the following Login Sync section.

The additional functionality of syncing logins is also achieved by using the same aforementioned custom user database “AgentDB” in the managed instance which stores the latest logins, roles, and permission definitions from the primary managed instance. There will be a SQL Agent Job which runs in both primary and secondary which will take the latest job definitions synced to the secondary and create the logins automatically. Both AAD and SQL logins are handled.

The Sync Agent Job can be scheduled to run at user defined intervals, the default value is to run every 2 minutes.

Limitations

There are certain limitations in the workaround which should be noted before using the scripts.

  1. If a Login/Role creation is in-progress during failover, all the progress made will be lost. The Secondary server won’t have these logins and associated access and permissions.

Solution Components

The solution contains two major components, A user database called “AgentDB” and a scheduled job called “SyncLoginsAndAgentJobs”.

Database objects - AgentDB

The AgentDB contains the following supporting tables and procedures for syncing the logins/roles:

  1. Tables:
    1. dbo.syssqllogins: Contains one row for each login account.
    2. dbo.sysserverpermissions: Stores permissions given to any principal
    3. dbo.sysserverprincipals: Contains a row for every server-level principal.
      1. S = SQL login
      2. U = Windows login
      3. E = External Login (AAD)
      4. G = Windows group
      5. X = External Group (AAD)
      6. R = Server role
      7. C = Login mapped to a certificate
      8. K = Login mapped to an asymmetric key
    4. dbo.sysserverrolemembers: Stores one row for each member of each fixed and user-defined server role.
  1. Procedures:
    1. SyncLoginsRolePermissions: This is the main procedure which acts as an entry point for Syncing Logins jobs across primary and secondary MI instances.
    2. BackupLoginsRolePermissions:This procedure copies the login, roles, and permission definitions from system tables to AgentDB tables with similar structure.
    3. CreateLoginsInSecondary: This procedure creates/updates/deletes logins, roles, and permissions in secondary based on the latest definitions copied from primary.

 

SQL Agent Job – SyncLoginsAndAgentJobs

This is a SQL agent job which runs in both the primary managed instance as well as the secondary managed instance with a recurring schedule of 2 minutes. The agent job calls two stored procedures “SyncAgentJobs” and “SyncLoginsRolesPermissions” held within the AgentDB. The job schedule can be modified based on custom requirement. Any new jobs created in primary will be created in secondary as disabled. Also, any changes made to the jobs in the primary will be carried over to the secondary but disable state is maintained.

 

Deployment Steps

To deploy the solution, follow the below steps in order (Scripts are located here),

  1. Enable Failover cluster in Azure SQL Managed Instance.
  2. Check and verify if primary and secondary databases are online and accessible.
  3. Run 01_Create_AgentDB.sql in primary to create AgentDB database
  4. Run 02_Create_Tables.sql in primary to create necessary tables.
  5. Run 03_Create_Procedures.sql in primary to create necessary procedures.
  6. Ensure AgentDB is fully synced between primary and secondary.
  7. Run 04_Create_Agent_Job.sql in primary to create Sync Agent Job in SQL Agent.
  8. Run 04_Create_Agent_Job.sql in secondary to create Sync Agent Job in SQL Agent.
  9. Validate the solution functionality by doing a manual failover.

 

Feedback and suggestions

If you have feedback or suggestions for improving this data migration asset, please contact the Database Platform Engineering Team. Thanks for your support!

%3CLINGO-SUB%20id%3D%22lingo-sub-2860495%22%20slang%3D%22en-US%22%3EAzure%20SQL%20Managed%20Instance%20%E2%80%93%20Sync%20Agent%20Jobs%20and%20Logins%20in%20Failover%20Groups%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2860495%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--323013392%22%20id%3D%22toc-hId--322061139%22%3EIntroduction%3C%2FH2%3E%0A%3CP%3EIn%20an%20Azure%20SQL%20Managed%20Instance%20setup%20with%20Failover%20Group%2C%20the%20schema%2C%20data%2C%20and%20database-level%20users%20will%20always%20be%20synced%20between%20primary%20and%20secondary%20instance.%20As%20of%20October%202021%2C%20there%20is%20no%20sync%20mechanism%20for%20SQL%20Server%20Agent%20Jobs%20or%20Server%20Logins%2FRoles%20because%20the%20functionality%20of%20replicating%20system%20databases%20does%20not%20exist.%20This%20blog%20provides%20guidance%20and%20scripts%20to%20implement%20a%20workaround%20solution%20to%20have%20the%20Agent%20Jobs%20and%20Server%20Logins%2FRoles%20synced%20between%20primary%20and%20secondary%20instances.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2130467855%22%20id%3D%22toc-hId--2129515602%22%3ESync%20Agent%20Jobs%3C%2FH2%3E%0A%3CP%3EThe%20objective%20of%20syncing%20Agent%20jobs%20is%20achieved%20by%20having%20a%20custom%20database%20named%20%E2%80%9CAgentDB%E2%80%9D%20in%20the%20MI%20instance%20which%20stores%20the%20latest%20job%20definitions%20from%20primary.%20There%20will%20be%20a%20SQL%20Agent%20Job%20that%20runs%20in%20both%20primary%20and%20secondary%20which%20will%20monitor%20on%20a%20schedule%20for%20failover%20events.%3C%2FP%3E%0A%3CP%3EIn%20the%20event%20of%20a%20failover%2C%20the%20jobs%20from%20the%20primary%20managed%20instance%20will%20be%20automatically%20created%20in%20a%20secondary%20managed%20instance%20by%20using%20the%20definition%20stored%20in%20the%20AgentDB.%3C%2FP%3E%0A%3CP%3EThe%20reason%20for%20choosing%20the%20AgentDB%20as%20the%20main%20information%20holder%20is%20due%20to%20the%20following%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EIt%20avoids%20the%20need%20for%20a%20Linked%20Server%20between%20the%20managed%20instances.%3C%2FLI%3E%0A%3CLI%3ETo%20isolate%20the%20objects%20required%20for%20the%20sync%20mechanism%20which%20else%20may%20have%20led%20to%20interfering%20with%20other%20user%20databases%20and%20schemas.%20If%20this%20is%20not%20wished%20then%20the%20scripts%20can%20be%20modified%20to%20use%20an%20existing%20user%20database.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH3%20id%3D%22toc-hId--1439906381%22%20id%3D%22toc-hId--1438954128%22%3ELimitations%3C%2FH3%3E%0A%3CP%3EThere%20are%20certain%20limitations%20in%20the%20workaround%20which%20should%20be%20noted%20before%20using%20the%20scripts.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EIf%20a%20job%20is%20in-progress%20during%20failover%2C%20all%20the%20progress%20made%20will%20be%20lost.%20The%20secondary%20jobs%20will%20start%20only%20from%20the%20first%20step.%3C%2FLI%3E%0A%3CLI%3EWhen%20job%20switching%20occurs%20between%20primary%20and%20secondary%2C%20the%20history%20will%20be%20lost%20as%20the%20jobs%20are%20deleted%20and%20created.%3C%2FLI%3E%0A%3CLI%3EInstant%20specific%20jobs%20like%20primary%20only%20jobs%20and%20secondary%20only%20jobs%20is%20not%20available%20and%20can%20be%20extended%20based%20on%20the%20available%20scripts.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH3%20id%3D%22toc-hId-1047606452%22%20id%3D%22toc-hId-1048558705%22%3ESolution%20Components%3C%2FH3%3E%0A%3CP%3EThe%20solution%20contains%20two%20major%20components%2C%20A%20user%20database%20%E2%80%9CAgentDB%E2%80%9D%20and%20a%20scheduled%20job%20%E2%80%9CSyncLoginsAndAgentJobs%E2%80%9D.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECustom%20Database%20-%20AgentDB%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20AgentDB%20contains%20the%20following%20supporting%20tables%20and%20procedures%20for%20syncing%20the%20jobs%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CU%3ETables%3C%2FU%3E%3A%3COL%20class%3D%22lia-list-style-type-lower-alpha%22%3E%0A%3CLI%3ESyscategories%3A%20Stores%20the%20job%20categories%3C%2FLI%3E%0A%3CLI%3ESysfailoverhistory%3A%20Stores%20cluster%20failover%20history%20information%3C%2FLI%3E%0A%3CLI%3ESysjobs%3A%20Stores%20agent%20job%20details%3C%2FLI%3E%0A%3CLI%3ESysjobschedules%3A%20Stores%20job%20and%20schedule%20relation%20details%3C%2FLI%3E%0A%3CLI%3ESysjobservers%3A%20stores%20job%20servers%E2%80%99%20information%3C%2FLI%3E%0A%3CLI%3ESysjobsteps%3A%20Stores%20all%20job%20step%20details%3C%2FLI%3E%0A%3CLI%3ESysschedules%3A%20Stores%20all%20available%20schedules%20for%20the%20agent%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CU%3EProcedures%3C%2FU%3E%3A%3COL%20class%3D%22lia-list-style-type-lower-alpha%22%3E%0A%3CLI%3ESyncAgentJobs%3A%20This%20is%20the%20main%20procedure%20that%20acts%20as%20an%20entry%20point%20for%20Syncing%20Agent%20jobs%20across%20primary%20and%20secondary%20managed%20instances.%3C%2FLI%3E%0A%3CLI%3EBackupAgentJobs%3A%20This%20procedure%20copies%20the%20job%20definitions%20from%20msdb%20system%20tables%20to%20AgentDB%20tables%20with%20a%20similar%20structure.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3ECreateJobsInNewPrimary%3A%20This%20procedure%20creates%20new%20jobs%20in%20secondary%20after%20the%20primary%20failover%20to%20secondary.%3C%2FLI%3E%0A%3CLI%3EDisableJobsInSecondary%3A%20This%20procedure%20is%20used%20to%20disable%20all%20the%20common%20jobs%20on%20the%20secondary%20instance%20which%20were%20created%20as%20part%20of%20the%20failover%20process%20when%20the%20primary%20is%20available%20and%20takes%20over%20the%20primary%20role.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH3%20id%3D%22toc-hId--759848011%22%20id%3D%22toc-hId--758895758%22%3ESync%20Scenarios%3C%2FH3%3E%0A%3CP%3EThe%20default%20setup%20in%20two%20managed%20instances%2C%20Instance%20A%20and%20Instance%20B.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EInstance%20A%20%E2%80%93%20Primary%3C%2FLI%3E%0A%3CLI%3EInstance%20B%20%E2%80%93%20Secondary%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3EScenario%201%3A%20Instance%20A%20is%20Primary%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EWhen%20Instance%20A%20is%20primary%2C%20SQL%20Agent%20job%20contents%20from%20msdb%20will%20be%20copied%20from%20the%20local%20MSDB%20to%20the%20AgentDB%20and%20into%20the%20respective%20tables.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image002.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F318312i75DC88C3DF3BE2C8%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image002.png%22%20alt%3D%22image002.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EScenario%202%3A%20Instance%20B%20is%20Primary%20after%20Failover%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EWhen%20Instance%20B%20becomes%20primary%20after%20failover%20happens%2C%20the%20SQL%20agent%20job%20contents%20from%20AgentDB%20are%20used%20to%20create%20or%20sync%20jobs%20in%20the%20SQL%20Agent%20running%20in%20Instance%20B.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image003.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F318315i1DDD7A3E0F2D5E94%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image003.png%22%20alt%3D%22image003.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EAgent%20DB%20databases%20will%20be%20kept%20in%20sync%20between%20Instance%20A%20and%20Instance%20B%20by%20using%20the%20standard%20database%20replication%20feature%20of%20failover%20groups.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--770351115%22%20id%3D%22toc-hId--769398862%22%3ESync%20Server%20Logins%2FRoles%3C%2FH2%3E%0A%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CU%3E%3CSTRONG%3EEnsure%20AgentDB%20is%20fully%20synced%20between%20primary%20and%20secondary%20before%20continuing%20with%20the%20following%20Login%20Sync%20section.%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EThe%20additional%20functionality%20of%20syncing%20logins%20is%20also%20achieved%20by%20using%20the%20same%20aforementioned%20custom%20user%20database%20%E2%80%9CAgentDB%E2%80%9D%20in%20the%20managed%20instance%20which%20stores%20the%20latest%20logins%2C%20roles%2C%20and%20permission%20definitions%20from%20the%20primary%20managed%20instance.%20There%20will%20be%20a%20SQL%20Agent%20Job%20which%20runs%20in%20both%20primary%20and%20secondary%20which%20will%20take%20the%20latest%20job%20definitions%20synced%20to%20the%20secondary%20and%20create%20the%20logins%20automatically.%20Both%20AAD%20and%20SQL%20logins%20are%20handled.%3C%2FP%3E%0A%3CP%3EThe%20Sync%20Agent%20Job%20can%20be%20scheduled%20to%20run%20at%20user%20defined%20intervals%2C%20the%20default%20value%20is%20to%20run%20every%202%20minutes.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--79789641%22%20id%3D%22toc-hId--78837388%22%3ELimitations%3C%2FH3%3E%0A%3CP%3EThere%20are%20certain%20limitations%20in%20the%20workaround%20which%20should%20be%20noted%20before%20using%20the%20scripts.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EIf%20a%20Login%2FRole%20creation%20is%20in-progress%20during%20failover%2C%20all%20the%20progress%20made%20will%20be%20lost.%20The%20Secondary%20server%20won%E2%80%99t%20have%20these%20logins%20and%20associated%20access%20and%20permissions.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH3%20id%3D%22toc-hId--1887244104%22%20id%3D%22toc-hId--1886291851%22%3ESolution%20Components%3C%2FH3%3E%0A%3CP%3EThe%20solution%20contains%20two%20major%20components%2C%20A%20user%20database%20called%20%E2%80%9CAgentDB%E2%80%9D%20and%20a%20scheduled%20job%20called%20%E2%80%9CSyncLoginsAndAgentJobs%E2%80%9D.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EDatabase%20objects%20-%20AgentDB%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20AgentDB%20contains%20the%20following%20supporting%20tables%20and%20procedures%20for%20syncing%20the%20logins%2Froles%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CU%3ETables%3C%2FU%3E%3A%3COL%20class%3D%22lia-list-style-type-lower-alpha%22%3E%0A%3CLI%3Edbo.syssqllogins%3A%20Contains%20one%20row%20for%20each%20login%20account.%3C%2FLI%3E%0A%3CLI%3Edbo.sysserverpermissions%3A%20Stores%20permissions%20given%20to%20any%20principal%3C%2FLI%3E%0A%3CLI%3Edbo.sysserverprincipals%3A%20Contains%20a%20row%20for%20every%20server-level%20principal.%3COL%20class%3D%22lia-list-style-type-lower-roman%22%3E%0A%3CLI%3ES%20%3D%20SQL%20login%3C%2FLI%3E%0A%3CLI%3EU%20%3D%20Windows%20login%3C%2FLI%3E%0A%3CLI%3EE%20%3D%20External%20Login%20(AAD)%3C%2FLI%3E%0A%3CLI%3EG%20%3D%20Windows%20group%3C%2FLI%3E%0A%3CLI%3EX%20%3D%20External%20Group%20(AAD)%3C%2FLI%3E%0A%3CLI%3ER%20%3D%20Server%20role%3C%2FLI%3E%0A%3CLI%3EC%20%3D%20Login%20mapped%20to%20a%20certificate%3C%2FLI%3E%0A%3CLI%3EK%20%3D%20Login%20mapped%20to%20an%20asymmetric%20key%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3CLI%3Edbo.sysserverrolemembers%3A%20Stores%20one%20row%20for%20each%20member%20of%20each%20fixed%20and%20user-defined%20server%20role.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3COL%20start%3D%222%22%3E%0A%3CLI%3E%3CU%3EProcedures%3C%2FU%3E%3A%3COL%20class%3D%22lia-list-style-type-lower-alpha%22%3E%0A%3CLI%3ESyncLoginsRolePermissions%3A%20This%20is%20the%20main%20procedure%20which%20acts%20as%20an%20entry%20point%20for%20Syncing%20Logins%20jobs%20across%20primary%20and%20secondary%20MI%20instances.%3C%2FLI%3E%0A%3CLI%3EBackupLoginsRolePermissions%3AThis%20procedure%20copies%20the%20login%2C%20roles%2C%20and%20permission%20definitions%20from%20system%20tables%20to%20AgentDB%20tables%20with%20similar%20structure.%3C%2FLI%3E%0A%3CLI%3ECreateLoginsInSecondary%3A%20This%20procedure%20creates%2Fupdates%2Fdeletes%20logins%2C%20roles%2C%20and%20permissions%20in%20secondary%20based%20on%20the%20latest%20definitions%20copied%20from%20primary.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1897747208%22%20id%3D%22toc-hId--1896794955%22%3ESQL%20Agent%20Job%20%E2%80%93%20SyncLoginsAndAgentJobs%3C%2FH2%3E%0A%3CP%3EThis%20is%20a%20SQL%20agent%20job%20which%20runs%20in%20both%20the%20primary%20managed%20instance%20as%20well%20as%20the%20secondary%20managed%20instance%20with%20a%20recurring%20schedule%20of%202%20minutes.%20The%20agent%20job%20calls%20two%20stored%20procedures%20%E2%80%9CSyncAgentJobs%E2%80%9D%20and%20%E2%80%9CSyncLoginsRolesPermissions%E2%80%9D%20held%20within%20the%20AgentDB.%20The%20job%20schedule%20can%20be%20modified%20based%20on%20custom%20requirement.%26nbsp%3BAny%20new%20jobs%20created%20in%20primary%20will%20be%20created%20in%20secondary%20as%20disabled.%20Also%2C%20any%20changes%20made%20to%20the%20jobs%20in%20the%20primary%20will%20be%20carried%20over%20to%20the%20secondary%20but%20disable%20state%20is%20maintained.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-589765625%22%20id%3D%22toc-hId-590717878%22%3EDeployment%20Steps%3C%2FH2%3E%0A%3CP%3ETo%20deploy%20the%20solution%2C%20follow%20the%20below%20steps%20in%20order%20(Scripts%20are%20located%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fdownload%2Fdetails.aspx%3Fid%3D103563%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%3CSTRONG%3Ehere%3C%2FSTRONG%3E%3C%2FA%3E)%2C%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EEnable%20Failover%20cluster%20in%20Azure%20SQL%20Managed%20Instance.%3C%2FLI%3E%0A%3CLI%3ECheck%20and%20verify%20if%20primary%20and%20secondary%20databases%20are%20online%20and%20accessible.%3C%2FLI%3E%0A%3CLI%3ERun%2001_Create_AgentDB.sql%20in%20primary%20to%20create%20AgentDB%20database%3C%2FLI%3E%0A%3CLI%3ERun%2002_Create_Tables.sql%20in%20primary%20to%20create%20necessary%20tables.%3C%2FLI%3E%0A%3CLI%3ERun%2003_Create_Procedures.sql%20in%20primary%20to%20create%20necessary%20procedures.%3C%2FLI%3E%0A%3CLI%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CSTRONG%3EEnsure%20AgentDB%20is%20fully%20synced%20between%20primary%20and%20secondary.%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FLI%3E%0A%3CLI%3ERun%2004_Create_Agent_Job.sql%20in%20primary%20to%20create%20Sync%20Agent%20Job%20in%20SQL%20Agent.%3C%2FLI%3E%0A%3CLI%3ERun%2004_Create_Agent_Job.sql%20in%20secondary%20to%20create%20Sync%20Agent%20Job%20in%20SQL%20Agent.%3C%2FLI%3E%0A%3CLI%3EValidate%20the%20solution%20functionality%20by%20doing%20a%20manual%20failover.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-456080901%22%20id%3D%22toc-hId-457033154%22%3EFeedback%20and%20suggestions%3C%2FH2%3E%0A%3CP%3EIf%20you%20have%20feedback%20or%20suggestions%20for%20improving%20this%20data%20migration%20asset%2C%20please%20contact%20the%20%3CA%20href%3D%22mailto%3Adatasqlninja%40microsoft.com%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EDatabase%20Platform%20Engineering%20Team%3C%2FA%3E.%20Thanks%20for%20your%20support!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2860495%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20an%20Azure%20SQL%20Managed%20Instance%20setup%20with%20Failover%20Group%2C%20the%20schema%2C%20data%2C%20and%20database-level%20users%20will%20always%20be%20synced%20between%20primary%20and%20secondary%20instances.%20As%20of%20October%202021%2C%20there%20is%20no%20sync%20mechanism%20for%20SQL%20Server%20Agent%20Jobs%20or%20Server%20Logins%2FRoles%20because%20the%20functionality%20of%20replicating%20system%20databases%20does%20not%20exist.%20This%20document%20provides%20guidance%20and%20scripts%20to%20implement%20a%20workaround%20solution%20to%20have%20the%20Agent%20Jobs%20and%20Server%20Logins%2FRoles%20synced%20between%20primary%20and%20secondary%20instances.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2860495%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDatabase%20Platform%20CSE%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDatabase%20Platform%20CSE%20%E2%80%93%20SQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Nov 10 2021 01:58 AM
Updated by: