Migrate Tencent Cloud MongoDB to Alibaba Cloud

Updated at:

You can use the native MongoDB backup and restore tools, mongodump and mongorestore, to fully migrate a Tencent Cloud MongoDB replica set instance to Alibaba Cloud.

Background

When you need to migrate your Tencent Cloud MongoDB database to Alibaba Cloud due to business adjustments or to use specific Alibaba Cloud features, you can use the native MongoDB backup and restore tools, mongodump and mongorestore, for a full data migration.

Prerequisites

Considerations

  • This operation is a full data migration. Before migrating, you must stop all services connected to the source Tencent Cloud MongoDB database. To ensure data consistency, do not write new data to the source database during the migration.
  • To avoid disrupting your business, migrate the data during off-peak hours.
  • If you have previously used the mongodump command to back up the database, move the files from the dump directory to another location. Ensure that the dump directory is empty. Otherwise, the new backup operation will overwrite the existing backup files in the directory.
  • For the database versions and storage engines supported by Alibaba Cloud MongoDB, see Database versions and storage engines. If you are migrating across different versions or storage engines, verify compatibility in advance.

Database account permission requirements

Migration object Permission requirements
Tencent Cloud MongoDB instance read permission on the source database
Alibaba Cloud MongoDB instance readWrite permission on the destination database

Procedure

Tencent Cloud MongoDB instances provide only an internal endpoint and no public endpoint. You must create a Tencent Cloud cloud server with a public IP address to forward traffic for the migration. After the migration, you can release the Tencent Cloud cloud server if you no longer need it.

  1. Create a Tencent Cloud cloud server. In this topic, a Linux-based cloud server is used as an example.
    Note To ensure proper communication between the Tencent Cloud cloud server and the Tencent Cloud MongoDB replica set instance, you must configure the cloud server in the same region, availability zone, VPC, and subnet as the MongoDB replica set instance.
  2. Log on to the Tencent Cloud cloud server and install MongoDB. For more information, see Install MongoDB.
    Note Ensure that the installed MongoDB version matches the version of your Tencent Cloud MongoDB database.
  3. Return to the Tencent Cloud server console. In the left-side navigation pane, click Security Groups.
  4. On the Inbound Rules tab, click Add Rule to allow public access to the MongoDB port 27017. In the Add Inbound Rule dialog box, set Type to "Custom", Source to 0.0.0.0/0, Protocol and Port to tcp:27017, Policy to "Allow", and Description to "mongodb".
  5. Go to the Tencent Cloud MongoDB console and click the name of the target MongoDB instance.
  6. Click the Security Groups tab, and then click Configure Security Group.
  7. In the Configure Security Group dialog box, select the security group where port 27017 is open, and click Confirm.
  8. On the Tencent Cloud MongoDB console, obtain the internal IP address of the Tencent Cloud MongoDB instance. In the left-side navigation pane, choose Replica Set Instances or Sharded Cluster Instances. In the instance list, view the IP address and port in the Intranet Address column.
  9. Log on to the Tencent Cloud cloud server and run the following command to back up data to the server.
    mongodump --host <host>:27017 -u <username> --authenticationDatabase admin
    Note
    • <host>: The internal IP address of the Tencent Cloud MongoDB instance.
    • <username>: The database account used to connect to the Tencent Cloud MongoDB database. The default value is mongouser.
    Example:
    mongodump --host 10.10.0.7:27017 -u mongouser --authenticationDatabase admin
  10. When prompted with Enter password:, enter the password for the database account to start the backup.
    Note Wait for the backup to complete. The command backs up the data to the dump directory in the current directory.
  11. On the Tencent Cloud console, obtain the public IP address of the Tencent Cloud cloud server. In the left-side navigation pane, choose Instances. In the instance list, find the IP address labeled (Public) in the Primary IP Address column.
  12. Log on to the Alibaba Cloud MongoDB console and add the public IP address of the Tencent Cloud cloud server to the IP whitelist of the Alibaba Cloud MongoDB instance. For more information, see Configure an IP whitelist.
  13. Obtain the public endpoint of the Alibaba Cloud MongoDB instance.
    • If you are migrating to an Alibaba Cloud MongoDB replica set instance, obtain the public endpoint of the primary node. For more information, see Connect to a replica set instance.
    • If you are migrating to an Alibaba Cloud MongoDB sharded cluster instance, obtain the public endpoint of any mongos node. For more information, see Connect to a sharded cluster instance.
    Note You must apply for a public endpoint. For more information, see Apply for a public endpoint.
  14. On the Tencent Cloud cloud server, run the following command to import the data into the Alibaba Cloud MongoDB database.
    mongorestore --host <mongodb_host>:3717 -u <username> -d <database>  <dir> --authenticationDatabase admin
    Note
    • <mongodb_host>: The public endpoint of the Alibaba Cloud MongoDB instance, excluding the port number.
    • <username>: The database account used to connect to the Alibaba Cloud MongoDB instance. This example uses the account test.
    • <database>: The database to import. If the backup file contains multiple databases, repeat this step for each database.
    • <dir>: The directory where the database backup files are stored.

    Examples:

    • Import the mongodbtest database from the backup file:
      mongorestore --host dds-bpxxxxxxxxxx-pub.mongodb.rds.aliyuncs.com:3717 -u test --authenticationDatabase admin -d mongodbtest /dump/mongodbtest 
    • Import the test123 database from the backup file:
      mongorestore --host dds-bpxxxxxxxxxx-pub.mongodb.rds.aliyuncs.com:3717  -u test -authenticationDatabase admin -d test123 /dump/test123
  15. When prompted with Enter password:, enter the password for the database account to start the import.
    Note Wait for the import to complete. The data will then be available in your Alibaba Cloud MongoDB database.
  16. Based on your business needs, choose an appropriate time to switch your application to the Alibaba Cloud MongoDB instance.

Connecting to an Alibaba Cloud MongoDB database