Sql-server – Migrate on-premise SQL Server databases to Azure SQL Database

azure-sql-databasemigrationsql serversql-server-2008

We're in the process of a server migration from an on-premise server (Win2008R2) to Azure PaaS.

To move the databases, we used the Microsoft Data Migration Assistant (DMA) tool, which worked great and we can connect to the migrated Azure DB via SQL Server Management Studio.

Considering:

  • Made quite a few changes to the migrated Azure database (tables, SPs, indexes) to work with the apps in Azure
  • Combined multiple DBs from the on-prem server into one DB in Azure via DMA to save costs
  • One on-premise database is continually being modified by insert and update operations (multiple tables) during the migration process
  • When fully switching hosting in Azure we need to make sure all data is up-to-date. This will be done very early in the AM during which on-prem IIS websites are stopped assuring no DB operations are made, giving us a short window to migrate missing data

Question: What is the best and fastest way to migrate data (all vs missing/updated) considering the above?

Can this be achieved by following the below steps?

  1. Create a new empty Azure SQL database (to later hold all the tables of 5 on-prem databases)
  2. Via Microsoft Data Migration Assistant (DMA), migrate only the schema of that one on-prem database which is continually being modified by insert/update operations
  3. Via SQL Data Sync Agent, set up auto data sync (e.g. every 30 minutes) between the on-prem and Azure database
  4. After data sync up and running, via Microsoft Data Migration Assistant (DMA)– migrate schema and data of the rest of the on-prem databases (no data changes during migration process) into the single Azure database previously created and used for syncing

EDIT:

After enabling Data Sync in the Azure portal, the sync was unsuccessful due to the below logged errors:

  1. Member Database: MyAzureDb -> Tombstone cleanup failed with the exception "SqlException Error Code: -2146232060 – SqlError Number:18456, Message: Login failed.
  2. Member Database: MyAzureDb -> Database provisioning failed with the exception "SqlException Error Code: -2146232060 – SqlError Number:18456, Message: Login failed.

To fix 1 and 2 above tried: ALTER ROLE DataSync_executor ADD MEMBER [myUser];
but got Cannot add the principal 'myUser', because it does not exist or you do not have permission.

  1. Member Database:MyOnPremDb: -> Database provisioning failed with the exception "SqlException Error Code: -2146232060 – SqlError Number:325, Message: Incorrect syntax near 'MERGE'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the SET COMPATIBILITY_LEVEL option of ALTER DATABASE. SqlError Number:156, Message: Incorrect syntax near the keyword 'AS'.

The current compatibility level of the on-premise database is 80. Not sure what impact setting it to 100 will have to the production databse/apps.

Best Answer

I would recommend you to migrate first only the schema of your on-premises databases to Azure SQL Databases and then let Azure SQL Data Sync to migrate the data to Azure and keep it updated on Azure SQL Database.

My suggestion to start with an empty schema on the Azure SQL Database side is because when SQL data Sync finds data on-premises and on Azure it start comparing both databases and that consumes a lot of resources.

On the initial sync SQL Data Sync may consume a lot of resources on the on-premises database server even when having an empty schema on the Azure side, for that you can use SQL Server Resource Governor to cap the CPU used by the data sync sessions in your on premises SQL Server, and this way avoid big performance impact possibly affecting database users.

When you are ready, you can switch your users (gradually or not if SQL Data Sync is on bi-directional mode) to Azure. Once your users have been migrated, you can then remove the member database (the on-premises database) from the SQL Data Sync configuration and stop SQL Data Sync operation.