This page describes how to create a migration job for Cloud SQL for SQL Server sources with Google Cloud CLI. For more information about migrating between Cloud SQL for SQL Server instances with Database Migration Service, see Migration guide for Cloud SQL for SQL Server sources.
Before you begin
- Ensure you meet the following requirements:
- You have a Cloud Storage bucket for SQL Server backup files.
- You have a source connection profile for your source instance.
- You created and configured your destination Cloud SQL for SQL Server instance, and you have a destination connection profile for the instance.
- In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
- Enable the Database Migration Service, Compute Engine, Cloud Storage, and Cloud SQL Admin APIs.
Required roles
To get the permissions that you need to create migration jobs in Database Migration Service, ask your administrator to grant you the following IAM roles on your project:
-
Database Migration Admin (
roles/datamigration.admin) -
Storage Admin (
roles/storage.admin) -
Cloud SQL Editor (
roles/cloudsql.editor)
For more information about granting roles, see Manage access.
These predefined roles contain the permissions required to perform homogeneous SQL Server migrations with Database Migration Service. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to perform homogeneous SQL Server migrations with Database Migration Service:
datamigration.*resourcemanager.projects.getresourcemanager.projects.listcloudsql.instances.createcloudsql.instances.getcloudsql.instances.listcloudsql.databases.getcloudsql.databases.deletecloudsql.operations.getcompute.machineTypes.listcompute.machineTypes.getcompute.projects.getstorage.buckets.createstorage.buckets.liststorage.objects.list
You might also be able to get these permissions with custom roles or other predefined roles.
Define settings and create a migration job
gcloud
This sample uses the optional --no-async flag so that all operations
are performed synchronously. This means that some commands might take
a while to complete. You can skip the --no-async flag to run commands asynchronously.
If you do, you need to use the
gcloud database-migration operations describe
command to verify if your operation is successful.
Before using any of the command data below, make the following replacements:
- MIGRATION_JOB_ID with a machine-readable identifier for your migration job. You use this value to work with migration jobs by using Database Migration Service Google Cloud CLI commands or API.
- REGION with the region identifier where you want to save the migration job.
- MIGRATION_JOB_NAME with a human-readable name for your migration job. This value is displayed in Database Migration Service in the Google Cloud console.
- SOURCE_CONNECTION_PROFILE_ID with a machine-readable identifier of the source connection profile.
- DESTINATION_CONNECTION_PROFILE_ID with a machine-readable identifier of the destination connection profile.
- DESTINATION_PROJECT_ID with the Google Cloud project identifier where you have your destination Cloud SQL for SQL Server instance. This must be the same project where you have your Database Migration Service API enabled and where you create the migration job.
- COMMA_SEPARATED_DATABASE_ID_LIST with a comma-separated list of database identifiers of the SQL Server you want to migrate from your backup files.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud database-migration migration-jobs \ create MIGRATION_JOB_ID \ --no-async \ --region=REGION \ --display-name=MIGRATION_JOB_NAME \ --source=SOURCE_CONNECTION_PROFILE_ID \ --destination=DESTINATION_CONNECTION_PROFILE_ID \ --sqlserver-databases=COMMA_SEPARATED_DATABASE_ID_LIST \ --project=DESTINATION_PROJECT_ID \ --type=CONTINUOUS
Windows (PowerShell)
gcloud database-migration migration-jobs ` create MIGRATION_JOB_ID ` --no-async ` --region=REGION ` --display-name=MIGRATION_JOB_NAME ` --source=SOURCE_CONNECTION_PROFILE_ID ` --destination=DESTINATION_CONNECTION_PROFILE_ID ` --sqlserver-databases=COMMA_SEPARATED_DATABASE_ID_LIST ` --project=DESTINATION_PROJECT_ID ` --type=CONTINUOUS
Windows (cmd.exe)
gcloud database-migration migration-jobs ^ create MIGRATION_JOB_ID ^ --no-async ^ --region=REGION ^ --display-name=MIGRATION_JOB_NAME ^ --source=SOURCE_CONNECTION_PROFILE_ID ^ --destination=DESTINATION_CONNECTION_PROFILE_ID ^ --sqlserver-databases=COMMA_SEPARATED_DATABASE_ID_LIST ^ --project=DESTINATION_PROJECT_ID ^ --type=CONTINUOUS
You should receive a response similar to the following:
Waiting for migration job [MIGRATION_JOB_ID] to be created with [OPERATION_ID] Waiting for operation [OPERATION_ID] to complete...done. Created migration job MIGRATION_JOB_ID [OPERATION_ID]
The migration job is now created. You can proceed with the migration process:
- (Optional) Perform a migration job test to check if Database Migration Service can reach all the necessary source and destination entities.
- Start the migration job to begin moving your data to the destination instance.