MongoDB 备份恢复中遇到的 lost connection to server 问题

备份方法: 参见 http://www.jb51.net/article/40285.htm

整库备份:

mongodump -h dbhost -d dbname -o dbdirectory

整库恢复:

mongorestore -h dbhost -d dbname –directoryperdb dbdirectory

单表备份:

mongoexport -h dbhost -d dbname -c collectionname -f collectionKey -o dbdirectory

单表恢复

mongoimport -d my_mongodb -c user user.dat

恢复过程中报错:

mongoimport -d popstar -c mails mails

2015-11-02T10:05:25.228+0100    connected to: localhost
2015-11-02T10:05:25.735+0100    error inserting documents: lost connection to server
2015-11-02T10:05:25.735+0100    Failed: lost connection to server
2015-11-02T10:05:25.735+0100    imported 0 documents

解决方案参见: http://stackoverflow.com/questions/33475505/mongodb-mongoimport-loses-connection-when-importing-big-files

guess the problem is about performance, any way you can solved used:

you can use mongoimport option -j. Try increment if not work with 4. i.e, 4,8,16, depend of the number of core you have in your cpu.

mongoimport –help

-j, –numInsertionWorkers= number of insert operations to run concurrently (defaults to 1)

完美解决语句:

mongoimport -d popstar -c mails mails -j 10

Donate - Support to make this site better.
捐助 - 支持我让我做得更好.