Skip to content

Commit 890ac7b

Browse files
committed
Addressing PR comments.
1 parent f09e761 commit 890ac7b

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

articles/azure-sql/managed-instance/managed-instance-link-use-scripts-to-failover-database.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
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
33
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.
55
services: sql-database
66
ms.service: sql-managed-instance
77
ms.subservice: data-movement
@@ -18,7 +18,7 @@ ms.date: 03/15/2022
1818

1919
[!INCLUDE[appliesto-sqlmi](../includes/appliesto-sqlmi.md)]
2020

21-
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.
2222

2323
> [!NOTE]
2424
> 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
2929
> [!TIP]
3030
> SQL Managed Instance link database failover can be set up with [SSMS wizard](managed-instance-link-use-ssms-to-failover-database.md).
3131
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.
3333

3434
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.
3535

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.
3737

3838
## Switch the replication mode from asynchronous to synchronous
3939

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.
4242

4343
## Switch replication mode on Managed Instance
4444

@@ -107,7 +107,7 @@ Invoke-WebRequest -Method PATCH -Headers $headers -Uri $uriFull -ContentType "ap
107107
## Switch replication mode on SQL Server
108108

109109
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.
111111

112112
```sql
113113
-- Sets the Distributed Availability Group to synchronous commit.
@@ -123,7 +123,7 @@ AVAILABILITY GROUP ON
123123
(AVAILABILITY_MODE = SYNCHRONOUS_COMMIT);
124124
```
125125

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.
127127

128128
```sql
129129
-- Verifies the state of the distributed availability group
@@ -141,11 +141,11 @@ WHERE
141141
ag.is_distributed=1
142142
```
143143

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.
145145

146146
## Check LSN values on both SQL Server and Managed Instance
147147

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.
149149

150150
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.
151151

@@ -170,9 +170,9 @@ WHERE
170170

171171
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.
172172

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.
174174

175-
```
175+
```sql
176176
-- Obtain LSN for a database on SQL Managed Instance.
177177
SELECT
178178
db.name AS [Database name],
@@ -199,7 +199,7 @@ SQL Managed Instance link database failover and migration to Azure is accomplish
199199

200200
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.
201201

202-
```
202+
```PowerShell
203203
# ====================================================================================
204204
# POWERSHELL SCRIPT TO FAILOVER AND MIGRATE DATABASE WITH SQL MANAGED INSTANCE LINK
205205
# USER CONFIGURABLE VALUES
@@ -246,7 +246,7 @@ Invoke-WebRequest -Method DELETE -Headers $headers -Uri $uriFull -ContentType "a
246246

247247
## Cleanup Availability Group and Distributed Availability Group on SQL Server
248248

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.
250250
Replace `<DAGName>` with the name of the Distributed Availability Group on SQL Server and replace `<AGName>` with Availability Group name on the SQL Server.
251251

252252
``` sql
@@ -260,7 +260,7 @@ With this step, the migration of the database from SQL Server to Managed Instanc
260260

261261
## Next steps
262262

263-
For more information on the link feature, see the following:
263+
For more information on the link feature, see the following resources:
264264

265265
- [Managed Instance link – connecting SQL Server to Azure reimagined](https://aka.ms/mi-link-techblog).
266266
- [Prepare for SQL Managed Instance link](./managed-instance-link-preparation.md).

articles/azure-sql/managed-instance/managed-instance-link-use-scripts-to-replicate-database.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ This first step in creating SQL Managed Instance link is establishing the trust
6060

6161
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.
6262

63-
> [IMPORTANT]
63+
> [!IMPORTANT]
6464
> Certificates are generated with an expiry date and time, and they need to be rotated before they expire.
6565
6666
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
100100
SELECT * FROM sys.certificates
101101
```
102102

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.
104104

105105
Now you can get the public key of the generated certificate.
106106

@@ -115,7 +115,7 @@ SELECT @PUBLICKEYENC AS PublicKeyEncoded;
115115

116116
Save the value of PublicKeyEncoded from the output, as it will be needed for the next step.
117117

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.
119119

120120
Execute the following PowerShell script in Azure Cloud Shell (fill out necessary user information, copy, paste into Azure Cloud Shell and execute).
121121
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.
@@ -197,7 +197,7 @@ EXEC sp_get_endpoint_certificate @endpoint_type = 4
197197

198198
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.
199199

200-
> [IMPORTANT]
200+
> [!IMPORTANT]
201201
> Name of the certificate must be SQL Managed Instance FQDN.
202202
203203
```sql
@@ -254,7 +254,7 @@ New mirroring endpoint was created with CERTIFICATE authentication, and AES encr
254254

255255
### Altering existing database mirroring endpoint
256256

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.
258258
> Use this step only if using existing Availability Groups with existing database mirroring endpoint.
259259
>
260260
@@ -343,14 +343,14 @@ WITH (CLUSTER_TYPE = NONE)
343343
GO
344344
```
345345

346-
>[NOTE]
346+
> [!NOTE]
347347
> One database per single Availability Group is the current product limitation for replication to SQL Managed Instance using the link feature.
348348
> If you get the Error 1475 you'll have to create a full backup without COPY ONLY option, that will start new backup chain.
349349
> 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.
350350
351351
### Verify AG and distributed AG
352352

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.
354354

355355
```sql
356356
-- 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
365365

366366
## Creating SQL Managed Instance link
367367

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.
369369

370370
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.
371371

@@ -462,10 +462,10 @@ FROM
462462

463463
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.
464464

465-
>[IMPORTANT]
465+
> [!IMPORTANT]
466466
> 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).
467467
468-
>[IMPORTANT]
468+
> [!IMPORTANT]
469469
> 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).
470470
471471
## Next steps
@@ -474,6 +474,6 @@ For more information on the link feature, see the following:
474474

475475
- [Managed Instance link – connecting SQL Server to Azure reimagined](https://aka.ms/mi-link-techblog).
476476
- [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).
478478
- [Use SQL Managed Instance link via SSMS to replicate database](./managed-instance-link-use-ssms-to-replicate-database.md).
479479
- [Use SQL Managed Instance link via SSMS to migrate database](./managed-instance-link-use-ssms-to-failover-database.md).

articles/azure-sql/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@
12431243
href: managed-instance/link-feature-best-practices.md
12441244
- name: Replicate databases with scripts
12451245
href: managed-instance/managed-instance-link-use-scripts-to-replicate-database.md
1246-
- name: Failover databases with scripts
1246+
- name: Fail over databases with scripts
12471247
href: managed-instance/managed-instance-link-use-scripts-to-failover-database.md
12481248

12491249
- name: Configure business continuity

0 commit comments

Comments
 (0)