mongdb backup

Backup and restore a database mongo


backup database:


Whole database backup:
mongodump dbhost -d dbname -h -o dbdirectory
-h: MongDB where the server address, for example: 127.0.0.1, of course, you can 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, need to establish in advance the directory, the system automatically creates a directory in the dump test after the backup directory, the directory to store the database instance backup data.


The entire database recovery:
mongorestore -h dbhost -d dbname -directoryperdb dbdirectory
-h: MongoDB server address where
-d: the need to restore the database instance, such as: test, of course, the name can also be backed up and the time is not the same, such as test2
-directoryperdb : location backup data, for example: c: \ data \ dump \ test, here, why add one more test, not the backup dump time, it prompts the reader to see!
-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!

 

Backup single collection:
mongoexport -h dbhost collectionName -d dbname -f -c -o dbdirectory collectionKey
-h: MongoDB server address where
-d: the need to restore the database instance
-c: the need to restore the set
-f: need to export the field ( omitted for all fields)
-o: represents the exported file name

 


Export single collection:

Import data parameters:

-d database to be imported
-c to be imported table (does not create its own existence)
--type CSV / json (default)
--file backup file path

Import data instance

mongoimport -d shop -c teach --type json --file ./test.sdo.json

Guess you like

Origin www.cnblogs.com/GYC-GXm/p/12112868.html