This topic describes how to migrate data between ApsaraDB for MongoDB instances of different Alibaba Cloud accounts by using Data Transmission Service (DTS). DTS supports full data migration and incremental data migration. When you migrate data between ApsaraDB for MongoDB instances, you can select both of the supported migration types to ensure service continuity.
Prerequisites
- The source instance is a standalone instance or a replica set instance. If the source instance is a sharded cluster instance, we recommend that you use the built-in commands of MongoDB to migrate data. For more information, see Migrate a self-managed MongoDB database to ApsaraDB for MongoDB by using tools provided by MongoDB. Note DTS does not support incremental data migration from a standalone instance. For more information, see Migration types.
- The destination instance is created in the destination region. For more information, see Create a standalone instance, Create a replica set instance, or Create a sharded cluster instance. Note The available storage space of the destination instance is 10% larger than the total size of the data in the source instance. 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 the loads on the database servers are high or the server specifications do not meet the migration 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.
- DTS does not support incremental data migration from a standalone instance. To ensure data consistency, do not write data to the source instance during full data migration.
- 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.
- ApsaraDB for MongoDB automatically updates the minor version of the instance to the latest version if the minor version of an ApsaraDB for MongoDB instance expires or is not included in the maintenance list and when you perform some operations. This ensures that the ApsaraDB for MongoDB instance can provide higher performance and stability. For more information, see Database version upgrade, Data migration, Overview, Restore backup data to a new ApsaraDB for MongoDB instance by backup point, Restore backup data to a new ApsaraDB for MongoDB instance by point in time, and Restore one or more databases of an ApsaraDB for MongoDB instance.
- 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 type | Task configuration fee | Internet traffic fee |
---|---|---|
Full data migration | Free of charge. | Charged only when data is migrated from Alibaba Cloud over the Internet. For more information, see Billing overview. |
Incremental data migration | Charged. For more information, see Billing overview. |
Migration types
Migration type | Description |
---|---|
Full data migration | DTS migrates the existing data of 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 migrates incremental data from the source MongoDB database to the destination MongoDB database. Note
|
Permissions required for database accounts
Database | Full data migration | Incremental data migration |
---|---|---|
Source ApsaraDB for MongoDB instance | Read permissions on the source database | Read permissions on the source, admin, and local databases |
Destination ApsaraDB for MongoDB instance | Read and write permissions on the destination database | Read and write permissions on the destination database |
Preparations
- Log on to the ApsaraDB for MongoDB console by using the Alibaba Cloud account that owns the source instance.
- Apply for a public endpoint for the source instance. For more information, see Apply for a public endpoint.
- Add the CIDR blocks of DTS servers to the whitelist of the source instance. For more information, see Configure a whitelist or an ECS security group for an ApsaraDB for MongoDB instance. Note You can determine the CIDR blocks you need to add based on the region in which the destination instance resides. For more information, see Add the CIDR blocks of DTS servers to the security settings of on-premises databases.
For example, if the source instance resides in the China (Hangzhou) region and the destination instance resides in the China (Shenzhen) region, you must add the CIDR blocks of DTS servers in the China (Shenzhen) region to the whitelist of the source instance.
Procedure
- Log on to the ApsaraDB for MongoDB console.
- In the left-side navigation pane, click Replica Set Instances or Sharded Cluster Instances based on the instance type.
- In the upper-left corner of the page, select the resource group and region to which the instance belongs.
- Click the ID of an instance, or click
in the Actions column corresponding to the instance and select Manage.
- In the upper-right corner of the instance details page, click Migrate Databases.
- On the Create Migration Task page, create a data migration task.
- View the progress of the 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
An incremental data migration task does not automatically stop. You must manually stop the task.
- Wait until Incremental Data Migration and The migration task is not delayed appear 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.
- Wait until the status of incremental data migration changes to The migration task is not delayed again. Then, manually stop the migration task.
- Full data migration
- Switch your workloads to the destination ApsaraDB for MongoDB instance.
What to do next
If you no longer need the source instance, release the source instance.
- If the source instance is charged based on the pay-as-you-go billing method, you can release the instance. For more information, see Release an instance or a node.
- If the source instance is charged based on the subscription billing method, you are not allowed to release the instance.
References
If you migrate data to a sharded cluster instance, you can configure data sharding based on your business requirements. For more information, see Configure sharding to maximize the performance of shards.