Execute and Troubleshoot Migrations
Implement online and offline migrations to Azure. Migrate between Azure SQL services, use MI database copy and move, and troubleshoot common migration failures.
Executing migrations
Youβve picked your new house and planned the move. Now itβs time to load the truck.
Offline is straightforward: pack everything, drive, unpack, done. Online is trickier β youβre forwarding mail while still living in the old house, then flipping the address at the last moment.
This module covers the actual execution β the tools, the steps, and what to do when things go wrong (because they will).
Offline migration: step by step
To Azure SQL Managed Instance (native backup/restore)
Kenjiβs preferred method for databases with an acceptable downtime window:
- Take a full backup to Azure Blob Storage
BACKUP DATABASE NorthStarERP
TO URL = 'https://northstarstorage.blob.core.windows.net/backups/NorthStarERP.bak'
WITH CREDENTIAL = 'AzureStorageCredential', COMPRESSION;
- Restore on MI
RESTORE DATABASE NorthStarERP
FROM URL = 'https://northstarstorage.blob.core.windows.net/backups/NorthStarERP.bak';
- Validate β check row counts, run application smoke tests
- Redirect applications β update connection strings to MI endpoint
Key requirements:
- Backup must be in Azure Blob Storage (MI canβt restore from local disk)
- Use
CREDENTIALfor storage authentication (SAS token or managed identity) - Backup must be compatible with the MI SQL version
- COPY_ONLY backups recommended to avoid breaking on-prem log chains
To Azure SQL Database (BACPAC)
Priya uses BACPAC for new customer database provisioning:
- Export BACPAC from source (via SSMS, SqlPackage, or Azure Portal)
- Upload to Azure Blob Storage
- Import into Azure SQL Database (via Portal or SqlPackage)
# Export using SqlPackage
SqlPackage /Action:Export /ssn:source-server /sdn:MyDB /tf:MyDB.bacpac
# Import into Azure SQL Database
SqlPackage /Action:Import /tsn:myserver.database.windows.net \
/tdn:MyDB /tu:admin /tp:Password /sf:MyDB.bacpac
BACPAC limitations
BACPAC files include both schema and data β but be aware:
- No incremental sync β itβs a point-in-time snapshot
- Size limit: Import can be slow for databases over 150 GB
- Schema validation on import can fail if unsupported features are used
- For large databases, consider DMS or native backup/restore (to MI) instead
Online migration: step by step
Azure DMS online migration to SQL Database
- Create a DMS instance in the Azure portal
- Create a migration project β specify source (on-prem SQL Server) and target (Azure SQL DB)
- Run pre-migration assessment β validates compatibility
- Start migration β DMS performs initial full data copy
- Continuous sync β DMS tails the transaction log, replicating ongoing changes
- Monitor sync status β check for replication lag in the DMS dashboard
- Cutover β when sync is caught up, stop application writes, wait for final sync, switch connection strings
Log Replay Service (LRS) to Managed Instance
Kenjiβs method for the mission-critical ERP database:
- Configure continuous log backup shipping to Azure Blob Storage
- Start LRS in continuous mode
Start-AzSqlInstanceDatabaseLogReplay -ResourceGroupName "NorthStarRG" `
-InstanceName "northstar-mi" -DatabaseName "NorthStarERP" `
-StorageContainerUri "https://northstarstorage.blob.core.windows.net/logbackups" `
-StorageContainerSasToken "sv=2021-06-08..." `
-AutoComplete
- LRS restores full backup, then continuously restores differential and log backups
- Monitor progress β check restore status, replication lag
- Cutover β take a final log backup, LRS restores it, database comes online
- Redirect applications to MI
LRS auto-complete vs manual complete
- Auto-complete: LRS completes automatically when it detects the last log backup (with
NORECOVERYflag removed). Set the-AutoCompleteflag. - Manual complete: You explicitly trigger the cutover with
Complete-AzSqlInstanceDatabaseLogReplay. Gives more control over timing.
Auto-complete is simpler; manual is safer for mission-critical databases where you want to verify sync status before cutover.
Migrating between Azure SQL services
Sometimes the migration is within Azure β moving from one service to another:
| From β To | Method |
|---|---|
| SQL Database β SQL Database | Database copy, geo-replication, BACPAC |
| SQL Database β Managed Instance | DMS, BACPAC export/import |
| Managed Instance β SQL Database | BACPAC export/import (may lose MI-specific features) |
| Managed Instance β Managed Instance | MI database copy, MI link, native backup/restore |
| SQL VM β Managed Instance | DMS, native backup/restore, LRS |
| SQL VM β SQL Database | DMS, BACPAC |
MI database copy and move
Azure SQL Managed Instance supports database copy and move operations β particularly useful for:
- Moving databases between MIs in different subscriptions or regions
- Creating copies for testing/dev environments
- Disaster recovery setup
Database copy
Creates a copy of a database on the same or different MI:
- Same instance: Quick internal copy
- Cross-instance: Uses managed instance link technology
- The copy is a point-in-time snapshot
- Source database remains online during copy
Database move
Transfers a database from one MI to another:
- Source database is removed after successful transfer
- Works across subscriptions and regions
- Uses Azure Resource Manager for orchestration
Exam tip: copy vs move
The exam distinguishes between copy and move:
- Copy = database exists on BOTH source and target after the operation
- Move = database exists ONLY on the target after the operation (removed from source)
Both operations are initiated through the Azure portal, PowerShell, or CLI β not through T-SQL.
Troubleshooting migrations
Migrations fail. Kenjiβs learned these lessons the hard way:
Common failure patterns
| Problem | Cause | Fix |
|---|---|---|
| Compatibility errors | Source uses features not supported on target | Run DMA assessment first; remediate or choose different target |
| Timeout during import | Large database, slow network, insufficient target tier | Increase target tier temporarily; use native backup instead of BACPAC for large DBs |
| Login/user orphaning | Logins exist on source server but not target | Map orphaned users with ALTER USER ... WITH LOGIN or create new logins |
| Collation mismatch | Source and target have different default collations | Set explicit collation in CREATE DATABASE or use COLLATE in queries |
| Storage credential failures | SAS token expired, wrong permissions, wrong container | Regenerate SAS token with Read/List permissions; verify container path |
| DMS sync lag increasing | Source generating changes faster than DMS can replicate | Increase DMS tier, reduce source write load, check network bandwidth |
| LRS stuck on a log backup | Missing or corrupt log backup file | Check blob storage for gaps in log sequence; re-take the missing backup |
Post-migration validation checklist
- Row counts β compare source and target for all tables
- Checksum validation β verify data integrity
- Schema comparison β objects, indexes, constraints, permissions
- Application testing β run functional tests against the new target
- Performance testing β compare query execution times
- Security validation β logins, users, permissions, encryption status
- Monitoring setup β configure alerts on the new target
Tomas asks Sam: βWhat if the migration fails halfway through?β Sam replies: βThatβs why we always keep the source running until validation is complete. Offline migration? Donβt delete the source for at least two weeks. Online migration? Keep DMS running until youβre confident in the target.β
Kenji migrated a database to Azure SQL MI using native backup/restore. Users report they can't log in. The error says 'user not found.' What is the most likely cause?
Priya needs to move a database from one Azure SQL Managed Instance to another in a different Azure subscription. The source database should not exist after the operation. What should she use?
During an LRS online migration to MI, Tomas notices the restore is stuck and not progressing. What should he check first?
π¬ Video coming soon
Youβve completed Domain 1! You now understand how to choose, deploy, scale, and migrate Azure SQL platforms.
Next up: Entra Authentication for Azure SQL β secure your databases with Microsoft Entra ID authentication.