MongoDB provides native backup utilities that you can use to migrate Azure Cosmos DB API for MongoDB to Alibaba Cloud.
- This data migration is a full migration. To avoid data inconsistencies, we recommend that you stop all write operations to the database before migration.
- If you have used mongodump commands to back up the database, move the files in the dump folder to other directories. Make sure that the default dump folder is empty before data migration. Otherwise, existing backup files in this folder will be overwritten.
- Run mongodump and mongorestore commands on servers on which MongoDB is installed. Do not run these commands in the mongo shell.
Required database permissions
|Migration type||Full migration|
|Azure Cosmos DB||Read|
|Target MongoDB instance||Read and write|
- Create an ApsaraDB for MongoDB instance. For more information, see Create an instance.
- The instance storage capacity must be larger than Azure Cosmos DB.
- Select MongoDB version 3.4.
- Set a password for the ApsaraDB for MongoDB instance. For more information, see Set a password.
- Install MongoDB on a server. For more information, see Install MongoDB.
- Install MongoDB 3.0 or a later version.
- This server is used to temporarily store data during backup and recovery, and is not needed after the migration is complete.
- The capacity of the disk where the backup is stored must be larger than Azure Cosmos DB.
This example installs MongoDB on a Linux server. You can also use other operating systems, such as Windows.
- Log on to the Azure portal.
- Click Azure Cosmos DB from the left-side navigation pane.
- On the Azure Cosmos DB page, click the account name of the Azure Cosmos DB that you want to migrate.
- On the account details page, click Connection String.
- Click the Read-only Keys tab to view the database connection information.
Note To migrate data, you only need a database account that has read-only permissions.
- Run the following command on the MongoDB server to back up the Azure Cosmos DB to
mongodump --host <HOST>:10255 --authenticationDatabase admin -u <USERNAME> -p <PRIMARY PASSWORD> --ssl --sslAllowInvalidCertificates
Note: Replace <HOST>, <USERNAME>, and <PRIMARY PASSWORD> with the corresponding values shown in theFigure 1 figure.
After the backup is complete, backups of the Azure Cosmos DB are stored in the dump folder.
- Obtain the endpoint of the primary node of the ApsaraDB for MongoDB instance. For more information, see Retrieve the seven connection elements.
- Run the following command on the MongoDB server to export the backups to the ApsaraDB
for MongoDB instance.
mongorestore --host <mongodb_host>:3717 --authenticationDatabase admin -u <username> -p <password> dumpDescription:
- <mongodb_host>: The endpoint of the primary node of the MongoDB instance.
- <username>: The username for the MongoDB instance.
- <password>: The password for the MongoDB instance.
After the recovery is complete, backups of the Azure Cosmos DB are migrated to the ApsaraDB for MongoDB instance.