mongodump and mongorestore


mongoexport和mongoimport只能导出/导入某个特定集合

1 mongoexport bin目录下
./mongoexport <hostname><:port> -d nlptext -c nlp --type=csv --query '{"$or":[{"status":"checked","result":"no"},{"result":"questionable"}]}'
-f mId,name,synonyms,text,nlpResult,nlpDate,status,result,time,user -o ./nlp/nlpText720.csv
输出json数据

2 mongoimport bin目录下
./mongoimport <hostname><:port> -d pgceditors -c birth_death_info (path)/nlp/nlpText720.csv


mongodump和mongorestore可以将整个database导出/导入

3 mongodump bin目录下
./mongodump <hostname><:port> -u "test" -p "aaa" -d pgceditors -c birth_death_info -o /export/editor_db_backup/birth_death_info
导出为bson数据

4 mongorestore bin目录下
./mongorestore <hostname><:port> -u "test" -p "aaa" -d pgceditors -c birth_death_info (<path>)/export/editor_db_backup/birth_death_info

bson和json都是非压缩的数据,但bson的体积稍小。
速度的话,bson (mongodump输出)会快很多,接近快1个数量级。

注意:

一、mongodump excludes the local database in its output。在mongodump执行导出的过程中,若客户端向数据库中增加了数据,这些数据不会被backup。

并且,mongodump只是获取数据库中的数据,并不导出索引。只能在mongorestore时重建索引。

二、mongorestore命令恢复备份数据。在恢复数据时会重建索引。并且mongorestore只会insert,不会update。若在已有表的基础上restore,对相同_id的数据不会覆盖。

 

posted @ 2017-11-23 17:34  江湖凶险  阅读(301)  评论(0编辑  收藏  举报