Cyber Deals - Get up to 65% off on CKA, CKAD, CKS, KCNA, KCSA exams and courses!

On-premise SQL Server to Azure SQL Migration using Log Replay Service (LRS)-Part 3 Migration

On-premise SQL Server to Azure SQL Migration using Log Replay Service (LRS)-Part 3 Migration

Migration Procedure

Start the migration

You start the migration by starting LRS. You can start the service in either autocomplete or continuous mode.

When you use autocomplete mode, the migration will finish automatically when the last of the specified backup files has been restored. This option requires the start command to specify the filename of the last backup file.

When you use continuous mode, the service will continuously restore any new backup files that were added. The migration will finish on the manual cutover only.

Here we are using continuous mode, since we want to migrate the databases with minimal downtime.

Start LRS in continuous mode

Here’s an example of starting LRS in continuous mode by using PowerShell:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. [Learn more about bidirectional Unicode characters](https://github.co/hiddenchars)
[Show hidden characters](/on-premise-sql-server-to-azure-sql-migration-using-log-replay-service-lrs-part-3-migration/{{ revealButtonHref }})
Start-AzSqlInstanceDatabaseLogReplay -ResourceGroupName "SQLMIJagathRG" `
-InstanceName "sqlmanagedinstancejagath" -Name "AdventureWorks2016" `
-Collation "SQL_Latin1_General_CP1_CI_AS" `
-StorageContainerUri "https://storageaccountsqlmitest.blob.core.windows.net/sqlmibackup/AdventureWorks2016" `
-StorageContainerSasToken "mySASToken"
[view raw](https://gist.github.com/Jagath4u/4a442220da308b74ca218effd6f1a717/raw/bad5d211813aa3ef5a5c1387c262719eed278298/Start%20LRS%20in%20continuous%20mode.ps1) [Start LRS in continuous mode.ps1](https://gist.github.com/Jagath4u/4a442220da308b74ca218effd6f1a717#file-start-lrs-in-continuous-mode-ps1) hosted with ❤ by [GitHub](https://github.com)

Here’s an example of starting LRS in continuous mode by using the Azure CLI:

az sql midb log-replay start -g SQLMIJagathRG --mi sqlmanagedinstancejagath -n AdventureWorks2016
   --storage-uri "https://storageaccountsqlmitest.blob.core.windows.net/sqlmibackup/AdventureWorks2016"
   --storage-sas "mySASToken"

Run LRS as background Job

PowerShell and CLI clients to start LRS in continuous mode are synchronous. This means that clients will wait for the API response to report on success or failure to start the job.

During this wait, the command won’t return control to the command prompt. If you’re scripting the migration experience, and you need the LRS start command to give back control immediately to continue with rest of the script, you can run PowerShell as a background job

with the -AsJob switch. For example:

$lrsjob = Start-AzSqlInstanceDatabaseLogReplay <required parameters> -AsJob

When you start a background job, a job object returns immediately, even if the job takes an extended time to finish. You can continue to work in the session without interruption while the job runs.

Monitor the migration progress

To monitor the progress of the migration through PowerShell, use the following command:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. [Learn more about bidirectional Unicode characters](https://github.co/hiddenchars)
[Show hidden characters](/on-premise-sql-server-to-azure-sql-migration-using-log-replay-service-lrs-part-3-migration/{{ revealButtonHref }})
Get-AzSqlInstanceDatabaseLogReplay -ResourceGroupName "SQLMIJagathRG" `
-InstanceName "sqlmanagedinstancejagath" -Name "AdventureWorks2016"
[view raw](https://gist.github.com/Jagath4u/fee8eaf64a200e18c02045f40db6f193/raw/a654937689a902ef05b291845d24a6b3dffccc37/Monitor%20LRS%20in%20continuous%20mode.ps1) [Monitor LRS in continuous mode.ps1](https://gist.github.com/Jagath4u/fee8eaf64a200e18c02045f40db6f193#file-monitor-lrs-in-continuous-mode-ps1) hosted with ❤ by [GitHub](https://github.com)

To monitor the progress of the migration through the Azure CLI, use the following command:

az sql midb log-replay show -g SQLMIJagathRG --mi sqlmanagedinstancejagath -n AdventureWorks2016

Stop the migration

If you need to stop the migration, use the following cmdlets. Stopping the migration will delete the restoring database on SQL Managed Instance, so resuming the migration won’t be possible.

To stop the migration process through PowerShell, use the following command:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. [Learn more about bidirectional Unicode characters](https://github.co/hiddenchars)
[Show hidden characters](/on-premise-sql-server-to-azure-sql-migration-using-log-replay-service-lrs-part-3-migration/{{ revealButtonHref }})
Stop-AzSqlInstanceDatabaseLogReplay -ResourceGroupName "SQLMIJagathRG" `
-InstanceName "sqlmanagedinstancejagath" -Name "AdventureWorks2016"
[view raw](https://gist.github.com/Jagath4u/67e61e8deee0e873d81b9274d8a70ca8/raw/7dde1c7d3200648c9180a456d8927380bb8cbc2d/Stop%20LRS%20in%20continuous%20mode.ps1) [Stop LRS in continuous mode.ps1](https://gist.github.com/Jagath4u/67e61e8deee0e873d81b9274d8a70ca8#file-stop-lrs-in-continuous-mode-ps1) hosted with ❤ by [GitHub](https://github.com)

To stop the migration process through the Azure CLI, use the following command:

az sql midb log-replay stop -g SQLMIJagathRG --mi sqlmanagedinstancejagath -n AdventureWorks2016

Complete the migration (continuous mode)

If you started LRS in continuous mode, after you’ve ensured that all backups have been restored, initiating the cutover will complete the migration. After the cutover, the database will be migrated and ready for read and write access.

To complete the migration process in LRS continuous mode through PowerShell, use the following command:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. [Learn more about bidirectional Unicode characters](https://github.co/hiddenchars)
[Show hidden characters](/on-premise-sql-server-to-azure-sql-migration-using-log-replay-service-lrs-part-3-migration/{{ revealButtonHref }})
Complete-AzSqlInstanceDatabaseLogReplay -ResourceGroupName "SQLMIJagathRG" `
-InstanceName "sqlmanagedinstancejagath" -Name "AdventureWorks2016" `
-LastBackupName "MY-PF2HM3EY_AdventureWorks2016_LOG_20211219_230104.trn"
[view raw](https://gist.github.com/Jagath4u/a42b20c47ac19230d88c0b39a26d65e5/raw/966c9375bf97c9d3a157d412ff400f365d656d8d/Complete%20LRS%20in%20continuous%20mode.ps1) [Complete LRS in continuous mode.ps1](https://gist.github.com/Jagath4u/a42b20c47ac19230d88c0b39a26d65e5#file-complete-lrs-in-continuous-mode-ps1) hosted with ❤ by [GitHub](https://github.com)

To complete the migration process in LRS continuous mode through the Azure CLI, use the following command:

az sql midb log-replay complete - g SQLMIJagathRG --mi sqlmanagedinstancejagath -n AdventureWorks2016 –last-backup-name "MY-PF2HM3EY_AdventureWorks2016_LOG_20211219_230104.trn"
Jagath Jayaprakash

Jagath Jayaprakash

ITO Service Delivery Consultant III at DXC Technology


Disclaimer: Views expressed in articles are those of the respective authors and do not necessarily reflect the views of their employers or this site. While we aim for accuracy, please verify information before relying on it, and let us know if you spot an error.
Share:

Related Posts

Snowflake Vs Microsoft Azure: 6 Major Differences

Snowflake Vs Microsoft Azure: 6 Major Differences

Most organizations and companies are switching to cloud computing technology. Snowflake and Azure cloud computing-based technology are being very …

Kubernetes vs OpenShift – 15 Facts You Should Know

Kubernetes vs OpenShift – 15 Facts You Should Know

Kubernetes is an opensource project and OpenShift is an enterprise opensource product; more like an engine vs car.

Build your own Multi-node Kubernetes Cluster with Ubuntu(20) on VirtualBox

Build your own Multi-node Kubernetes Cluster with Ubuntu(20) on VirtualBox

Typically Minikube is a utility that most developers use when they are learning Kubernetese. Though it’s a great tool, Minikube runs a single-node …

Connecting remote worker nodes to self-managed Kubernetes cluster via Azure P2S VPN connection

Connecting remote worker nodes to self-managed Kubernetes cluster via Azure P2S VPN connection

Just recently, I was setting up Self-Managed K3s Kubernetes cluster on Azure VM, I had an requirement to include worker nodes from my home network...

Installing oVirt 4 with Self-Hosted Engine on Enterprise Linux

Installing oVirt 4 with Self-Hosted Engine on Enterprise Linux

oVirt is one of the best free and open-source virtualization solution with enterprise level features. Installing oVirt cluster is simple and straight …

How to Request Resource Quota Increase in Microsoft Azure

How to Request Resource Quota Increase in Microsoft Azure

As we know public cloud is offering unlimited* amount of resources and as an end user of public cloud we don’t need to worry about...