MongoDB Data Backup
In MongoDB we use the Mongodump command to back up MongoDB data.
The command is able to export all the data to the specified folder.
The Mongodump command is able to specify the server to which the exported data is transferred by using the number of parameters.
Grammar
The mongodump command script syntax is as follows:
>---o dbdirectory
- -H:
MONGDB the server address, for example: 127.0.0.1. Of course, you can also specify the port number: 127.0.0.1:27017
- -D:
Database instances that need to be backed up, such as: test
- -O:
The location where the backed up data is stored. For example: C:\data\dump. Of course, the folder needs to be established in advance, after the backup is complete, the system itself actively in the Dump folder to create a test folder. This folder contains the backup data for the database instance.
The optional list of MONGODUMP commands is as follows:
Grammar |
Descriptive narrative |
Example |
Mongodump--host host_name--port port_number |
This command will back up all MONGODB data |
Mongodump--host w3cschool.cc--port 27017 |
Mongodump--dbpath Db_path--out backup_directory |
|
Mongodump--dbpath/data/db/--out/data/backup/ |
Mongodump--collection Collection--db db_name |
The command backs up a collection of the specified databases. |
Mongodump--collection mycol--db test |
MongoDB Data Recovery
MongoDB uses the Mongorerstore command to restore the backed up data.
Grammar
The mongorestore command script syntax is as follows:
>----Directoryperdb dbdirectory
- -H:
MongoDB Host Server address
- -D:
A database instance that needs to be restored, such as test, can also be a different name than the backup time, for example Test2
- --directoryperdb:
The location where the backup data resides. For example: C:\data\dump\test. Why do you add a test here instead of a dump at backup time? Read the tips for yourself!
- --drop:
When recovering, delete the current data and then restore the backed up data.
That is, after the recovery, after the backup to add changes to the data will be deleted, use with caution oh.
Novice MongoDB Learning---(vii) MongoDB Backup (mongodump) and recovery (Mongorerstore)