You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-sql/managed-instance/managed-instance-link-use-scripts-to-failover-database.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: Failover database with link feature with T-SQL and PowerShell scripts
2
+
title: Fail over database with link feature with T-SQL and PowerShell scripts
3
3
titleSuffix: Azure SQL Managed Instance
4
-
description: This guide teaches you how to use the SQL Managed Instance link with scripts to failover database from SQL Server to Azure SQL Managed Instance.
4
+
description: This guide teaches you how to use the SQL Managed Instance link with scripts to fail over database from SQL Server to Azure SQL Managed Instance.
This article teaches you to use scripts, T-SQL and PowerShell, to use[Managed Instance link feature](link-feature.md), more specifically to failover (migrate) your database from SQL Server to Azure SQL Managed Instance.
21
+
This article teaches you to use T-SQL and PowerShell scripts for[Managed Instance link feature](link-feature.md)to fail over (migrate) your database from SQL Server to Azure SQL Managed Instance.
22
22
23
23
> [!NOTE]
24
24
> The link feature for Azure SQL Managed Instance is currently in preview.
@@ -29,16 +29,16 @@ This article teaches you to use scripts, T-SQL and PowerShell, to use [Managed I
29
29
> [!TIP]
30
30
> SQL Managed Instance link database failover can be set up with [SSMS wizard](managed-instance-link-use-ssms-to-failover-database.md).
31
31
32
-
Failing over your database from your SQL Server instance to your SQL Managed Instance breaks the link between the two databases, stopping replication, and leaving both databases in an independent state, ready for individual read-write workloads.
32
+
Database failover from SQL Server instance to SQL Managed Instance breaks the link between the two databases. Failover stops replication and leaves both databases in an independent state, ready for individual read-write workloads.
33
33
34
34
To start migrating database to the SQL Managed Instance, first stop the application workload to the SQL Server during your maintenance hours. This is required to enable SQL Managed Instance to catchup with the database replication and make migration to Azure without any data loss.
35
35
36
-
Note that while database is a part of Always On Availability Group, it is not possible to set it to read-only mode. You will need to ensure that your applications(s) are not committing transactions to SQL Server.
36
+
While database is a part of Always On Availability Group, it isn't possible to set it to read-only mode. You'll need to ensure that your application(s) aren't committing transactions to SQL Server.
37
37
38
38
## Switch the replication mode from asynchronous to synchronous
39
39
40
-
The replication between SQL Server and SQL Managed Instance is asynchronous by default. Before migrating databse to Azure, link needs to be switched to synchronous mode. Synchronous replication across distances might slow down transactions on the primary SQL Server.
41
-
Switching from Async to Sync mode requires replication mode change on SQL Managed Instance as well as on SQL Server.
40
+
The replication between SQL Server and SQL Managed Instance is asynchronous by default. Before you perform database migration to Azure, the link needs to be switched to synchronous mode. Synchronous replication across distances might slow down transactions on the primary SQL Server.
41
+
Switching from async to sync mode requires replication mode change on SQL Managed Instance and SQL Server.
Use the following T-SQL script to change the replication mode of Distributed Availability Group on SQL Server from async to sync. Replace `<DAGName>` with the name of Distributed Availability Group, and replace `<AGName>` with the name of Availability Group created on SQL Server. In addition, replace `<ManagedInstanceName>` with the name of your SQL Managed Instance.
110
-
With this step, the migration of the database from SQL Server to SQL Managed Instance is been completed.
110
+
With this step, the migration of the database from SQL Server to SQL Managed Instance is completed.
111
111
112
112
```sql
113
113
-- Sets the Distributed Availability Group to synchronous commit.
@@ -123,7 +123,7 @@ AVAILABILITY GROUP ON
123
123
(AVAILABILITY_MODE = SYNCHRONOUS_COMMIT);
124
124
```
125
125
126
-
To validate change of the link replication, execute the following DMV, and expected results are shown below. They are indicating SYNCHRONOUS_COMIT state.
126
+
To validate change of the link replication, execute the following DMV, and expected results are shown below. They're indicating SYNCHRONOUS_COMIT state.
127
127
128
128
```sql
129
129
-- Verifies the state of the distributed availability group
@@ -141,11 +141,11 @@ WHERE
141
141
ag.is_distributed=1
142
142
```
143
143
144
-
With both SQL Managed Instance, and SQL Server being switched to Sync mode, the replication between the two entities is now synchronous. If you require to reverse this state, follow the same steps by setting async state in properties for both SQL Server and SQL Managed Instance.
144
+
With both SQL Managed Instance, and SQL Server being switched to Sync mode, the replication between the two entities is now synchronous. If you require to reverse this state, follow the same steps and set async state for both SQL Server and SQL Managed Instance.
145
145
146
146
## Check LSN values on both SQL Server and Managed Instance
147
147
148
-
To complete the migration, we need to ensure that the replication has completed. For this we need to ensure that LSNs (Log Sequence Numbers) indicating the log records written for both SQL Server and SQL Managed Instance are the same. Initially, it is expected that SQL Server LSN will be higher than LSN number on SQL Managed Instance. The difference is caused by the fact that SQL Managed Instance might be lagging somewhat behind the primary SQL Server due to network latency. After some time, LSNs on SQL Managed Instance and SQL Server should match and stop changing, as the workload on SQL Server should be stopped.
148
+
To complete the migration, we need to ensure that the replication has completed. For this, you need to ensure that LSNs (Log Sequence Numbers) indicating the log records written for both SQL Server and SQL Managed Instance are the same. Initially, it's expected that SQL Server LSN will be higher than LSN number on SQL Managed Instance. The difference is caused by the fact that SQL Managed Instance might be lagging somewhat behind the primary SQL Server due to network latency. After some time, LSNs on SQL Managed Instance and SQL Server should match and stop changing, as the workload on SQL Server should be stopped.
149
149
150
150
Use the following T-SQL query on SQL Server to read the LSN number of the last recorded transaction log. Replace `<DatabaseName>` with your database name and look for the last hardened LSN number, as shown below.
151
151
@@ -170,9 +170,9 @@ WHERE
170
170
171
171
Use the following T-SQL query on SQL Managed Instance to read the LSN number of the last hardened LSN number for your database. Replace `<DatabaseName>` with your database name.
172
172
173
-
Query shown below will work on General Purpose SQL Managed Instance. For Business Critical Managed Instance, you will need to uncomment `and drs.is_primary_replica = 1` at the end of the script. On Business Critical, this will read only primary replica details.
173
+
Query shown below will work on General Purpose SQL Managed Instance. For Business Critical Managed Instance, you will need to uncomment `and drs.is_primary_replica = 1` at the end of the script. On Business Critical, this filter will make sure that only primary replica details are read.
174
174
175
-
```
175
+
```sql
176
176
-- Obtain LSN for a database on SQL Managed Instance.
177
177
SELECT
178
178
db.nameAS [Database name],
@@ -199,7 +199,7 @@ SQL Managed Instance link database failover and migration to Azure is accomplish
199
199
200
200
Use the following API to initiate database failover to Azure. Replace `<YourSubscriptionID>` with your actual Azure subscription ID. Replace `<RG>` with the resource group where your SQL Managed Instance is deployed and replace `<ManagedInstanceName>` with the name of our SQL Managed Instance. In addition, replace `<DAGName>` with the name of Distributed Availability Group made on SQL Server.
## Cleanup Availability Group and Distributed Availability Group on SQL Server
248
248
249
-
After breaking the link and migrating database to Azure SQL Managed Instance, consider cleaning up Availability Group and Distributed Availability Group on SQL Server if they are not used otherwise.
249
+
After breaking the link and migrating database to Azure SQL Managed Instance, consider cleaning up Availability Group and Distributed Availability Group on SQL Server if they aren't used otherwise.
250
250
Replace `<DAGName>` with the name of the Distributed Availability Group on SQL Server and replace `<AGName>` with Availability Group name on the SQL Server.
251
251
252
252
```sql
@@ -260,7 +260,7 @@ With this step, the migration of the database from SQL Server to Managed Instanc
260
260
261
261
## Next steps
262
262
263
-
For more information on the link feature, see the following:
263
+
For more information on the link feature, see the following resources:
264
264
265
265
-[Managed Instance link – connecting SQL Server to Azure reimagined](https://aka.ms/mi-link-techblog).
266
266
-[Prepare for SQL Managed Instance link](./managed-instance-link-preparation.md).
Copy file name to clipboardExpand all lines: articles/azure-sql/managed-instance/managed-instance-link-use-scripts-to-replicate-database.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ This first step in creating SQL Managed Instance link is establishing the trust
60
60
61
61
Certificates-based trust is the only supported way to secure database mirroring endpoints on SQL Server and SQL Managed Instance. In case you've existing Availability Groups that are using Windows Authentication, certificate based trust needs to be added to the existing mirroring endpoint as a secondary authentication option. This can be done by using ALTER ENDPOINT statement.
62
62
63
-
> [IMPORTANT]
63
+
> [!IMPORTANT]
64
64
> Certificates are generated with an expiry date and time, and they need to be rotated before they expire.
65
65
66
66
Here's the overview of the process to secure database mirroring endpoints for both SQL Server and SQL Managed Instance:
@@ -100,7 +100,7 @@ GO
100
100
SELECT*FROMsys.certificates
101
101
```
102
102
103
-
In the query results you'll find the certificate and will see that is has been encrypted with the master key.
103
+
In the query results you'll find the certificate and will see that it has been encrypted with the master key.
104
104
105
105
Now you can get the public key of the generated certificate.
106
106
@@ -115,7 +115,7 @@ SELECT @PUBLICKEYENC AS PublicKeyEncoded;
115
115
116
116
Save the value of PublicKeyEncoded from the output, as it will be needed for the next step.
117
117
118
-
Next step should be executed in PowerShell, with installed Az.Sql module, version 3.5.1 or higher, or use Azure Cloud shell online to run the commands as it's always updated wit the latest module versions.
118
+
Next step should be executed in PowerShell, with installed Az.Sql module, version 3.5.1 or higher, or use Azure Cloud Shell online to run the commands as it's always updated wit the latest module versions.
119
119
120
120
Execute the following PowerShell script in Azure Cloud Shell (fill out necessary user information, copy, paste into Azure Cloud Shell and execute).
121
121
Replace `<SubscriptionID>` with your Azure Subscription ID. Replace `<ManagedInstanceName>` with the short name of your managed instance. Replace `<PublicKeyEncoded>` below with the public portion of the SQL Server certificate in binary format generated in the previous step. That will be a long string value starting with 0x, that you've obtained from SQL Server.
Copy the entire public key from Managed Instance starting with “0x” shown in the previous step and use it in the below query by replacing `<InstanceCertificate>` with the key value. No quotations need to be used.
199
199
200
-
> [IMPORTANT]
200
+
> [!IMPORTANT]
201
201
> Name of the certificate must be SQL Managed Instance FQDN.
202
202
203
203
```sql
@@ -254,7 +254,7 @@ New mirroring endpoint was created with CERTIFICATE authentication, and AES encr
254
254
255
255
### Altering existing database mirroring endpoint
256
256
257
-
> [NOTE] SKIP this step if you've just created a new mirroring endpoint.
257
+
> [!NOTE] SKIP this step if you've just created a new mirroring endpoint.
258
258
> Use this step only if using existing Availability Groups with existing database mirroring endpoint.
259
259
>
260
260
@@ -343,14 +343,14 @@ WITH (CLUSTER_TYPE = NONE)
343
343
GO
344
344
```
345
345
346
-
>[NOTE]
346
+
>[!NOTE]
347
347
> One database per single Availability Group is the current product limitation for replication to SQL Managed Instance using the link feature.
348
348
> If you get the Error 1475 you'll have to create a full backup without COPY ONLY option, that will start new backup chain.
349
349
> As the best practice it's highly recommended that collation on SQL Server and SQL Managed Instance is the same. This is because depending on collation settings, AG and DAG names could, or could not be case sensitive. If there's a mismatch with this, there could be issues in ability to successfully connect SQL Server to Managed Instance.
350
350
351
351
### Verify AG and distributed AG
352
352
353
-
Use the following script to list all available Availability Groups and Distributed Availability Groups on the SQL Server. Availability Group state needs to be connected, and Distributed Availability Group state disconnected at this point. Distributed Availability Group state will move to connected only when it has been joined with SQL Managed Instance. This will be explained in one of the next steps.
353
+
Use the following script to list all available Availability Groups and Distributed Availability Groups on the SQL Server. Availability Group state needs to be connected, and Distributed Availability Group state disconnected at this point. Distributed Availability Group state will move to `connected` only when it has been joined with SQL Managed Instance. This will be explained in one of the next steps.
354
354
355
355
```sql
356
356
-- This will show that Availability Group and Distributed Availability Group have been created on SQL Server.
@@ -365,7 +365,7 @@ Alternatively, in SSMS object explorer, expand the “Always On High Availabilit
365
365
366
366
## Creating SQL Managed Instance link
367
367
368
-
The final step of the set up is to create the SQL Managed Instance link. To accomplish this, a REST API call will be made. Invoking direct API calls will be replaced with PowerShell and CLI clients, which will be delivered in one of our next releases.
368
+
The final step of the setup process is to create the SQL Managed Instance link. To accomplish this, a REST API call will be made. Invoking direct API calls will be replaced with PowerShell and CLI clients, which will be delivered in one of our next releases.
369
369
370
370
Invoking direct API call to Azure can be accomplished with various API clients. However, for simplicity of the process, execute the below PowerShell script from Azure Cloud Shell.
371
371
@@ -462,10 +462,10 @@ FROM
462
462
463
463
In addition, once the connection is established, Managed Instance Databases view in SSMS will initially show replicated database as “Restoring…”. This is because the initial seeding is in progress moving the full backup of the database, which is followed by the catchup replication. Once the seeding process is done, the database will no longer be in “Restoring…” state. For small databases, seeding might finish quickly so you might not see the initial “Restoring…” state in SSMS.
464
464
465
-
>[IMPORTANT]
465
+
>[!IMPORTANT]
466
466
> The link will not work unless network connectivity exists between SQL Server and Managed Instance. To troubleshoot the network connectivity following steps described in [test bidirectional network connectivity](managed-instance-link-preparation.md#test-bidirectional-network-connectivity).
467
467
468
-
>[IMPORTANT]
468
+
>[!IMPORTANT]
469
469
> Make regular backups of the log file on SQL Server. If the log space used reaches 100%, the replication to SQL Managed Instance will stop until this space use is reduced. It is highly recommended that you automate log backups through setting up a daily job. For more details on how to do this see [Backup log files on SQL Server](link-feature-best-practices.md#take-log-backups-regularly).
470
470
471
471
## Next steps
@@ -474,6 +474,6 @@ For more information on the link feature, see the following:
474
474
475
475
-[Managed Instance link – connecting SQL Server to Azure reimagined](https://aka.ms/mi-link-techblog).
476
476
-[Prepare for SQL Managed Instance link](./managed-instance-link-preparation.md).
477
-
-[Use SQL Managed Instance link via SSMS to migrate database](./managed-instance-link-use-scripts-to-failover-database.md).
477
+
-[Use SQL Managed Instance link wity scripts to migrate database](./managed-instance-link-use-scripts-to-failover-database.md).
478
478
-[Use SQL Managed Instance link via SSMS to replicate database](./managed-instance-link-use-ssms-to-replicate-database.md).
479
479
-[Use SQL Managed Instance link via SSMS to migrate database](./managed-instance-link-use-ssms-to-failover-database.md).
0 commit comments