All Products
Search
Document Center

ApsaraDB for MongoDB:Migrate a self-managed MongoDB database that uses the replica set architecture to ApsaraDB for MongoDB by using DTS

Last Updated:Nov 15, 2023

This topic describes how to use Data Transmission Service (DTS) to migrate a self-managed MongoDB database that uses the replica set architecture to ApsaraDB for MongoDB. DTS supports full data migration and incremental data migration. When you configure a data migration task, you can select these two migration types to ensure service continuity.

You can also use the built-in commands of MongoDB to migrate self-managed MongoDB databases. For more information, see Migrate self-managed databases to Alibaba Cloud by using tools provided by MongoDB. For more information about data migration and synchronization solutions, see Overview.

Prerequisites

  • The versions of the source and destination MongoDB databases are supported by DTS. For more information, see Overview of data migration scenarios.
  • The available storage space of the ApsaraDB for MongoDB instance is 10% larger than the total size of the data in the self-managed MongoDB database. This is a recommended prerequisite.

Usage notes

  • DTS consumes the resources of the source and destination databases during full data migration. This may increase the loads on the database servers. If you migrate a large amount of data or if the server specifications do not 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.
  • If the source and destination ApsaraDB for MongoDB instances have different versions or storage engines, make sure that the versions or storage engines are compatible. For more information, see MongoDB versions and storage engines.
  • The admin or local database cannot be used as the source or destination database.
  • The data is concurrently written to the destination database. Therefore, the storage space occupied in the destination database is 5% to 10% larger than the size of the data in the source database.
  • Make sure that the destination MongoDB database does not have the same primary key as the source database. The default primary key is _id. Otherwise, data loss may occur in the destination database. If the destination database has the same primary key as the source database, clear the related data in the destination database without interrupting the services of DTS. If the same primary key is _id, you can delete the data in the destination database that has the same _id as the source database.

Billing

Migration typeTask configuration feeInternet traffic fee
Full data migrationFree of charge. Charged only when data is migrated from Alibaba Cloud over the Internet. For more information, see Billing overview.
Incremental data migrationCharged. For more information, see Billing overview.

Migration types

  • Full data migration: DTS migrates all existing data of objects in the source MongoDB database to the destination MongoDB database.
    Note DTS can migrate the following types of objects: database, collection, and index.
  • Incremental data migration: After full data migration is complete, DTS migrates incremental data of 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

DatabaseFull data migrationIncremental data migration
Self-managed MongoDB databaseRead permissions on the source databaseRead permissions on the source, admin, and local databases
ApsaraDB for MongoDB instanceRead and write permissions on the destination databaseRead and write permissions on the destination database

For more information about how to create a database account and grant permissions to the database account, see the following topics:

Procedure

  1. Log on to the DTS console.
  2. In the left-side navigation pane, click Data Migration.
  3. On the upper part of the Migration Tasks page, select the region in which the destination ApsaraDB for MongoDB instance resides.
  4. In the upper-right corner of the page, click Create Migration Task.
  5. Configure the source and destination databases. Configure the source and destination databases
    SectionParameterDescription
    N/ATask NameThe 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 DatabaseInstance TypeThe instance type of the source database. In this example, User-Created Database with Public IP Address is selected.
    Note If you select other instance types, you must deploy the network environment for the self-managed database. For more information, see Preparation overview.
    Instance RegionThe region in which the source database resides. If you select User-Created Database with Public IP Address as the instance type, you do not need to specify the Instance Region parameter.
    Note If a whitelist is configured for the self-managed MongoDB database, you must add the CIDR blocks of DTS servers to the whitelist of the database. You can click Get IP Address Segment of DTS next to Instance Region to obtain the CIDR blocks of DTS servers.
    Database TypeThe type of the source database. Select MongoDB.
    Hostname or IP AddressThe endpoint that is used to connect to the self-managed MongoDB database. In this example, a public IP address is used.
    Port NumberThe service port number of the self-managed MongoDB database.
    Note The service port of the self-managed MongoDB database must be accessible over the Internet.
    Database NameThe name of the authentication database. The database account is created in this database.
    Database AccountThe account that is used to log on to the self-managed MongoDB database. For information about the permissions that are required for the account, see Permissions required for database accounts.
    Database PasswordThe 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. If the information is incorrect, the Failed message is displayed and you must click Check next to the Failed message to modify the information.
    EncryptionSelect Non-encrypted.
    Note You can select SSL-encrypted only when you migrate data from MongoDB Atlas.
    Destination DatabaseInstance TypeThe instance type of the destination database. Select MongoDB Instance.
    Instance RegionThe region in which the destination ApsaraDB for MongoDB instance resides.
    MongoDB Instance IDThe ID of the destination ApsaraDB for MongoDB instance.
    Database NameThe name of the authentication database. The database account is created in this database.
    Database AccountThe 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 PasswordThe password of the database account.
    Note After you specify the information about the destination instance, 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. If the information is incorrect, the Failed message is displayed and you must click Check next to the Failed message to modify the information.
  6. 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.
  7. Select the migration types and the objects to be migrated. Select the migration types and the objects to be migrated
    SettingDescription
    Select the migration types
    • To perform only full data migration, select only Full Data Migration.
    • To ensure service continuity during data migration, select Full Data Migration and Incremental Data Migration.
    Note If Incremental Data Migration is not selected, we recommend that you do not write data to the self-managed MongoDB database during full data migration. This ensures data consistency between the source and destination databases.
    Select the objects to be migrated
    • Select one or more objects from the Available section. Click the Rightwards arrow icon and add the objects to the Selected Objects section.
      Note DTS cannot migrate data from the admin, local, or config 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 objectsYou 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 a failed connection to the source or destination databaseBy default, if DTS fails to connect to the source and destination databases, DTS retries within the following 12 hours. You can specify the retry time range based on your business requirements. If DTS is reconnected to the source and destination databases within the specified time range, DTS resumes the data migration task. Otherwise, the data migration task fails.
    Note Within the retry 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 instances are released.
  8. Click Precheck.
    Note
    • A precheck is performed before the migration task starts. The migration task only starts after the precheck succeeds.
    • If the precheck fails, click the Note icon next to each failed check item to view the related details. Fix the issues as instructed and run the precheck again.
  9. After the task passes the precheck, click Next.
  10. In the Confirm Settings dialog box, specify the Instance Class parameter and select the check box to agree to Data Transmission Service (Pay-As-You-Go) Service Terms.
  11. Click Buy and Start to start the data 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

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

      Note We recommend that you select an appropriate time to manually stop the data migration task. For example, you can stop the task during off-peak hours or before you switch your workloads to the ApsaraDB for MongoDB instance.
      1. Wait until Incremental Data Migration and The migration task is not delayed are displayed 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. The migration task is not delayed
  12. Switch your workloads to the destination ApsaraDB for MongoDB instance.

References

Connect to a replica set instance