This topic describes how to migrate data from a replica set instance to a sharded cluster instance by using Data Transmission Service (DTS). DTS supports both full data migration and incremental data migration. You can use these two types of migration together to migrate data between ApsaraDB for MongoDB instances without downtime.

Prerequisites

The available storage space on the shard nodes of the destination instance is sufficient to store the data that is migrated from the source instance.

Precautions

  • DTS uses specific resources of the source instance and destination instance during the full data migration process. This may increase the loads of the physical hosts on which these instances are deployed. If the data volume is large or the specifications of the physical hosts do not meet your requirements, the source instance and destination instance may become unavailable. We recommend that you migrate data during off-peak hours to prevent interruptions to your workloads.
  • If the source instance and destination instance run different database engine versions or different storage engines, make sure that the database engine version or storage engine of the source instance is compatible with the database engine version or storage engine of the destination instance. For more information, see MongoDB versions and storage engines.

Billing

Migration type Task configuration Internet traffic
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 All existing data in the source instance is migrated to the destination instance.
Note Full data migration is supported for databases, collections, and indexes.
Incremental data migration Only the incremental data in the source instance is migrated to the destination instance.
Note
  • Incremental data migration can be used to synchronize the create and delete operations that are performed on databases, collections, and indexes.
  • Incremental data migration can be used to synchronize the create, delete, and update operations that are performed on documents.

Permissions required

Instance Full data migration Incremental data migration
Source instance Read permissions on the source database Read permissions on the source database, the database named admin, and the database named local
Destination 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 accounts on an ApsaraDB for MongoDB instance, see Manage user permissions on MongoDB databases.

Preparations

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

Note After you configure data sharding for the destination instance, the data that is migrated from the source instance is distributed among different shard nodes. This maximizes the performance of the destination instance.

Procedure

  1. Log on to the ApsaraDB for MongoDB console.
  2. In the upper-left corner of the page, select the resource group and the region of the target instance.
  3. In the left-side navigation pane, click Replica Set Instances.
  4. Find the target instance 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. Specify the information about the source database and destination database.
      Configure the source database and destination database
      Section Parameter Description
      N/A Task Name DTS automatically generates a task name. We recommend that you specify an informative name that helps identify the migration task. The task name does not need to be unique.
      Source Database Instance Type Select ApsaraDB for MongoDB.
      Instance Region Select the region where the source instance resides.
      MongoDB Instance ID Select the ID of the source instance.
      Database Name Enter the name of the source database. The permissions on the source database must be granted to the account that is used to connect to the source instance.
      Note If you want to use the root account, enter admin in the Database Name field.
      Database Account Enter the username of the account that is used to connect to the source instance. For more information about the permissions that are required for the account, see Permissions required.
      Database Password Enter the password of the account that is used to connect to the source instance.
      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 appears. If the information is incorrect, the Failed message appears and you must click Check next to the Failed message to modify the information.
      Destination Database Instance Type Select MongoDB Instance.
      Instance Region Select the region where the destination instance resides.
      MongoDB Instance ID Select the ID of the destination instance.
      Database Name Enter the name of the destination database. The permissions on the destination database must be granted to the account that is used to connect to the destination instance.
      Note If you want to use the root account, enter admin in the Database Name field.
      Database Account Enter the username of the account that is used to connect to the destination instance. For more information about the permissions that are required for the account, see Permissions required.
      Database Password Enter the password of the account that is used to connect to the destination instance.
      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.
      Note DTS automatically creates IP address whitelists on the source instance and destination instance. The created IP address whitelists contain the IP address of the DTS server. This ensures that the DTS server can communicate with the source instance and destination instance. After the data of the source instance is migrated to the destination instance, you can delete these IP address whitelists. For more information, see Configure a whitelist for a sharded cluster instance.
    3. Specify the migration types and the objects that you want to migrate.
      Migration types and objects
      Action Description
      Specify the 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 the full data migration process. This ensures data consistency between the source instance and destination instance.
      Specify the objects that you want to migrate
      1. Select one or more objects from the Available section.
      2. Click to move the selected objects to the Selected section.
      Note
      • Data in the database named admin and the database named local cannot be migrated.
      • 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 an object to have a different name after the migration, you can use the object name mapping feature of DTS to rename the object. For more information, see Object name mapping.
      Specify whether to rename objects You can use the object name mapping feature of DTS to rename the objects that you want to migrate. For more information, see Object name mapping.
      Specify the retry time for a failed connection to the source instance or destination instance By default, if DTS fails to connect to the source instance or destination instance, DTS retries to establish a connection within the next 12 hours. You can specify the retry time based on your business requirements. If DTS reconnects to the source instance and destination instance within the specified period of time, DTS resumes the migration task. If DTS cannot reconnect to the source instance or destination instance within the specified period of time, the migration task fails.
      Note When DTS retries to establish a connection, you are charged for the migration task. We recommend that you specify the retry time based on your business requirements. After the source instance and destination instance are released, we recommend that you release the migration task at your earliest opportunity.
    4. After you configure the preceding parameters, click Precheck in the lower-right corner of the page.
      Note
      • Before the migration task starts, you must perform a precheck. The migration task can be started only after it passes the precheck.
      • If the migration task fails the precheck, you can click the Info icon icon next to each failed item to view details about the failure.
        • You can troubleshoot the failures based on the information that is displayed. Then, you can perform a precheck again.
        • If you do not need to troubleshoot the failures, you can ignore the failed items and perform a precheck again.
    5. After the migration task passes the precheck, click Next.
    6. In the Confirm Settings dialog box, specify the Channel Specification parameter, and read and select Data Transmission Service (Pay-As-You-Go) Service Terms.
    7. Click Buy and Start to start the migration task.
  7. View the progress of the migration task.
    • Full data migration

      Do not manually stop a migration task. If you manually stop a migration task, the data that is migrated to the destination instance may be incomplete. You need only to wait until the migration task is completed and automatically stops.

    • Incremental data migration

      The migration task does not automatically stop. You must manually stop the migration task.

    1. Wait until Incremental Data Migration and The migration task is not delayed appear in the progress bar of the migration task. Then, stop data writes to the source database for a few minutes. The delay of Incremental Data Migration may be displayed in the progress bar.
    2. When the status of Incremental Data Migration changes to The migration task is not delayed, manually stop the migration task.
  8. Switch your workloads over to the destination 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 source instance. For more information, see Release an ApsaraDB for MongoDB instance.
  • If the source instance is charged based on the subscription billing method, you cannot release the source instance.