Document Database Service

Migrating Data Using mongodump and mongorestore

2025-07-16 03:38:05

The use of the mongodump and mongorestore tools to migrate data in the DDS is a common and reliable approach. These two tools are official MongoDB backup and restore tools that can help you back up data from one DDS instance to a file, and then restore the backup file to another DDS instance.

Follow the following steps to migrate data in the DDS using mongodump and mongorestore:

  1. Use mongodump to back up data: Run the mongodump command on the server where the source DDS instance resides to back up the data to a file. mongodump command: mongodump --uri=your_source_mongodb_uri --out=/path/to/backup_directory. Wherein, your_source_mongodb_uri is the connection URI of the source DDS instance, and /path/to/backup_directory is the directory where the backup files are saved. Make sure you have permission to write files into this directory.

  2. Transfer backup files to the target server: Transfer the files backed up in the previous step to the server where the target DDS instance resides, using scp, rsync, or another file transfer tool.

  3. Use mongorestore to restore data: Run the mongorestore command on the server where the target DDS instance resides to restore the backup files to the target MongoDB instance. mongorestore command: mongorestore --uri=your_target_mongodb_uri /path/to/backup_directory. Wherein, your_target_mongodb_uri is the connection URI of the target MongoDB instance, and /path/to/backup_directory is the directory where the backup files are located.

  4. Verify data migration: After running the mongorestore command, you can connect to the target DDS instance and verify whether the data is migrated successfully using mongo shell or MongoDB client tool.

Note:

Using the mongodump and mongorestore tools for data migration will cause the data on the target MongoDB instance to be completely overwritten by the data in the source instance. Therefore, before data migration, it is important to back up data and test and verify data migration outside of the production environment. If data already exists on the target instance to which data is migrated, take special care to avoid data conflicts and repeated insertions. In addition, if the amount of data is large or the data must be migrated in the production environment, the DDS replica set or sharded cluster is recommended to migrate data progressively to ensure data continuity and consistency.


eIrX1bXWaKKH