All Products
Search
Document Center

ApsaraDB for MongoDB:Migrate data between ApsaraDB for MongoDB instances of different Alibaba Cloud accounts

更新時間:Sep 08, 2024

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

Usage notes

  • DTS uses the resources of the source and destination databases during a full data migration. This may increase the loads on the database servers. If you migrate a large volume of data or the server specifications cannot meet your business requirements, database services may become unavailable. Before you migrate data, evaluate the impact of data migration on the performance of the source and destination instances. 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 the full data migration process.

  • If the source self-managed MongoDB database and the destination instance run different database versions or storage engines, make sure that no compatibility issues occur between them before you start migration. For more information about the database versions and storage engines supported by ApsaraDB for MongoDB, see MongoDB versions and storage engines.

  • By default, a new instance runs the latest minor version. This ensures high performance and stability.

  • The data is concurrently written to the destination instance. Therefore, the storage capacity occupied in the destination instance is 5% to 10% larger than the storage capacity occupied in the source instance.

  • Make sure that the destination instance does not have the same primary key as that in the source instance. The default primary key is _id. Otherwise, data may be lost. If the source and destination instances have the same primary key, delete the corresponding document in the destination instance without interrupting your business services.

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 Billing overview.

Incremental data migration

Charged. For more information, see Billing overview.

Migration types

Migration type

Description

Full data migration

DTS migrates the existing data of 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 migrates 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 migrated.

  • The create, delete, and update operations that are performed on documents can be migrated.

Permissions required for database accounts

Database

Full data migration

Incremental data migration

Source ApsaraDB for MongoDB instance

Read permissions on the source database

Read permissions on the source, admin, and local databases

Destination ApsaraDB for MongoDB 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 a database account and grant permissions to the database account, see Manage user permissions on MongoDB databases.

Preparations

  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 Modify an IP address whitelist of an ApsaraDB for MongoDB instance.

    Note

    You can determine the CIDR blocks you need to add based on the region in which the destination instance resides. For more information, see Add the CIDR blocks of DTS servers.

    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 left-side navigation pane, click Replica Set Instances or Sharded Cluster Instances based on the instance type.

  3. In the upper-left corner of the page, select the resource group and region to which the instance belongs.

  4. Click the ID of an instance, or click More icon in the Actions column corresponding to the instance and select Manage.

  5. In the upper-right corner of the instance details page, click Migrate Database.

  6. On the Create Migration Task page, create a data migration task.

    1. Configure the source and destination databases.

      Configure the source and destination databases

      Section

      Parameter

      Description

      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

      The instance type of the source database. In this example, User-Created Database with Public IP Address is selected.

      Instance Region

      The region in which the source instance resides.

      Database Type

      The type of the source database. Select MongoDB.

      Hostname or IP Address

      The domain name obtained from the public endpoint of the source instance. Example: dds-bp1b47357f218e74****-pub.mongodb.rds.aliyuncs.com.

      Port Number

      The service port of the source instance. In this example, 3717 is used.

      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. Otherwise, the Failed message is displayed and you must click Check next to the Failed message to modify the information.

      Encryption

      Specifies whether to encrypt the connection. Select Non-encrypted or SSL-encrypted based on your business requirements. 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 are consumed.

      Destination Database

      Instance Type

      The instance type of the destination database. Select MongoDB Instance.

      Instance Region

      The region in which 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 is displayed. Otherwise, the Failed message is displayed 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.

      Warning

      If the CIDR blocks of DTS servers are automatically or manually added to the whitelist of the database or instance, or to the ECS security group rules, security risks may arise. Therefore, before you use DTS to migrate data, you must understand and acknowledge the potential risks and take preventive measures, including but not limited to the following measures: enhance the security of your username and password, limit the ports that are exposed, authenticate API calls, regularly check the whitelist or ECS security group rules and forbid unauthorized CIDR blocks, or connect the database to DTS by using Express Connect, VPN Gateway, or Smart Access Gateway.

    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 full data migration may not be migrated from the source instance to the destination instance.

      If you select only Incremental Data Migration, take note of the following items:

      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

      To select the objects to be migrated, perform the following steps:

      1. Select one or more objects from the Available section.

      2. Click the icon to add the 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 instance, 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 failed connections to the source or destination database

      By default, if DTS fails to connect to the source and destination databases, DTS retries within the next 12 hours. You can specify the retry time range based on your business requirements. If DTS reconnects to the source and destination databases within the specified retry time range, DTS resumes the data migration task. Otherwise, the data migration task fails.

      Note

      Within the time range in which DTS attempts to reconnect to the source and destination databases, you are charged for the DTS instance. We recommend that you specify the retry time range based on your business requirements. You can also release the DTS instance at the earliest opportunity after the source and destination databases 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, click View Details next to each failed item. After you analyze the causes based on the check results, troubleshoot the issues. Then, run a precheck again.

      • If an alert is triggered for an item during the precheck:

        • If an alert item cannot be ignored, click View Details next to the failed item and troubleshoot the issues. Then, run a precheck again.

        • If the alert item can be ignored, click Confirm Alert Details. In the View Details dialog box, click Ignore. In the message that appears, click OK. Then, click Precheck Again to run a precheck again. If you ignore the alert item, data inconsistency may occur, and your business may be exposed to potential risks.

    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 the check box to agree to 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 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 status 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 billed based on the pay-as-you-go billing method, you can release the instance. For more information, see Release an ApsaraDB for MongoDB instance.

  • If the source instance is billed based on the subscription billing method, you are not allowed to release the instance.

References

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