This topic describes how to migrate data between ApsaraDB for MongoDB instances of different Alibaba Cloud accounts 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

Precautions

  • DTS consumes the resources of the source and destination instances during full data migration. This may increase the loads of the database servers. If you migrate a large volume of data or the server specifications cannot 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.
  • DTS does not support incremental data migration from a standalone instance. To ensure data consistency, do not write data to the source instance during full data migration.
  • If the source and destination MongoDB databases use different versions or storage engines, make sure that your applications can run on both databases. For more information about the versions and storage engines that are supported by ApsaraDB for MongoDB, see MongoDB versions and storage engines.
  • To ensure better performance and stability of the instance, the system will upgrade the minor version to the latest version by default. If the minor version of your instance expires or is not included in the maintenance list and the instance is upgraded, migrated, changed, Created from a backup, Created by point-in-time, or performed Restore one or more databases of an ApsaraDB for MongoDB instance.

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 for database accounts

Database Full data migration Incremental data migration
Source ApsaraDB for MongoDB instance The read permissions on the source database The read permissions on the source database, the admin database, and the local database
Destination ApsaraDB for MongoDB instance The read and write permissions on the destination database The 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.

Before you begin

  1. Log on to the ApsaraDB for MongoDB console by using the Alibaba Cloud account that owns the source instance.
  2. Apply for a public endpoint for the source instance. For more information, see Apply for a public endpoint.
  3. Add the CIDR blocks of DTS servers to the whitelist of the source instance. For more information, see Configure a whitelist or an ECS security group for an ApsaraDB for MongoDB instance.
    Note You can determine the CIDR blocks you need to add based on the region where the destination instance resides. For more information, see Add the CIDR blocks of DTS servers to the security settings of on-premises databases.

    For example, if the source instance resides in the China (Hangzhou) region and the destination instance resides in the China (Shenzhen) region, you must add the CIDR blocks of DTS servers in the China (Shenzhen) region to the whitelist of the source 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 or Sharded Cluster 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 data migration task.
    1. Configure the source and destination databases.
      MongoDB: Configure the source and destination databases
      Section Parameter Description
      N/A Task Name DTS automatically generates a task name. We recommend that you specify an informative name for easy identification. You do not need to use a unique task name.
      Source Database Instance Type Select User-Created Database with Public IP Address.
      Instance Region Select the region where the source instance resides.
      Database Type Select MongoDB.
      Hostname or IP Address Enter the domain name obtained from the public endpoint of the source instance. For example, enter dds-1udxxxxxxx-pub.mongodb.rds.aliyuncs.com.
      Port Number Enter 3717, which is the service port of the source instance.
      Database Name Enter the name of the authentication database. The database account is created in this database.
      Note If the database account is root, enter admin.
      Database Account Enter the database account of the source ApsaraDB for MongoDB instance. For information about the permissions that are required for the account, see Permissions required for database accounts.
      Database Password Enter the password of the database account.
      Note After you specify the source database parameters, click Test Connectivity next to Database Password to verify whether the specified parameters are valid. If the specified parameters are valid, the Passed message appears. If the Failed message appears, click Check next to Failed. Modify the source database parameters based on the check results.
      Encryption This parameter specifies whether to use an encrypted connection between DTS and the source instance. Select Non-encrypted or SSL-encrypted. If you select SSL-encrypted, you must enable SSL encryption for the source instance before you configure the data migration task.
      Note
      • You can select SSL-encrypted only for MongoDB Atlas databases.
      • If you select SSL-encrypted, more CPU resources will be consumed.
      Destination Database Instance Type Select MongoDB Instance.
      Instance Region Select the region where the destination ApsaraDB for MongoDB instance resides.
      MongoDB Instance ID Select the ID of the destination ApsaraDB for MongoDB instance.
      Database Name Enter the name of the authentication database. The database account is created in this database.
      Note If the database account is root, enter admin.
      Database Account Enter the database account of the destination ApsaraDB for MongoDB instance. For information about the permissions that are required for the account, see Permissions required for database accounts.
      Database Password Enter the password of the database account.
      Note After you specify the destination database parameters, click Test Connectivity next to Database Password to verify whether the specified parameters are valid. If the specified parameters are valid, the Passed message appears. If the Failed message appears, click Check next to Failed. Modify the destination database parameters based on the check results.
    2. In the lower-right corner of the page, click Set Whitelist and Next.
      Note After data is migrated, you can remove the CIDR blocks of DTS servers from the whitelist of the source instance if they are no longer needed. For more information, see Configure a whitelist for an ApsaraDB for MongoDB instance.
    3. Select the migration types and the objects to be migrated.
      Select the migration types and the objects to be migrated
      Setting Description
      Select the migration types To ensure data consistency, we recommend that you select both Full Data Migration and Incremental Data Migration.

      If you select only Full Data Migration, the data updated during the migration process may not be migrated from the source instance to the destination instance.

      If you select only Incremental Data Migration, take note of the following information:
      Note
      • DTS does not support incremental data migration for standalone instances.
      • If Incremental Data Migration is not selected, we recommend that you do not write data to the source instance during full data migration. This ensures data consistency between the source and destination instances.
      Select the objects to be migrated
      1. Select one or more objects from the Available section.
      2. Click the icon to move the objects to the Selected section.
      Note
      • DTS cannot migrate data from the admin or local database.
      • You can select databases, collections, or functions as the objects to be migrated.
      • By default, after an object is migrated to the destination instance, the name of the object remains unchanged. 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 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 for failed connections to the source or destination database By default, if DTS fails to connect to the source or destination database, DTS retries within the next 12 hours. You can specify the retry time based on your needs. If DTS reconnects to the source and destination databases within the specified time, 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 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. 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 instance or a node.
  • If the source instance is charged based on the subscription billing method, you cannot release the source instance.

References

If you migrate data to a sharded cluster instance, you can configure data sharding based on your needs. For more information, see Configure sharding to maximize the performance of shards.