MongoDB backup and recovery
MongoDB data backup
In Mongodb we use the mongodump command to back up MongoDB data. This command can export all data to the specified directory.
The mongodump command can use parameters to specify the server where the exported data will be dumped.
Syntax
The mongodump command script syntax is as follows:
>mongodump -h dbhost -d dbname -o dbdirectory
-h:
The server where MongDB is located Address, for example: 127.0.0.1, of course you can also specify the port number: 127.0.0.1:27017
-d:
needs to be backed up Database instance, for example: test
-o:
The backup data storage location, for example: c:\data\dump, of course The directory needs to be established in advance. After the backup is completed, the system automatically creates a test directory in the dump directory, which stores the backup data of the database instance.
Instance
Use 27017 locally to start your mongod service. Open the command prompt window, enter the bin directory of the MongoDB installation directory and enter the command mongodump:
>mongodump
After executing the above command, the client will connect to the MongoDB service with IP address 127.0.0.1 and port number 27017, and backup All data to bin/dump/ directory. The command output is as follows:
The mongodump command optional parameter list is as follows:
Syntax | Description | Instance |
---|---|---|
This command will back up all MongoDB data | mongodump --host w3cschool.cc --port 27017 | |
This command will back up the collection of the specified database. | mongodump --collection mycol --db test |