Use DTS to incrementally migrate data from a Tencent Cloud MongoDB replica set instance to Alibaba Cloud

Updated at:

This topic describes how to use Data Transmission Service (DTS) to incrementally migrate data from a Tencent Cloud MongoDB replica set instance to Alibaba Cloud. DTS supports full and incremental data migration. You can use both migration types to migrate your Tencent Cloud MongoDB database without service interruptions.

Background information

You can use DTS to migrate your database for business adjustments or to use the features of Alibaba Cloud MongoDB. This topic describes how to use the incremental data migration method to migrate a Tencent Cloud MongoDB V3.6 replica set instance to an Alibaba Cloud MongoDB instance.

Prerequisites

  • The Tencent Cloud MongoDB replica set instance runs on version 3.6.

    Note

    For information about how to migrate Tencent Cloud MongoDB V3.2 replica set and sharded cluster instances, see Use MongoDB tools to migrate Tencent Cloud MongoDB to Alibaba Cloud.

  • An Alibaba Cloud MongoDB instance is created. If you have not created one, see Create a replica set instance or Create a sharded cluster instance.

    Note

    The storage space of the destination Alibaba Cloud MongoDB instance must be at least 10% larger than the used storage space of the source Tencent Cloud MongoDB replica set instance. If the storage space of the destination instance is insufficient, you can upgrade its storage space. For more information, see Change instance configurations.

  • If you migrate data to an Alibaba Cloud MongoDB sharded cluster instance, you must partition the data to achieve optimal performance. For more information, see Configure data partitioning.

Precautions

  • DTS consumes resources from the source and destination databases during full data migration, which may increase the load on your database servers. If your database has heavy traffic or low server specifications, the database may become unavailable. Before you migrate data, evaluate the impact on your services. We recommend that you migrate data during off-peak hours.

  • DTS automatically resumes a failed task. Before you switch your business to the destination instance, you must end or release the task. This prevents the task from being automatically resumed, which can cause data in the destination instance to be overwritten by data from the source instance.

  • The admin and local databases cannot be migrated.

  • For more information about the versions and storage engines supported by Alibaba Cloud MongoDB, see Versions and storage engines. If you migrate data across different versions or storage engines, you must check the compatibility in advance.

  • Because DTS writes data concurrently, the storage space used by the destination database is 5% to 10% larger than that of the source database.

  • Ensure that the destination MongoDB instance does not have documents with the same primary key (the default is _id) as the source instance. Otherwise, data loss may occur. If the destination instance has documents with the same primary key as the source instance, you must clear the relevant data in the destination instance without affecting your services. For example, you can delete the documents that have the same _id as the source.

  • If the source MongoDB is a sharded cluster instance, the number of source Mongos nodes cannot exceed 10.

Billing information

Migration Types Instance configurations Internet traffic
Full data migration Free of charge Free of charge
Incremental data migration Charged, For more information, see Data Transmission Service (DTS) pricing. Free of charge

Migration type description

  • Full data migration: All data of the migration objects is migrated from the source instance to the destination instance..
    Note Data migration is supported at the database, collection, and index levels.
  • Incremental data migration: Updated data of the migration objects is synchronized from the source instance to the destination instance..
    Note
    • The create and delete operations for databases, collections, and indexes can be synchronized.
    • The create, delete, and update operations on documents can be synchronized.

Required database account permissions

Instance Type

Full data migration

Incremental data migration

Tencent Cloud MongoDB replica set instance

read permission on the databases to be migrated

read permission on the databases to be migrated, the admin database, and the local database

Alibaba Cloud MongoDB instance

readWrite permission on the destination database

readWrite permission on the destination database

Pre-migration preparations

Tencent Cloud MongoDB instances provide only internal endpoints and do not have public endpoints. To migrate data, you must create a Tencent Cloud server with a public IP address to forward port data. After the migration is complete, you can release the Tencent Cloud server if you no longer need it.

  1. Create a Tencent Cloud server. This topic uses a Tencent Cloud server that runs a Linux operating system as an example.

    Note

    To ensure proper communication between the Tencent Cloud server and the Tencent Cloud MongoDB replica set instance, the region, zone, VPC, and subnet of the server must be the same as those of the instance.

  2. Go to the Tencent Cloud server console to view the internal and public IP addresses of the server.

  3. Go to the Tencent Cloud MongoDB console to view the internal IP address of the Tencent Cloud MongoDB replica set instance.

  4. Log on to the Tencent Cloud server and run the following command to start the iptables service. If the service is already running, skip this step.

    service iptables start
  5. Run the following command to set iptables rules to map port 27017.

    iptables -t nat -A PREROUTING -d <CVM_IP>  -p tcp --dport 27017 -j DNAT --to-destination <MongoDB_IP>:27017
    iptables -t nat -A POSTROUTING -d <MongoDB_IP> -p tcp --dport 27017 -j SNAT --to-source <CVM_IP>
    Note
    • <CVM_IP>: the internal IP address of the Tencent Cloud server.

    • <MongoDB_IP>: the internal IP address of the Tencent Cloud MongoDB replica set instance.

    Example:

    iptables -t nat -A PREROUTING -d 10.10.0.5  -p tcp --dport 27017 -j DNAT --to-destination 10.10.0.7:27017
    iptables -t nat -A POSTROUTING -d 10.10.0.7 -p tcp --dport 27017 -j SNAT --to-source 10.10.0.5
  6. You can enable routing and forwarding on the Tencent Cloud server.

    echo 1 > /proc/sys/net/ipv4/ip_forward
  7. Return to the Tencent Cloud server console. In the navigation pane on the left, click Security Groups.

  8. On the Inbound Rules tab, click Add Rule to allow access from the internet to MongoDB port 27017.

  9. Go to the Tencent Cloud MongoDB console and click the name of the destination MongoDB instance.

  10. Click the Security Group tab and then click Configure Security Group.

  11. In the Configure Security Group dialog box, select the security group in which port 27017 is enabled and click OK.

Procedure (New console)

  1. Navigate to the migration task list page for the destination region using one of the following methods.

    From the DTS console

    1. Log on to the Data Transmission Service (DTS) console.

    2. In the navigation pane on the left, click Data Migration.

    3. In the upper-left corner of the page, select the region where the migration instance is located.

    From the DMS console

    Note

    The actual operations may vary based on the mode and layout of the DMS console. For more information, see Simple mode console and Customize the layout and style of the DMS console.

    1. Log on to the Data Management (DMS) console.

    2. In the top menu bar, choose Data + AI > Data Transmission (DTS) > Data Migration.

    3. To the right of Data Migration Tasks, select the region where the migration instance is located.

  2. Click Create Task to navigate to the task configuration page.

  3. Configure the source and destination databases.

    Warning

    After you select the source and destination instances, we recommend that you carefully read the limits displayed at the top of the page. Otherwise, the task may fail or data inconsistency may occur.

    Category

    Configuration

    Description

    None

    Task Name

    DTS automatically generates a task name. We recommend that you specify a descriptive name for easy identification. The name does not need to be unique.

    Source Database

    Select Existing Connection

    • To use a database instance that has been added to the system (created or saved), select the desired database instance from the drop-down list. The database information below will be automatically configured.

      Note

      In the DMS console, this parameter is named Select a DMS database instance..

    • If you have not registered the database instance with the system, or do not need to use a registered instance, manually configure the database information below.

    Database Type

    Select MongoDB.

    Connection Type

    Select Public IP.

    Instance Region

    Select the region where the Tencent Cloud MongoDB database resides.

    Note

    If the region of the Tencent Cloud MongoDB database is not available, you can select the region that is geographically closest to the database.

    Architecture

    Select Replica Set.

    Domain Name or IP

    Enter the public IP address of the Tencent Cloud MongoDB database server.

    Note

    You can configure security group rules as described in Preparations. You can also click Get DTS IP Segments next to the Instance Region parameter to obtain the IP addresses of the DTS servers. Then, add the obtained IP addresses to the security group rules of the Tencent Cloud MongoDB replica set instance.

    Port

    Enter the port number of the Tencent Cloud MongoDB database. In this example, enter 27017.

    Authentication Database Name

    Enter the name of the authentication database. The default value is admin.

    Database Account

    Enter the account used to log on to the Tencent Cloud MongoDB database. The default value is mongouser. For information about the required permissions, see Required database account permissions.

    Database Password

    Enter the password for the Tencent Cloud MongoDB database account.

    Connection Method

    Select Unencrypted Connection.

    Destination Database

    Select Existing Connection

    • To use a database instance that has been added to the system (created or saved), select the desired database instance from the drop-down list. The database information below will be automatically configured.

      Note

      In the DMS console, this parameter is named Select a DMS database instance..

    • If you have not registered the database instance with the system, or do not need to use a registered instance, manually configure the database information below.

    Database Type

    Select MongoDB.

    Connection Type

    Select Cloud Instance.

    Instance Region

    Select the region where the destination Alibaba Cloud MongoDB instance resides.

    Architecture Type

    Select an architecture based on your business needs. Valid values:

    • Replica Set: Deploys multiple nodes to achieve high availability and read/write splitting. For more information, see Replica set architecture.

    • Sharded Cluster: Provides three components: Mongos, Shard, and ConfigServer. You can select the number and configurations of Mongos and Shard nodes. For more information, see Sharded cluster architecture.

    Instance ID

    Select the ID of the destination Alibaba Cloud MongoDB instance.

    Authentication Database Name

    Enter the name of the authentication database. The default value is admin.

    Database Account

    Enter the database account of the destination Alibaba Cloud MongoDB instance. For information about the required permissions, see Required database account permissions.

    Database Password

    Enter the password for the database account.

  4. After you complete the configuration, click Test Connectivity and Proceed at the bottom of the page.

    Note
    • Ensure that the IP address segment of the DTS service is automatically or manually added to the security settings of the source and destination databases to allow access from DTS servers. For more information, see Add DTS server IP addresses to a whitelist.

    • If the source or destination database is a self-managed database (the Access Method is not Alibaba Cloud Instance), you must also click Test Connectivity in the CIDR Blocks of DTS Servers dialog box that appears.

  5. Configure the task objects.

    1. On the Configure Objects page, configure the objects that you want to migrate.

      Configuration

      Description

      Migration Types

      • If you only need to perform a full migration, select both Schema Migration and Full Data Migration.

      • To perform a migration with no downtime, select Schema Migration, Full Data Migration, and Incremental Data Migration.

      Note
      • If you do not select Schema Migration, you must ensure that a database and tables to receive the data exist in the destination database. You can also use the object name mapping feature in the Selected Objects box as needed.

      • If you do not select Incremental Data Migration, do not write new data to the source instance during data migration to ensure data consistency.

      Processing Mode of Conflicting Tables

      • Precheck and Report Errors: checks whether the destination database contains collections that have the same names as collections in the source database. If the source and destination databases do not contain collections that have identical collection names, the precheck is passed. Otherwise, an error is returned during the precheck and the data synchronization task cannot be started.
        Note You can use the object name mapping feature to rename the collections that are synchronized to the destination database. You can use this feature if the source and destination databases contain identical collection names and the collections in the destination database cannot be deleted or renamed. For more information, see Set object names in the destination instance.
      • Ignore Errors and Proceed: skips the precheck for identical collection names in the source and destination databases.
        Warning If you select Ignore Errors and Proceed, data inconsistency may occur, and your business may be exposed to potential risks.
        • DTS does not synchronize data records that have the same primary key values as data records in the destination database.
        • Data may fail to be initialized, only some columns are synchronized, or the data synchronization task fails.

      Capitalization of Object Names in Destination Instance

      You can configure the case policy for database and collection object names in the destination instance. By default, the DTS default policy is selected. Alternatively, you can match the default policy of the source or destination database. For more information, see Case policy for destination object names.

      Source Objects

      Select one or more objects from the Source Objects section. Click the Rightwards arrow icon and add the objects to the Selected Objects section.

      Note
      • The admin and local databases cannot be migrated.

      • The migration objects can be selected at the granularity of database, collection, or function.

      Selected Objects

      Note
      • If you use the object name mapping feature, the migration of other objects that depend on the mapped object may fail.

      • To set a WHERE clause to filter data, right-click the object to be migrated in the Selected Objects box and set the filter condition in the dialog box that appears. For information about how to set the condition, see Set filter conditions.

    2. Click Next: Advanced Settings to configure advanced parameters.

      Configuration

      Description

      Retry Time for Failed Connections

      After the migration task starts, if the connection to the source or destination database fails, DTS reports an error and immediately begins to retry the connection. The default retry duration is 720 minutes. You can customize the retry time to a value from 10 to 1440 minutes. We recommend that you set the duration to more than 30 minutes. If DTS reconnects to the source and destination databases within the specified duration, the migration task automatically resumes. Otherwise, the task fails.

      Note
      • For multiple DTS instances that share the same source or destination, the network retry time is determined by the setting of the last created task.

      • Because you are charged for the task during the connection retry period, we recommend that you customize the retry time based on your business needs, or release the DTS instance as soon as possible after the source and destination database instances are released.

      Retry Time for Other Issues

      After the migration task starts, if a non-connectivity issue, such as a DDL or DML execution exception, occurs in the source or destination database, DTS reports an error and immediately begins to retry the operation. The default retry duration is 10 minutes. You can customize the retry time to a value from 1 to 1440 minutes. We recommend that you set the duration to more than 10 minutes. If the related operations succeed within the specified retry duration, the migration task automatically resumes. Otherwise, the task fails.

      Important

      The value of Retry Time for Other Issues must be less than the value of Retry Time for Failed Connections.

      Enable Throttling for Full Data Migration

      During full migration, DTS consumes read and write resources on the source and destination databases, which may increase the database load. If required, you can enable throttling for the full migration task. You can set Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s) to reduce the load on the destination database.

      Note
      • This configuration item is available only if you select Full Data Migration for Migration Types.

      • You can also adjust the full migration speed after the migration instance is running.

      Enable Throttling for Incremental Data Migration

      If required, you can also choose to set speed limits for the incremental migration task. You can set RPS of Incremental Data Migration and Data migration speed for incremental migration (MB/s) to reduce the load on the destination database.

      Note
      • This configuration item is available only if you select Incremental Data Migration for Migration Types.

      • You can also adjust the incremental migration speed after the migration instance is running.

      Environment Tag

      You can select an environment tag to identify the instance based on your business needs. No selection is required in this example.

      Configure ETL

      Based on your business needs, select whether to configure the ETL feature to process data.

      • Yes: Configures the ETL feature. You must also enter data processing statements in the text box.

      • No: Does not configure the ETL feature.

      Monitoring and Alerting

      Select whether to set alerts and receive alert notifications based on your business needs.

      • No: Does not set an alert.

      • Yes: Configure alerts by setting an alert threshold and an alert contact. If a migration fails or the latency exceeds the threshold, the system sends an alert notification.

    3. Click Next: Data Validation to configure a data validation task.

      For more information about the data validation feature, see Configure data validation.

  6. Save the task and run a precheck.

    • To view the parameters for configuring this instance when you call the API operation, move the pointer over the Next: Save Task Settings and Precheck button and click Preview OpenAPI parameters in the bubble that appears.

    • If you do not need to view or have finished viewing the API parameters, click Next: Save Task Settings and Precheck at the bottom of the page.

    Note
    • Before the migration task starts, DTS performs a precheck. The task starts only after it passes the precheck.

    • If the precheck fails, click View Details next to the failed check item, fix the issue based on the prompt, and then run the precheck again.

    • If a warning is reported during the precheck:

      • For check items that cannot be ignored, click View Details next to the failed item, fix the issue based on the prompt, and then run the precheck again.

      • For check items that can be ignored, you can click Confirm Alert Details, Ignore, OK, and Precheck Again to skip the alert item and run the precheck again. If you choose to ignore a warning, it may cause issues such as data inconsistency and pose risks to your business.

  7. Purchase the instance.

    1. When the Success Rate is 100%, click Next: Purchase Instance.

    2. On the Purchase page, select the link specification for the data migration instance. For more information, see the following table.

      Category

      Parameter

      Description

      New Instance Class

      Resource Group Settings

      Select the resource group to which the instance belongs. The default value is default resource group. For more information, see What is Resource Management?

      Instance Class

      DTS provides migration specifications with different performance levels. The link specification affects the migration speed. You can select a specification based on your business scenario. For more information, see Data migration link specifications.

    3. After the configuration is complete, read and select Data Transmission Service (Pay-as-you-go) Service Terms.

    4. Click Buy and Start. In the OK dialog box that appears, click OK.

      You can view the progress of the migration task on the Data Migration Tasks list page.

      Note
      • If the migration task does not include incremental migration, it stops automatically after the full migration is complete. After the task stops, its Status changes to Completed.

      • If the migration task includes incremental migration, it does not stop automatically. The incremental migration task continues to run. While the incremental migration task is running, the Status of the task is Running.

Procedure (Legacy console)

  1. Log in to the DTS console.

    Note

    If you are automatically redirected to the Data Management (DMS) console, you can click the jiqiren icon in the lower-right corner and then click 返回旧版 to return to the classic DTS console.

  2. In the left-side navigation pane, click Data Migration.
  3. At the top of the Migration Task List page, select the region where the destination MongoDB instance resides.

  4. In the upper-right corner, click Create Migration Task.
  5. Configure the Source and Destination Databases for the migration task.

    Category

    Configuration

    Description

    None

    Task Name

    DTS automatically generates a task name. We recommend that you specify a descriptive name for easy identification. The name does not have to be unique.

    Source Database

    Instance Type

    Select Self-managed Database with Public IP.

    Instance Region

    When you set the instance type to Self-managed Database With A Public IP Address, you do not need to set the Instance Region.

    Note

    You can configure security group rules as described in Preparations. You can also click Get DTS IP Segments next to the Instance Region parameter to obtain the IP addresses of the DTS servers. Then, add the obtained IP addresses to the security group rules of the Tencent Cloud MongoDB replica set instance.

    Database Type

    Select MongoDB.

    Hostname or IP Address

    Enter the public IP address of the Tencent Cloud server.

    Port

    Enter the port number of the Tencent Cloud MongoDB database. In this example, enter 27017.

    Database Name

    Enter the name of the authentication database. The default value is admin.

    Database Account

    Enter the account used to log on to the Tencent Cloud MongoDB database. The default value is mongouser. For information about the required permissions, see Required database account permissions.

    Database Password

    Enter the password for the Tencent Cloud MongoDB database account.

    Note

    After you enter the source database information, you can click Test Connection next to Database Password to verify that the information is correct. If the information is correct, a Test Passed message appears. If a Test Failed message appears, click Diagnose next to Test Failed and adjust the source database information as prompted.

    Connection Method

    Select Unencrypted Connection.

    Note

    You can select SSL Encrypted Connection only when migrating a MongoDB Atlas database.

    Destination Database

    Instance Type

    Select MongoDB Instance.

    Instance Region

    Select the region where the Alibaba Cloud MongoDB instance resides.

    MongoDB Instance ID

    Select the ID of the Alibaba Cloud MongoDB instance.

    Database Name

    Enter the name of the authentication database. The default value is admin.

    Database Account

    Enter the account used to log on to the Alibaba Cloud MongoDB database. For information about the required permissions, see Required database account permissions.

    Database Password

    Enter the password for the Alibaba Cloud MongoDB database account.

    Note

    After you enter the destination database information, you can click Test Connection next to Database Password to verify that the information is correct. If the information is correct, a Test Passed message appears. If a Test Failed message appears, click Diagnose next to Test Failed and adjust the destination database information as prompted.

  6. After the configuration is complete, click Authorize Whitelist and Proceed in the lower-right corner of the page.

    If the source or destination database is an Alibaba Cloud database instance, such as an RDS for MySQL or ApsaraDB for MongoDB instance, DTS automatically adds the IP addresses of the DTS servers in the corresponding region to the whitelist of the instance. If the source or destination database is a self-managed database on an ECS instance, DTS automatically adds the IP addresses of the DTS servers to the security rules of the ECS instance. You must also ensure that the self-managed database does not restrict access from the ECS instance. If the database is deployed in a cluster on multiple ECS instances, you must manually add the IP addresses of the DTS servers to the security rules of each ECS instance. If the source or destination database is a self-managed database in an on-premises data center or another cloud database, you must manually add the IP addresses of the DTS servers to allow access from them. For the IP addresses of the DTS servers, see CIDR blocks of DTS servers.

    Warning

    Adding the public CIDR blocks of DTS servers, whether automatically or manually, may introduce security risks. By using this product, you acknowledge and accept these potential risks. You are responsible for implementing basic security measures, including but not limited to using strong passwords, restricting open ports, using authentication for internal API calls, regularly reviewing and restricting unnecessary network segments, or connecting through private networks such as Express Connect, VPN Gateway, or Smart Access Gateway.

  7. Select Migration Objects and Migration Types.选择迁移类型和迁移对象

    Configuration

    Description

    Migration Types

    • If you only need to perform a full migration, select Full Data Migration.

    • For a zero-downtime migration, select both Full Data Migration and Incremental Data Migration. In this example, all three migration types are selected.

    Note

    If you do not select Incremental Data Migration, do not write new data to the Tencent Cloud MongoDB database during full data migration to ensure data consistency.

    Migration Objects

    • In the Migration Objects box, click the object to be migrated, and then click the icon to move it to the Selected Objects box.

      Note

      The admin and local databases cannot be migrated.

    • The migration objects can be selected at the granularity of database, collection, or function.

    • By default, the names of the migration objects remain unchanged. If you need the migration objects to have different names in the Alibaba Cloud MongoDB database, use the object name mapping feature provided by DTS. For more information, see Map tables and columns.

    Mapping Name Change

    To change the name of a migration object in the destination instance, use the object name mapping feature. For more information, see Map tables and columns.

    Retry Duration After Source/Destination Database Connection Failure

    The default retry duration is 12 hours. You can also customize the retry duration. If DTS successfully reconnects to the source or destination database within the set time, the migration task automatically resumes. Otherwise, the migration task fails.

    Note

    Because DTS charges for task runtime during connection retries, we recommend that you customize the retry duration based on your business needs, or release the DTS instance as soon as possible after the source and destination database instances are released.

  8. After the configuration is complete, click Precheck and Start in the lower-right corner of the page.

    Note
    • A precheck is performed before the migration task starts. The migration task can start only after all precheck items are passed.

    • If the precheck fails, click the 提示 icon next to the specific check item to view the failure details. Fix the issue as prompted and then perform the precheck again.

  9. After the precheck succeeds, click Next.
  10. On the Confirm Purchase Configuration page, select a Link Specification and select Data Transmission (Pay-As-You-Go) Terms of Service.

  11. Click Buy and Start to start the migration task.
    • Full data migration

      Do not manually end a migration task. If you do so, the system may fail to migrate all data of the database. Wait until the migration task is complete.

    • Incremental data migration

      An incremental data migration task does not automatically end. You need to manually end the task.

      Note Select an appropriate point in time to manually end a migration task. For example, you can end the migration task during off-peak hours or before you switch over your business to the destination ApsaraDB for MongoDB instance.
      1. When the task progress bar displays Incremental Data Migration and The migration task is not delayed, stop writing data to the source database for a few minutes. Wait until the progress bar displays the delay time of the incremental data migration next to Incremental Data Migration.
      2. After the status of Incremental Data Migration changes to The migration task is not delayed, manually end the migration task.Incremental data migration without delay
  12. Switch your business to the Alibaba Cloud MongoDB instance.

What to do next

The database account used for data migration has read and write permissions. To ensure database security, we recommend that you change the passwords of the database accounts in the Tencent Cloud MongoDB and Alibaba Cloud MongoDB instances after the data migration is complete.

How to connect to an Alibaba Cloud MongoDB database