Fully migrate Tencent Cloud MongoDB to Alibaba Cloud
Learn how to use Data Transmission Service (DTS) to perform a full migration of a Tencent Cloud MongoDB 3.2 replica set instance to Alibaba Cloud.
Core migration process
The migration process is divided into four main phases:
Preparation: Confirm the prerequisites and understand the considerations, billing, and required permissions.
Environment setup: Configure Internet access for the destination instance.
DTS configuration and execution: Create and configure a DTS migration task on Alibaba Cloud, then start and monitor the task.
Next steps: After migration completes, perform business cutover, security hardening, and resource release.
Preparation
Complete the following preparations before you start the actual operation.
Prerequisites
An Alibaba Cloud MongoDB instance is created. If not, see Create a replica set instance or Create a sharded cluster instance.
NoteThe destination ApsaraDB for MongoDB instance should have at least 10% more storage space than the source Tencent Cloud MongoDB replica set instance uses. If the destination instance has insufficient storage space, increase it. For more information, see Change instance configuration.
When migrating to an ApsaraDB for MongoDB sharded cluster instance, enable data sharding on the destination instance for optimal performance. For more information, see Configure data sharding.
Considerations
When you use DTS to migrate a standalone instance to Alibaba Cloud, incremental data migration is not supported.
The admin and local databases cannot be migrated.
During a full data migration, DTS consumes resources from both the source and destination instances, which increases database load. If your database handles heavy workloads or runs on a smaller instance type, this can put significant pressure on the database and potentially make the service unavailable. We recommend evaluating the potential impact and performing the data migration during off-peak hours.
DTS automatically resumes failed migration tasks. Before switching your workloads to the destination instance, you must stop or release the task. This prevents the task from automatically resuming and overwriting data in the destination instance.
For the versions and storage engines supported by Alibaba Cloud MongoDB instances, see Versions and storage engines. When migrating data across different versions or storage engines, verify compatibility beforehand.
Because DTS writes data concurrently, the storage space used on the destination is 5% to 10% larger than on the source.
To prevent data loss, ensure that no documents on the destination instance share a primary key (the
_idfield by default) with documents on the source. If such documents exist, you must delete them from the destination before the migration, provided it does not affect your business services.
Billing
Migration type | Link configuration fee | Internet traffic fee |
Full data migration | Free. | Charged only when data is migrated out of Alibaba Cloud over the Internet. For more information, see DTS billing items. |
Incremental data migration | Charged. For more information, see DTS billing items. |
Account permissions
We recommend that you use a high-privilege account.
Tencent Cloud MongoDB instance: mongouser
Alibaba Cloud MongoDB instance: root
Migration types
Migration type | Description |
Full data migration | DTS migrates all historical data of the required 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 synchronizes incremental data from the source MongoDB database to the destination MongoDB database. Note
|
Environment setup
Because Tencent Cloud MongoDB provides only internal network access by default, you need to configure a Cloud Load Balancer (CLB) to obtain a public IP address.
Step 1 (Optional): If you have not created a Tencent Cloud Load Balancer (CLB), create one first. If one already exists, you can skip this step.
Log on to the Tencent Cloud Load Balancer console and click Create.
On the purchase page, configure the following key parameters:
Billing method: Pay-As-You-Go
Region: Same region as the source MongoDB instance
Network type: Public network
VPC: Same network as the source MongoDB instance
Instance specification: Shared
Confirm the other settings and complete the creation. Wait for the instance status to change to Normal.
Step 2: Configure the MongoDB instance to provide external services through CLB
In the MongoDB Instance Console, click the target instance ID to enter the instance details page.
On the instance details page, find and click Configure CLB Internet Access Service.
In the dialog box, select the load balancer instance you created in the previous step and click Next.
In the listener rule configuration, set a listener port and click OK.
After completion, in the network configuration of the instance, find the Internet access address. Record the IP address and port between the
@symbol and the,symbol. This is the public connection address required for subsequent DTS configuration.Go to the security group to which the instance belongs. In the inbound rules, add a new rule to allow the MongoDB port you just configured (for example, 27017). The authorization source can be
0.0.0.0/0or a more precise IP range.In the top navigation bar, click Data Security > Security Groups. In the Joined security groups list, click the target Security group ID.
On the Inbound rule tab of Security group rules, click Add rule.
In the Add inbound rule dialog box, allow MongoDB database port 27017 to enable external access to this port.
Important0.0.0.0/0allows all IP addresses to access, which poses a security risk. Use it with caution.We recommend that you add the IP addresses provided in the DTS server access authorization dialog in the subsequent steps as the source to implement minimal authorization.
DTS configuration and execution
Log on to the Data Transmission Service (DTS) console.
In the left-side navigation pane, click Data Migration.
In the top navigation bar, select the region to which the migration instance belongs.
-
Click Create Task to navigate to the task configuration page.
Configure the source and destination databases.
WarningAfter 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
Parameter
Description
N/A
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
Database Type
Select MongoDB.
Access Method
Select Public IP.
Instance Region
Select the region of the Tencent Cloud MongoDB database.
NoteIf the region of the Tencent Cloud MongoDB database is not available in the list, select the closest region.
Architecture
Select the architecture based on your business needs. Valid values:
Replica set architecture: Deploys multiple nodes for high availability and read/write splitting. For more details, see Replica set architecture.
Sharded cluster architecture: Provides three components: Mongos, Shard, and ConfigServer. You can specify the number and configuration of Mongos and Shard nodes. For more information, see Sharded cluster architecture.
Migration Method
Oplog
Endpoint Type
Standalone
Domain Name or IP
Enter the public IP address of the Tencent Cloud MongoDB database server.
Port Number
Enter the CLB listener port configured in the previous phase.
Authentication Database
Enter the authentication database name. The default value is admin.
Database Account
Enter the account of the Tencent Cloud MongoDB database. The default value is mongouser.
Database Password
Enter the password of the Tencent Cloud MongoDB database account.
Encryption
Select Non-encrypted.
Destination Database
Database Type
Select MongoDB.
Access Method
Select Cloud Instance.
Instance Region
Select the region of the destination Alibaba Cloud MongoDB instance.
Replicate Data Across Alibaba Cloud Accounts
No
Instance ID
Select the ID of the destination Alibaba Cloud MongoDB instance.
Authentication Database
Enter the authentication database name. The default value is admin.
Database Account
Enter the database account for the destination Alibaba Cloud MongoDB instance.
Database Password
Enter the password for the database account.
Encryption
Select Non-encrypted.
After the configuration is complete, click Test Connectivity and Proceed.
Copy the DTS server IP addresses in the CIDR Blocks of DTS Servers dialog box, add them to the whitelist security settings of the source database, and click Confirm authorization and test link.
WarningAdding the public IP address blocks of DTS servers, whether automatically or manually, may introduce security risks. Using this product, you acknowledge and accept these potential risks. You must implement basic security measures, such as using strong passwords, limiting open ports for each CIDR block, using authentication for internal API calls, and regularly checking and restricting unnecessary CIDR blocks. You can also connect using an internal network, such as a leased line, VPN Gateway, or Smart Access Gateway.
Configure the task objects.
On the Configure Objects page, configure the objects that you want to migrate.
Parameter
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 if the destination database contains collections with the same names. If a collection with a duplicate name is found, an error is reported during the precheck phase and the data synchronization task does not start. Otherwise, the precheck is successful.
NoteIf you cannot delete or rename the collection with the same name in the destination database, you can use the object name mapping feature to change the collection name in the destination database. For more information, see Set the name of a synchronization object in the destination instance.
Ignore Errors and Proceed: Skips checking for collections with the same name in the destination database.
WarningSelecting Ignore Errors and Proceed may cause data inconsistency and put your business at risk. For example:
If a record in the destination database has the same primary key or unique key value as a record in the source database, the record in the destination database is retained. The record from the source database is not synchronized to the destination database.
Data initialization may fail, only some data may be synchronized, or the synchronization may fail.
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
In the Source Objects box, click the objects, and then click
to move them to the Selected Objects box.NoteThe admin and local databases cannot be migrated.
The granularity of migration objects is database, collection, or function.
Selected Objects
To set the name of a synchronization object in the destination instance, right-click the object in the Selected Objects box to modify it. For more information, see Object name mapping.
To remove a synchronization object, click it in the Selected Objects box, and then click
to move it to the Source Objects box.
NoteIf you use the object name mapping feature, the migration of other objects that depend on the mapped object may fail.
To filter data by using a WHERE clause, right-click the object to be migrated in the Selected Objects box and specify the filter condition in the dialog box that appears. For information about how to set the condition, see Configure filter conditions.
-
Click Next: Advanced Settings to configure advanced parameters.
Parameter
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.
ImportantThe 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.
Environment Tag
You can select an environment tag to identify the instance. This is not required for 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.
-
Click Data Verification to configure the data verification task. If you need to use the data verification feature, see Configure data verification.
NoteWe recommend that you select Full Data Verification and Incremental Data Verification to ensure data consistency. Other parameters can remain at their default values.
-
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.
-
-
-
When the Success Rate is 100%, click Next: Purchase Instance.
Purchase the instance.
-
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.
-
After the configuration is complete, read and select Data Transmission Service (Pay-as-you-go) Service Terms.
-
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.
-
-
Monitor the task and switch
After the task starts, you can see it in the Data Migration Tasks list.
Click the task ID to enter the details page. In the left-side navigation pane, click Task Management to view the task progress.
The task status will go through: precheck > schema migration > full migration > incremental migration.
When the task enters the incremental migration phase, observe the delay of Incremental Data Collection. When the delay approaches 0 seconds and remains stable, the source and destination databases are essentially synchronized. At this point, you can schedule a business downtime window to switch the application connection to the Alibaba Cloud MongoDB instance.
Next steps
Business verification: Verify that the business functions properly on the new Alibaba Cloud MongoDB instance.
End the DTS task: After confirming that the business runs stably on Alibaba Cloud, return to the DTS console and stop and release the migration task to avoid unnecessary fees.
Security hardening: Modify the database passwords of the source and destination databases to ensure data security.
Resource cleanup: If the resources such as CLB created on the Tencent Cloud side for migration are no longer needed, release them in a timely manner.