This topic describes how to migrate data from an ApsaraDB for MongoDB replica set instance to an ApsaraDB for MongoDB sharded cluster instance by using Data Transmission Service (DTS). DTS supports full data migration and incremental data migration. When you migrate data between ApsaraDB for MongoDB instances, you can select both of the supported migration types to ensure service continuity.

Prerequisites

Each shard in the destination sharded cluster instance has sufficient storage space.

Precautions

  • DTS consumes the resources of the source and destination databases during full data migration. This may increase the loads of the database servers. If you migrate a large amount of data or if the server specifications do not meet your requirements, database services may become unavailable. Before you migrate data, evaluate the impact of data migration on the performance of the source and destination databases. We recommend that you migrate data during off-peak hours.
  • If the source and destination ApsaraDB for MongoDB instances have different versions or storage engines, make sure that the versions or storage engines are compatible. For more information, see MongoDB versions and storage engines.

Billing

Migration type Task configuration fee Internet traffic fee
Full data migration Free of charge. Charged only when data is migrated from Alibaba Cloud over the Internet. For more information, see Pricing.
Incremental data migration Charged. For more information, see Pricing.

Migration types

Migration type Description
Full data migration DTS migrates the historical data of required objects from the source MongoDB database to the destination MongoDB database.
Note The following types of objects are supported: database, collection, and index.
Incremental data migration After full data migration is complete, DTS synchronizes incremental data from the source MongoDB database to the destination MongoDB database.
Note
  • The create and delete operations that are performed on databases, collections, and indexes can be synchronized.
  • The create, delete, and update operations that are performed on documents can be synchronized.

Permissions required for database accounts

Instance Full data migration Incremental data migration
ApsaraDB for MongoDB replica set instance Read permissions on the source database Read permissions on the source database, the admin database, and the local database
ApsaraDB for MongoDB sharded cluster instance Read and write permissions on the destination database Read and write permissions on the destination database
Note For more information about how to create and authorize a database account, see Manage user permissions on MongoDB databases.

Preparations

Create databases and collections to be sharded in the destination ApsaraDB for MongoDB instance, and configure data sharding based on your business requirements. For more information, see Configure sharding to maximize the performance of shards.

Note After you configure sharding for a cluster, the migrated data is distributed among different shards. This maximizes the performance of the sharded cluster.

Procedure

  1. Log on to the ApsaraDB for MongoDB console.
  2. In the left-side navigation pane, click Replica Set Instances.
  3. In the upper-left corner of the page, select the resource group and region to which the instance belongs.
  4. On the page that appears, find the instance that you want to manage and click its ID.
  5. In the upper-right corner of the page that appears, click Migrate Databases.
  6. On the Create Migration Task page, create a migration task.
    1. Configure the source and destination databases.
      Configure the source and destination databases
      Section Parameter Parameter
      N/A Task Name The task name that DTS automatically generates. We recommend that you specify a descriptive name that makes it easy to identify the task. You do not need to specify a unique task name.
      Source Database Instance Type Select ApsaraDB for MongoDB.
      Instance Region The region where the source ApsaraDB for MongoDB instance resides.
      MongoDB Instance ID The ID of the source instance.
      Database Name The name of the authentication database. The database account is created in this database.
      Note If you want to use the root account, enter admin in the Database Name field.
      Database Account The username of the account that is used to connect to the source instance. For information about the permissions that are required for the account, see Permissions required for database accounts.
      Database Password The password of the database account.
      Note After you specify the information about the source database, you can click Test Connectivity next to Database Password to check whether the information is correct. If the information is correct, the Passed message is displayed. If the information is incorrect, the Failed message is displayed and you must click Check next to the Failed message to modify the information.
      Destination Database Instance Type Select MongoDB Instance.
      Instance Region The region where the destination ApsaraDB for MongoDB instance resides.
      MongoDB Instance ID The ID of the destination instance.
      Database Name The name of the authentication database. The database account is created in this database.
      Note If you want to use the root account, enter admin in the Database Name field.
      Database Account The username of the account that is used to connect to the destination instance. For information about the permissions that are required for the account, see Permissions required for database accounts.
      Database Password The password of the database account.
      Note After you specify the information about the destination database, you can click Test Connectivity next to Database Password to check whether the information is correct. If the information is correct, the Passed message appears. If the information is incorrect, the Failed message appears and you must click Check next to the Failed message to modify the information.
    2. In the lower-right corner of the page, click Set Whitelist and Next.
    3. Configure migration types and the objects to migrate.
      Configure migration types and the objects to migrate
      Setting Description
      Select migration types
      • If you want to migrate only the existing data in the source instance, select Full Data Migration.
      • If you want to migrate data without downtime, select Full Data Migration and Incremental Data Migration.
      Note If Incremental Data Migration is not selected, do not write data to the source instance during full data migration. This ensures data consistency between the source instance and destination instance.
      Select objects to migrate The method to select objects to migrate:
      1. Select one or more objects from the Available section.
      2. Click to add the selected objects to the Selected section.
      Note
      • DTS cannot migrate data from the admin or local database.
      • The objects that you can migrate are databases, collections, and functions.
      • By default, after an object is migrated to the destination instance, the name of the object remains unchanged. If you want to rename an object in the destination database, you can use the object name mapping feature. For more information, see Object name mapping.
      Specify whether to rename objects You can use the object name mapping feature to rename the objects that are migrated to the destination instance. For more information, see Object name mapping.
      Specify the retry time range for a failed connection to the source or destination database By default, if DTS fails to connect to the source or destination database, DTS retries within the following 12 hours. You can specify the retry time range based on your business requirements. If DTS is reconnected to the source and destination databases within the specified time range, DTS resumes the data migration task. Otherwise, the data migration task fails.
      Note When DTS retries a connection, you are charged for the DTS instance. We recommend that you specify the retry time range based on your business needs. You can also release the DTS instance at your earliest opportunity after the source and destination instances are released.
    4. In the lower-right corner of the page, click Precheck.
      Note
      • Before you can start the data migration task, DTS performs a precheck. You can start the data migration task only after the task passes the precheck.
      • If the task fails to pass the precheck, you can click the Info icon icon next to each failed item to view details.
        • After you troubleshoot the issues based on the causes, you can run a precheck again.
        • If you do not need to troubleshoot the issues, you can ignore failed items and run a precheck again.
    5. After the data migration task passes the precheck, click Next.
    6. In the Confirm Settings dialog box, configure the Instance Class parameter. Then, read and select Data Transmission Service (Pay-As-You-Go) Service Terms.
    7. Click Buy and Start to start the data migration task.
  7. View the progress of the migration task.
    • Full data migration

      We recommend that you do not manually stop the task during full data migration. Otherwise, the data migrated to the destination database may be incomplete. You can wait until the full data migration task automatically stops.

    • Incremental data migration

      An incremental data migration task does not automatically stop. You must manually stop the task.

    1. Wait until Incremental Data Migration and The data migration task is not delayed appear in the progress bar of the data migration task. Then, stop writing data to the source instance for a few minutes. The latency of incremental data migration may be displayed in the progress bar.
    2. Wait until the state of incremental data migration changes to The migration task is not delayed again. Then, manually stop the migration task.
  8. Switch your workloads to the destination ApsaraDB for MongoDB instance.

What to do next

If you no longer need the source instance, release the source instance.

  • If the source instance is charged based on the pay-as-you-go billing method, you can release the instance. For more information, see Release an instance or a node.
  • If the source instance is charged based on the subscription billing method, you are not allowed to release the instance.