Azure Database Migration Service is a fully managed service that enables you to migrate your databases to Azure with minimal downtime. It supports various source databases such as SQL Server, Oracle, MySQL, PostgreSQL, and MongoDB, and target databases like Azure SQL Database, Azure SQL Managed Instance, and Azure Database for PostgreSQL.
In this tutorial, we will walk through the steps to migrate a SQL Server database to Azure SQL Database using Azure Database Migration Service (DMS) with CLI commands.
Prerequisites:
- An Azure subscription
- A source SQL Server database and its connection details
- A target Azure SQL Database and its connection details
- Azure CLI installed and logged in
Step 1: Create a migration service The first step is to create a migration service in Azure. To do this, run the following command in the Azure CLI:
az dms create --resource-group <resource-group-name> --name <dms-name> --location <location> --sku-name <sku-name> --subnet <subnet-id> --virtual-subnet-id <virtual-subnet-id>
Where:
<resource-group-name>
is the name of the resource group where you want to create the migration service.<dms-name>
is the name of the migration service.<location>
is the Azure region where you want to create the migration service.<sku-name>
is the pricing tier of the migration service. You can choose fromPremium_4vCores
,Premium_8vCores
, andPremium_16vCores
.<subnet-id>
is the ID of the subnet where you want to create the migration service.<virtual-subnet-id>
is the ID of the virtual subnet where you want to create the migration service.
Step 2: Create a source and target endpoint The next step is to create a source and target endpoint in the migration service. Run the following commands to create endpoints:
# Create a source endpoint
az dms create --resource-group <resource-group-name> --service-name <dms-name> --name <source-endpoint-name> --location <location> --type <source-database-type> --server <source-server-name> --user-name <source-user-name> --password <source-password> --database-name <source-database-name>
# Create a target endpoint
az dms create --resource-group <resource-group-name> --service-name <dms-name> --name <target-endpoint-name> --location <location> --type <target-database-type> --server <target-server-name> --user-name <target-user-name> --password <target-password> --database-name <target-database-name>
Where:
<source-endpoint-name>
is the name of the source endpoint.<source-database-type>
is the type of the source database. In this case, it issqlserver
.<source-server-name>
is the name of the source SQL Server instance.<source-user-name>
is the username to connect to the source database.<source-password>
is the password for the source user.<source-database-name>
is the name of the source database.
Similarly, replace the target endpoint details in the command to create a target endpoint.
Step 3: Create a migration project The next step is to create a migration project. Run the following command to create a migration project:
az dms project create --service-name <dms-name> --resource-group <resource-group-name> --name <project-name> --source-platform <source-database-type> --target-platform <target-database-type> --location
Where:
<project-name>
is the name of the migration project.<source-database-type>
is the type of the source database.<target-database-type>
is the type of the target database.
Step 4: Create a migration task The next step is to create a migration task. Run the following command to create a migration task:
az dms project task create --service-name <dms-name> --resource-group <resource-group-name> --project-name <project-name> --name <task-name> --source-platform <source-database-type> --target-platform <target-database-type> --source-connection-string <source-connection-string> --target-connection-string <target-connection-string>
Where:
<task-name>
is the name of the migration task.<source-connection-string>
is the connection string for the source database. You can get this from the Azure portal or the SQL Server Management Studio.<target-connection-string>
is the connection string for the target database. You can get this from the Azure portal.
Step 5: Start the migration task The final step is to start the migration task. Run the following command to start the migration task:
az dms project task start --service-name <dms-name> --resource-group <resource-group-name> --project-name <project-name> --name <task-name>
Once the migration task starts, it will copy the schema and data from the source database to the target database. You can monitor the progress of the migration task using the Azure portal or the Azure CLI.
Conclusion: In this tutorial, we have seen how to migrate a SQL Server database to Azure SQL Database using Azure Database Migration Service with CLI commands. You can use similar steps to migrate other types of databases to Azure.