MongoDB Database Migration

DRS helps you migrate data from self-built MongoDB databases on the ECS to the DDS DB instances on the current cloud. With DRS, you can migrate databases online with zero downtime and your services and databases can remain operational during migration.

This section describes how to use DRS to migrate data from self-built MongoDB databases on the ECS to DDS DB instances on the current cloud. The following network scenarios are supported:

  • Source and destination databases are in the same VPC.
  • Source and destination databases are in different VPCs.

Diagram

Figure 1 Source and destination databases in the same VPC
Figure 2 Source and destination databases in the same region and different VPCs

Migration Process

Figure 3 Migration process

Migration Suggestions (Important)

  • Database migration is closely impacted by a wide range of environmental and operational factors. To ensure the migration goes smoothly, you are advised to perform a test run before the actual migration to help you detect and resolve any potential issues in advance. Recommendations on how to minimize any potential impacts on your data base are provided in this section.
  • It is strongly recommended that you start your migration task during off-peak hours. A less active database is easier to migrate successfully. If the data is fairly static, there is less likely to be any severe performance impacts during the migration.

Notes on Migration (Important)

Before creating a migration task, read the migration notes carefully.

For details, see the Before You Start section in the Getting Started with Data Replication Service.

Preparing the Migration

  1. Permissions
    Table 1 lists the permissions required for the source and destination databases when migrating data from on-premises MongoDB databases to DDS DB instances.
    Table 1 Migration permissions

    Database

    Full Migration Permission

    Full+Incremental Migration Permission

    Source

    • Replica set: The source database user must have the readAnyDatabase permission on the admin database.
    • Cluster: The source database user must have the readAnyDatabase permission on the admin database and the read permission on the config database.
    • Single node: The source database user must have the readAnyDatabase permission on the admin database.
    • To migrate accounts and roles of the source database, the source database user must have the read permission on the system.users and system.roles system tables of the admin database.
    • Replica set: The source database user must have the readAnyDatabase permission on the admin database and have the read permission on the local database.
    • Single node: The source database user must have the readAnyDatabase permission on the admin database and the read permission on the local database.
    • Cluster: The source database user that connects to the mongos node must have the readAnyDatabase permission on the admin database and the read permission on the config database. The source database user that connects to the shard nodes must have the readAnyDatabase permission on the admin database and the read permission on the local database.
    • To migrate accounts and roles of the source database, the source database user must have the read permission on the system.users and system.roles system tables of the admin database.

    Destination

    The destination database user must have the readAnyDatabase permission on the admin database and the readWrite permission on the destination database.

    • Source database permissions:

      The source database account must have all the required permissions listed in Table 1. If the permissions are insufficient, create a user that has all of the permissions on the source database.

    • Destination database permissions:

      If the destination database is a DDS database, the initial account can be used.

  2. Network settings
    • The source database and destination DDS DB instance must be in the same region.
    • The source database and destination DDS DB instance can be either in the same VPC or different VPCs.
      • If the source and destination databases are in different VPCs, the subnets of the source and destination databases are required to be in different CIDR blocks. You need to create a VPC peering connection between the two VPCs. For details, see VPC Peering Connection Creation Procedure.
      • If the source and destination databases are in the same VPC, the networks are interconnected by default.
  3. Security rules
    • In the same VPC, the network is connected by default. You do not need to set a security group.
    • In different VPCs, establish a VPC peering connection between the two VPCs. You do not need to set a security group.
  4. Other

    You need to export the user information of the MongoDB database first and manually add it to the destination DDS DB instance because the user information will not be migrated.

Migration Procedure

  1. Create a migration task.

    1. Log in to the management console and choose Database > Data Replication Service to go to the DRS console.
    2. On the Online Migration Management page, click Create Migration Task.
    3. On the Create Replication Instance page, configure the task details, recipient, and replication instance and click Next.
      Figure 4 Replication instance information
      Table 2 Task information

      Parameter

      Description

      Task Name

      Consists of 4 to 64 characters, starts with a letter, and can contain only letters (case-insensitive), digits, hyphens (-), and underscores (_).

      Send Notifications

      If the function is enabled, DRS will send notifications to the specified recipients based on the mobile numbers and email addresses you provided. If an exception occurs during the migration, the system will send a notification to the specified recipients.

      NOTE:

      Recipients must confirm the subscription on the SMN console within 48 hours of receiving an SMS message or email. Otherwise, they cannot receive notifications from DRS.

      Synchronization Delay Threshold

      During an incremental migration, a synchronization delay indicates a time difference (in seconds) of synchronization between the source and destination database.

      If the synchronization delay exceeds the threshold you specify, DRS will send notifications to the specified recipients. The value ranges from 1 to 3,600. The unit is second.

      NOTE:

      In the early stages of an incremental migration, there is more delay because more data is waiting to be synchronized. In this situation, no notifications will be sent.

      Description

      Consists of a maximum of 256 characters and cannot contain the following special characters: !=<>'&"

      Table 3 Replication instance information

      Parameter

      Description

      Data Flow

      To the cloud

      Source DB Engine

      MongoDB database

      Destination DB Engine

      DDS

      Network Type

      VPC

      Destination DB Instance

      The DDS DB instance you purchased.

      Migration Type

      Select Full+Incremental as an example:

      • Full: This migration type is suitable for scenarios where a service interruption is acceptable. All objects and data in non-system databases are migrated to the destination database at one time. The objects include tables, views, and stored procedures.
        NOTE:

        If you perform a full migration, you are advised to stop operations on the source database. Otherwise, data generated in the source database during the migration will not be synchronized to the destination database.

      • Full+Incremental: This migration type allows you to migrate data without interrupting services. After a full migration initializes the destination database, an incremental migration initiates and parses logs to ensure data consistency between the source and destination databases.
      NOTE:

      If you select the Full+Incremental migration type, data generated during the full migration will be synchronized to the destination database with zero downtime, ensuring that both the source and destination databases remain accessible.

    4. On the Configure Source and Destination Databases page, wait until the replication instance is created, and then configure the source and destination database details. You are advised to click Test Connection in the Source Database and Destination Database areas to check that both the source and destination databases are connected. Then, select the check box before the agreement and click Next.
      Figure 5 Source and destination database details
      Table 4 Source database information

      Parameter

      Description

      Source Database Type

      Non-DDS DB instance

      VPC

      A dedicated virtual network in which the source database is located. It isolates networks for different services. You can select an existing VPC or create a VPC. For details on how to create a VPC, see Creating a VPC.

      Subnet

      A subnet provides dedicated network resources that are logically isolated from other networks, improving network security. Subnets can take effect only in AZs. You need to enable the DHCP for subnets where you plan to create the source database, and cannot disable the DHCP during creation. For details on how to create a VPC, see the Creating a VPC section in the Virtual Private Cloud User Guide.

      IP Address or Domain Name

      The IP address or domain name of the source database.

      Port

      The port of the source database.

      Range: 1 - 65535

      Database Username

      A username for the source database.

      Database Password

      The password for the database username.

      SSL Connection

      To improve data security during the migration, you are advised to enable SSL to encrypt migration links and upload a CA certificate.

      Table 5 Destination database information

      Parameter

      Description

      DB Instance Name

      The DDS DB instance you have selected during the migration task creation is displayed by default and cannot be changed.

      Database Username

      The username for accessing the destination DDS DB instance.

      Database Password

      The password for the database username.

    5. On the Set Task page, select a migration type and migration objects.
      Figure 6 Migration objects
      Table 6 Migration types and objects

      Parameter

      Description

      Migration Object

      Select the objects to be migrated. The objects can be either databases or tables. After the objects are migrated to the destination DB instance, the object names remain the same as those in the source database and cannot be modified.

    6. On the Check Task page, check the migration task.
      • If any check fails, review the cause and rectify the fault. After the fault is rectified, click Check Again.

        For details about how to handle check failures, see the Checking Whether the Source Database Is Connected section in the Data Replication Service User Guide.

      • If all check items are successful, click Next.
      Figure 7 Task Check

      You can proceed to the next step only when all check items are successful. If any alarms are generated, view and confirm the alarm details first before proceeding to the next step.

    7. On the Confirm Task page, specify Start Time, select the check box before the agreement, and click Next.
      • Set Start Time to Start upon task creation or Start at a specified time based on site requirements.
      • After a migration task is started, the performance of the source and destination databases may be affected. You are advised to start a migration task during off-peak hours. If you have to migrate data during peak hours, you can select Yes for Flow Control to control the migration speed.
    8. After the task is submitted, go back to the Online Migration Management page to view the task status.

  2. Manage the migration task.

    The migration task contains two phases: full migration and incremental migration. You can manage them in different phases.
    • Full migration

      Viewing the migration progress: Click the target full migration task, and on the Migration Progress tab, you can see the migration progress. When the progress reaches 100%, the migration is complete.

    • Incremental migration
      • Viewing the synchronization delay: After the full migration is complete, an incremental migration starts. On the Online Migration Management page, click the target migration task. On the displayed page, click Migration Progress to view the synchronization delay of the incremental migration. If the synchronization delay is 0s, the destination database is being synchronized with the source database in real time. You can also view the data consistency on the Migration Comparison tab.
        Figure 8 Viewing the synchronization delay
      • Viewing the migration results: On the Online Migration Management page, click the target migration task. On the displayed page, click Migration Comparison and perform a migration comparison in accordance with the comparison process, which should help you determine an appropriate time for migration to minimize service downtime.
        Figure 9 Database comparison process

        For details, see the Comparing Migration Items section in the Data Replication Service User Guide.

  3. Cut over services.

    You are advised to start the cutover process during off-peak hours. Before the cutover, ensure that at least one complete data comparison is performed during off-peak hours. You can start a comparison at a specified time during off-peak hours to obtain more specific comparison results. Due to slight time difference and continuous operations on data, inconsistent comparison results may be generated, reducing the reliability and validity of the results.

    1. First, stop services. If the workload is not heavy, this may not be necessary.
    2. Run the following statement on the source database and check whether any new sessions execute SQL statements within the next 1 to 5 minutes. If there are no new statements executed, the service has been stopped.
      db.currentOp()

      The process list queried by the preceding statement includes the connection of the DRS replication instance. If no additional session executes SQL statements, the service has been stopped.

    3. On the Migration Progress page, view the synchronization delay. When the delay is displayed as 0s and remains stable for a period, then you can perform a data-level comparison between the source and destination databases. For details about the time required, refer to the results of the previous comparison.
      • If there is enough time, compare all objects.
      • If there is not enough time, use the data-level comparison to compare the tables that are frequently used and that contain key business data or inconsistent data.
    4. Determine an appropriate time to cut the services over to the destination database. After services are restored and available, the migration is complete.

  4. Stop or delete the migration task.

    1. Stopping the migration task. After databases and services are migrated to the destination database, to prevent operations on the source database from being synchronized to the destination database to overwrite data, you can stop the migration task. This operation only deletes the replication instance, and the migration task is still displayed in the task list. You can view or delete the task. DRS will not charge for this task after you stop it.
    2. Delete the migration task. After the migration task is complete, you can delete it. After the migration task is deleted, it will no longer be displayed in the task list.