MongoDB data backup
grammar
mongodump command script syntax is as follows:
mongodump -h dbhost -d dbname -o dbdirectory
-H:
MongDB host server address, for example: 127.0.0.1, of course, may specify the port number: 127.0.0.1: 27017
-d:
database instance to be backed up, for example: Test
-o:
backup data storage location, for example: c : \ data \ dump, of course, the directory needs to establish in advance, the system automatically creates a test directory in the dump directory after the backup is complete, the directory backup data stored inside the database instance.
Examples
27017 mongod start using your services locally. Open a command prompt, enter MongoDB installation directory bin directory enter the command mongodump:
mongodump -h 127.0.0.1 -d db -o d:\db
MongoDB Data Recovery
MongoDB uses mongorestore command to restore data backed up.
grammar
mongorestore command script syntax is as follows:
mongorestore -h <hostname><:port> -d dbname <path>
--host <: Port>, -h <: Port>:
MongoDB where the server address, by default: localhost: 27017--db, -d:
database instance needs to be restored, for example: test, of course, the name can also be backed up and the time is not the same, such as test2--drop:
recovery time, first delete the current data, and then restore the backup data. That is, after the resumption, after adding backup modified data will be deleted, caution Oh!path:
The last parameter mongorestore, the installation position of the backup data, for example: c: \ data \ dump \ test.You can not specify the path and --dir Options, - dir can also set the backup directory.
--dir:
Specifies the backup directoryYou can not specify the path and --dir option.
Examples
Execute the following command:
mongorestore -h 127.0.0.1 -d db d:\db\db