{"id":5416,"date":"2020-07-30T13:36:16","date_gmt":"2020-07-30T05:36:16","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5416"},"modified":"2020-07-30T13:36:16","modified_gmt":"2020-07-30T05:36:16","slug":"mongodb%e7%9a%84%e5%a4%87%e4%bb%bd%e4%b8%8e%e6%81%a2%e5%a4%8d","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5416","title":{"rendered":"MongoDB\u7684\u5907\u4efd\u4e0e\u6062\u590d"},"content":{"rendered":"<h2>1.1 MongoDB\u7684\u5e38\u7528\u547d\u4ee4<\/h2>\n<p>mongoexport \/ mongoimport mongodump \/ mongorestore<br \/>\n\u6709\u4ee5\u4e0a\u4e24\u7ec4\u547d\u4ee4\u5728\u5907\u4efd\u4e0e\u6062\u590d\u4e2d\u8fdb\u884c\u4f7f\u7528\u3002<\/p>\n<h3>1.1.1 \u5bfc\u51fa\u5de5\u5177mongoexport<\/h3>\n<p>Mongodb\u4e2d\u7684mongoexport\u5de5\u5177\u53ef\u4ee5\u628a\u4e00\u4e2acollection\u5bfc\u51fa\u6210JSON\u683c\u5f0f\u6216CSV\u683c\u5f0f\u7684\u6587\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u6307\u5b9a\u5bfc\u51fa\u7684\u6570\u636e\u9879\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u6307\u5b9a\u7684\u6761\u4ef6\u5bfc\u51fa\u6570\u636e\u3002<br \/>\n\u8be5\u547d\u4ee4\u7684\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\\\"40%\\\">\u53c2\u6570<\/td>\n<td width=\\\"59%\\\">\u53c2\u6570\u8bf4\u660e<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-h<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u5bbf\u4e3b\u673a\u7684IP<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-u<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u7528\u6237\u540d<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-p<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u5bc6\u7801<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-d<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u540d\u5b57<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-c<\/td>\n<td width=\\\"59%\\\">\u6307\u660ecollection\u7684\u540d\u5b57<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-f<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u8981\u5bfc\u51fa\u90a3\u4e9b\u5217<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-o<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u5230\u8981\u5bfc\u51fa\u7684\u6587\u4ef6\u540d<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-q<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u5bfc\u51fa\u6570\u636e\u7684\u8fc7\u6ee4\u6761\u4ef6<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;type<\/td>\n<td width=\\\"59%\\\">\u6307\u5b9a\u6587\u4ef6\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;authenticationDatabase<\/td>\n<td width=\\\"59%\\\">\u9a8c\u8bc1\u6570\u636e\u7684\u540d\u79f0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>mongoexport\u5907\u4efd\u5b9e\u8df5<br \/>\n\u5907\u4efdapp\u5e93\u4e0b\u7684vast\u96c6\u5408<br \/>\nmongoexport -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d app -c vast -o \/home\/mongod\/backup\/vasts.dat<br \/>\n\u6ce8\uff1a\u5907\u4efd\u6587\u4ef6\u7684\u540d\u5b57\u53ef\u4ee5\u81ea\u5b9a\u4e49\uff0c\u9ed8\u8ba4\u5bfc\u51fa\u4e86JSON\u683c\u5f0f\u7684\u6570\u636e\u3002<br \/>\n\u5bfc\u51faCSV\u683c\u5f0f\u7684\u6570\u636e<br \/>\nmongoexport -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d app -c vast &#8211;type=csv -f id,name -o \/home\/mongod\/backup\/vast_csv.dat<\/p>\n<h3>1.1.2 \u5bfc\u5165\u5de5\u5177mongoimport<\/h3>\n<p>Mongodb\u4e2d\u7684mongoimport\u5de5\u5177\u53ef\u4ee5\u628a\u4e00\u4e2a\u7279\u5b9a\u683c\u5f0f\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u5bfc\u5165\u5230\u6307\u5b9a\u7684collection\u4e2d\u3002\u8be5\u5de5\u5177\u53ef\u4ee5\u5bfc\u5165JSON\u683c\u5f0f\u6570\u636e\uff0c\u4e5f\u53ef\u4ee5\u5bfc\u5165CSV\u683c\u5f0f\u6570\u636e\u3002<br \/>\n\u8be5\u547d\u4ee4\u7684\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\\\"40%\\\">\u53c2\u6570<\/td>\n<td width=\\\"59%\\\">\u53c2\u6570\u8bf4\u660e<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-h<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u5bbf\u4e3b\u673a\u7684IP<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-u<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u7528\u6237\u540d<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-p<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u5bc6\u7801<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-d<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u540d\u5b57<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-c<\/td>\n<td width=\\\"59%\\\">\u6307\u660ecollection\u7684\u540d\u5b57<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-f<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u8981\u5bfc\u51fa\u90a3\u4e9b\u5217<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-o<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u5230\u8981\u5bfc\u51fa\u7684\u6587\u4ef6\u540d<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-q<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u5bfc\u51fa\u6570\u636e\u7684\u8fc7\u6ee4\u6761\u4ef6<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;drop<\/td>\n<td width=\\\"59%\\\">\u63d2\u5165\u4e4b\u524d\u5148\u5220\u9664\u539f\u6709\u7684<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;headerline<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u7b2c\u4e00\u884c\u662f\u5217\u540d\uff0c\u4e0d\u9700\u8981\u5bfc\u5165\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-j<\/td>\n<td width=\\\"59%\\\">\u540c\u65f6\u8fd0\u884c\u7684\u63d2\u5165\u64cd\u4f5c\u6570\uff08\u9ed8\u8ba4\u4e3a1\uff09\uff0c\u5e76\u884c<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;authenticationDatabase<\/td>\n<td width=\\\"59%\\\">\u9a8c\u8bc1\u6570\u636e\u7684\u540d\u79f0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>mongoimport\u6062\u590d\u5b9e\u8df5<br \/>\n\u5c06\u4e4b\u524d\u6062\u590d\u7684\u6570\u636e\u5bfc\u5165<br \/>\nmongoimport -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d app -c vast &#8211;drop \/home\/mongod\/backup\/vasts.dat<br \/>\n\u5c06\u4e4b\u524d\u6062\u590d\u7684CSV\u683c\u5f0f\u6570\u636e\u5bfc\u5165<br \/>\nmongoimport -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d app -c vast &#8211;type=csv &#8211;headerline &#8211;file vast_csv.dat<\/p>\n<h3>1.1.3 \u3010\u5b9e\u9a8c\u3011mysql\u6570\u636e\u8fc1\u79fb\u81f3mongodb\u6570\u636e\u5e93<\/h3>\n<p>mysql\u76f8\u5173\u7684\u53c2\u8003\u6587\u6863\uff1a<a href=\\\"http:\/\/www.cnblogs.com\/clsn\/category\/1131345.html\\\">http:\/\/www.cnblogs.com\/clsn\/category\/1131345.html<\/a><br \/>\n\u5c06mysql\u6570\u636e\u5e93\u4e2d\u7684mysql\u4e0b\u7684user\u8868\u5bfc\u51fa\u3002<br \/>\nselect user,host,password from mysql.user into outfile \\&#8217;\/tmp\/user.csv\\&#8217; fields terminated by \\&#8217;,\\&#8217; optionally enclosed by \\&#8217;\\&#8221;\\&#8217; escaped by \\&#8217;\\&#8221;\\&#8217; lines terminated by \\&#8217;\\\\r\\\\n\\&#8217;;<br \/>\n\u547d\u4ee4\u8bf4\u660e\uff1a<br \/>\ninto outfile \\&#8217;\/tmp\/user.csv\\&#8217; &#8212;&#8212;\u5bfc\u51fa\u6587\u4ef6\u4f4d\u7f6e fields terminated by \\&#8217;,\\&#8217;\u3000\u3000 &#8212;&#8212;\u5b57\u6bb5\u95f4\u4ee5,\u53f7\u5206\u9694 optionally enclosed by \\&#8217;\\&#8221;\\&#8217;\u3000 &#8212;&#8212;\u5b57\u6bb5\u7528\\&#8221;\u53f7\u62ec\u8d77 escaped by \\&#8217;\\&#8221;\\&#8217; \u3000\u3000\u3000\u3000\u3000 \u3000&#8212;&#8212;\u5b57\u6bb5\u4e2d\u4f7f\u7528\u7684\u8f6c\u4e49\u7b26\u4e3a\\&#8221; lines terminated by \\&#8217;\\\\r\\\\n\\&#8217;; \u3000&#8212;&#8212;\u884c\u4ee5\\\\r\\\\n\u7ed3\u675f<br \/>\n\u67e5\u770b\u5bfc\u51fa\u5185\u5bb9<br \/>\n[mongod@MongoDB tmp]$ cat user.csv \\&#8221;root\\&#8221;,\\&#8221;localhost\\&#8221;,\\&#8221;\\&#8221; \\&#8221;root\\&#8221;,\\&#8221;db02\\&#8221;,\\&#8221;\\&#8221; \\&#8221;root\\&#8221;,\\&#8221;127.0.0.1\\&#8221;,\\&#8221;\\&#8221; \\&#8221;root\\&#8221;,\\&#8221;::1\\&#8221;,\\&#8221;\\&#8221; \\&#8221;\\&#8221;,\\&#8221;localhost\\&#8221;,\\&#8221;\\&#8221; \\&#8221;\\&#8221;,\\&#8221;db02\\&#8221;,\\&#8221;\\&#8221; \\&#8221;repl\\&#8221;,\\&#8221;10.0.0.%\\&#8221;,\\&#8221;*23AE809DDACAF96AF0FD78ED04B6A265E05AA257\\&#8221; \\&#8221;mha\\&#8221;,\\&#8221;10.0.0.%\\&#8221;,\\&#8221;*F4C9AC49A736981AE2739FC2F4A1FD92B4F07929\\&#8221;<br \/>\n\u5728mongodb\u4e2d\u5bfc\u5165\u6570\u636e<br \/>\nmongoimport -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d app -c user -f user,host,password &#8211;type=csv &#8211;file \/tmp\/user.csv<br \/>\n\u67e5\u770b\u5bfc\u5165\u7684\u5185\u5bb9<br \/>\n[root@MongoDB tmp]# mongo &#8211;port 27017 MongoDB shell version: 3.2.8 connecting to: 127.0.0.1:27017\/test &gt; use app switched to db app &gt; db.user.find() { \\&#8221;_id\\&#8221; : ObjectId(\\&#8221;5a53206b3b42ae4683180009\\&#8221;), \\&#8221;user\\&#8221; : \\&#8221;root\\\\tlocalhost\\&#8221; } { \\&#8221;_id\\&#8221; : ObjectId(\\&#8221;5a53206b3b42ae468318000a\\&#8221;), \\&#8221;user\\&#8221; : \\&#8221;root\\\\tdb02\\&#8221; } { \\&#8221;_id\\&#8221; : ObjectId(\\&#8221;5a53206b3b42ae468318000b\\&#8221;), \\&#8221;user\\&#8221; : \\&#8221;root\\\\t127.0.0.1\\&#8221; } { \\&#8221;_id\\&#8221; : ObjectId(\\&#8221;5a53206b3b42ae468318000c\\&#8221;), \\&#8221;user\\&#8221; : \\&#8221;root\\\\t::1\\&#8221; } { \\&#8221;_id\\&#8221; : ObjectId(\\&#8221;5a53206b3b42ae468318000d\\&#8221;), \\&#8221;user\\&#8221; : \\&#8221;localhost\\&#8221; } { \\&#8221;_id\\&#8221; : ObjectId(\\&#8221;5a53206b3b42ae468318000e\\&#8221;), \\&#8221;user\\&#8221; : \\&#8221;db02\\&#8221; } { \\&#8221;_id\\&#8221; : ObjectId(\\&#8221;5a53206b3b42ae468318000f\\&#8221;), \\&#8221;user\\&#8221; : \\&#8221;repl\\\\t10.0.0.%\\\\t*23AE809DDACAF96AF0FD78ED04B6A265E05AA257\\&#8221; } { \\&#8221;_id\\&#8221; : ObjectId(\\&#8221;5a53206b3b42ae4683180010\\&#8221;), \\&#8221;user\\&#8221; : \\&#8221;mha\\\\t10.0.0.%\\\\t*F4C9AC49A736981AE2739FC2F4A1FD92B4F07929\\&#8221; }<br \/>\n\u5230\u6b64\u6570\u636e\u8fc1\u79fb\u5b8c\u6210\u3002<\/p>\n<h2>1.2 mongodump\/mongorestore\u5b9e\u8df5<\/h2>\n<h3>1.2.1 mongodump\u5907\u4efd\u5de5\u5177<\/h3>\n<p>mongodump\u7684\u53c2\u6570\u4e0emongoexport\u7684\u53c2\u6570\u57fa\u672c\u4e00\u81f4<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\\\"40%\\\">\u53c2\u6570<\/td>\n<td width=\\\"59%\\\">\u53c2\u6570\u8bf4\u660e<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-h<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u5bbf\u4e3b\u673a\u7684IP<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-u<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u7528\u6237\u540d<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-p<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u5bc6\u7801<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-d<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u540d\u5b57<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-c<\/td>\n<td width=\\\"59%\\\">\u6307\u660ecollection\u7684\u540d\u5b57<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-o<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u5230\u8981\u5bfc\u51fa\u7684\u6587\u4ef6\u540d<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-q<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u5bfc\u51fa\u6570\u636e\u7684\u8fc7\u6ee4\u6761\u4ef6<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;authenticationDatabase<\/td>\n<td width=\\\"59%\\\">\u9a8c\u8bc1\u6570\u636e\u7684\u540d\u79f0<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;gzip<\/td>\n<td width=\\\"59%\\\">\u5907\u4efd\u65f6\u538b\u7f29<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;oplog<\/td>\n<td width=\\\"59%\\\">use oplog for taking a point-in-time snapshot<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>mongodump\u53c2\u6570\u5b9e\u8df5<br \/>\n\u5168\u5e93\u5907\u4efd<br \/>\nmongodump -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -o \/home\/mongod\/backup\/full<br \/>\n\u5907\u4efdtest\u5e93<br \/>\nmongodump -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test -o \/home\/mongod\/backup\/<br \/>\n\u5907\u4efdtest\u5e93\u4e0b\u7684vast\u96c6\u5408<br \/>\nmongodump -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test -c vast -o \/home\/mongod\/backup\/<br \/>\n\u538b\u7f29\u5907\u4efd\u5e93<br \/>\nmongodump -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test -o \/home\/mongod\/backup\/ &#8211;gzip<br \/>\n\u538b\u7f29\u5907\u4efd\u5355\u8868<br \/>\nmongodump -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test -c vast -o \/home\/mongod\/backup\/ &#8211;gzip<\/p>\n<h3>1.2.2 mongorestore\u6062\u590d\u5b9e\u8df5<\/h3>\n<p>mongorestore\u4e0emongoimport\u53c2\u6570\u7c7b\u4f3c<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\\\"40%\\\">\u53c2\u6570<\/td>\n<td width=\\\"59%\\\">\u53c2\u6570\u8bf4\u660e<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-h<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u5bbf\u4e3b\u673a\u7684IP<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-u<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u7528\u6237\u540d<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-p<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u5bc6\u7801<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-d<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u6570\u636e\u5e93\u7684\u540d\u5b57<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-c<\/td>\n<td width=\\\"59%\\\">\u6307\u660ecollection\u7684\u540d\u5b57<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-o<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u5230\u8981\u5bfc\u51fa\u7684\u6587\u4ef6\u540d<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">-q<\/td>\n<td width=\\\"59%\\\">\u6307\u660e\u5bfc\u51fa\u6570\u636e\u7684\u8fc7\u6ee4\u6761\u4ef6<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;authenticationDatabase<\/td>\n<td width=\\\"59%\\\">\u9a8c\u8bc1\u6570\u636e\u7684\u540d\u79f0<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;gzip<\/td>\n<td width=\\\"59%\\\">\u5907\u4efd\u65f6\u538b\u7f29<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;oplog<\/td>\n<td width=\\\"59%\\\">use oplog for taking a point-in-time snapshot<\/td>\n<\/tr>\n<tr>\n<td width=\\\"40%\\\">&#8211;drop<\/td>\n<td width=\\\"59%\\\">\u6062\u590d\u7684\u65f6\u5019\u628a\u4e4b\u524d\u7684\u96c6\u5408drop\u6389<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5168\u5e93\u5907\u4efd\u4e2d\u6062\u590d\u5355\u5e93\uff08\u57fa\u4e8e\u4e4b\u524d\u7684\u5168\u5e93\u5907\u4efd\uff09<br \/>\nmongorestore -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test &#8211;drop \/home\/mongod\/backup\/full\/test\/<br \/>\n\u6062\u590dtest\u5e93<br \/>\nmongorestore -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test \/home\/mongod\/backup\/test\/<br \/>\n\u6062\u590dtest\u5e93\u4e0b\u7684vast\u96c6\u5408<br \/>\nmongorestore -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test -c vast \/home\/mongod\/backup\/test\/vast.bson<br \/>\n&#8211;drop\u53c2\u6570\u5b9e\u8df5\u6062\u590d<br \/>\n# \u6062\u590d\u5355\u5e93 mongorestore -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test &#8211;drop \/home\/mongod\/backup\/test\/ # \u6062\u590d\u5355\u8868 mongorestore -h 10.0.0.152:27017 -uroot -proot &#8211;authenticationDatabase admin -d test -c vast &#8211;drop \/home\/mongod\/backup\/test\/vast.bson<\/p>\n<h3>1.2.3 mongoexport\/mongoimport\u4e0emongodump\/mongorestore\u7684\u5bf9\u6bd4<\/h3>\n<ol>\n<li>mongoexport\/mongoimport\u5bfc\u5165\/\u5bfc\u51fa\u7684\u662fJSON\u683c\u5f0f\uff0c\u800cmongodump\/mongorestore\u5bfc\u5165\/\u5bfc\u51fa\u7684\u662fBSON\u683c\u5f0f\u3002<\/li>\n<li>JSON\u53ef\u8bfb\u6027\u5f3a\u4f46\u4f53\u79ef\u8f83\u5927\uff0cBSON\u5219\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u4f53\u79ef\u5c0f\u4f46\u5bf9\u4eba\u7c7b\u51e0\u4e4e\u6ca1\u6709\u53ef\u8bfb\u6027\u3002<\/li>\n<li>\u5728\u4e00\u4e9bmongodb\u7248\u672c\u4e4b\u95f4\uff0cBSON\u683c\u5f0f\u53ef\u80fd\u4f1a\u968f\u7248\u672c\u4e0d\u540c\u800c\u6709\u6240\u4e0d\u540c\uff0c\u6240\u4ee5\u4e0d\u540c\u7248\u672c\u4e4b\u95f4\u7528mongodump\/mongorestore\u53ef\u80fd\u4e0d\u4f1a\u6210\u529f\uff0c\u5177\u4f53\u8981\u770b\u7248\u672c\u4e4b\u95f4\u7684\u517c\u5bb9\u6027\u3002\u5f53\u65e0\u6cd5\u4f7f\u7528BSON\u8fdb\u884c\u8de8\u7248\u672c\u7684\u6570\u636e\u8fc1\u79fb\u7684\u65f6\u5019\uff0c\u4f7f\u7528JSON\u683c\u5f0f\u5373mongoexport\/mongoimport\u662f\u4e00\u4e2a\u53ef\u9009\u9879\u3002\u8de8\u7248\u672c\u7684mongodump\/mongorestore\u5e76\u4e0d\u63a8\u8350\uff0c\u5b9e\u5728\u8981\u505a\u8bf7\u5148\u68c0\u67e5\u6587\u6863\u770b\u4e24\u4e2a\u7248\u672c\u662f\u5426\u517c\u5bb9\uff08\u5927\u90e8\u5206\u65f6\u5019\u662f\u7684\uff09\u3002<\/li>\n<li>JSON\u867d\u7136\u5177\u6709\u8f83\u597d\u7684\u8de8\u7248\u672c\u901a\u7528\u6027\uff0c\u4f46\u5176\u53ea\u4fdd\u7559\u4e86\u6570\u636e\u90e8\u5206\uff0c\u4e0d\u4fdd\u7559\u7d22\u5f15\uff0c\u8d26\u6237\u7b49\u5176\u4ed6\u57fa\u7840\u4fe1\u606f\u3002\u4f7f\u7528\u65f6\u5e94\u8be5\u6ce8\u610f\u3002<\/li>\n<\/ol>\n<h2>1.3 MongoDB\u4e2d\u7684oplog<\/h2>\n<h3>1.3.1 \u4ec0\u4e48\u662foplog<\/h3>\n<p>MongoDB \u7684Replication\u662f\u901a\u8fc7\u4e00\u4e2a\u65e5\u5fd7\u6765\u5b58\u50a8\u5199\u64cd\u4f5c\u7684\uff0c\u8fd9\u4e2a\u65e5\u5fd7\u5c31\u53eb\u505aoplog\u3002<br \/>\n\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b,oplog\u5206\u914d\u7684\u662f5%\u7684\u7a7a\u95f2\u78c1\u76d8\u7a7a\u95f4\u3002\u901a\u5e38\u800c\u8a00,\u8fd9\u662f\u4e00\u79cd\u5408\u7406\u7684\u8bbe\u7f6e\u3002\u53ef\u4ee5\u901a\u8fc7mongod &#8211;oplogSize\u6765\u6539\u53d8oplog\u7684\u65e5\u5fd7\u5927\u5c0f\u3002<br \/>\noplog\u662fcapped collection\uff0c\u56e0\u4e3aoplog\u7684\u7279\u70b9\uff08\u4e0d\u80fd\u592a\u591a\u628a\u78c1\u76d8\u586b\u6ee1\u4e86\uff0c\u56fa\u5b9a\u5927\u5c0f\uff09\u9700\u8981\uff0cMongoDB\u624d\u53d1\u660e\u4e86capped collection\uff08the oplog is actually the reason capped collections were invented\uff09. \u5b9a\u503c\u5927\u5c0f\u7684\u96c6\u5408\uff0coplogSizeMB: 2048\uff0coplog\u662f\u5177\u6709\u5e42\u7b49\u6027\uff0c\u6267\u884c\u8fc7\u540e\u7684\u4e0d\u4f1a\u53cd\u590d\u6267\u884c\u3002<br \/>\n\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0coplog\u4e3areplica set\u6216\u8005master\/slave\u6a21\u5f0f\u4e13\u7528\uff08standalone\u6a21\u5f0f\u8fd0\u884cmongodb\u5e76\u4e0d\u63a8\u8350\uff09\u3002<br \/>\noplog\u7684\u4f4d\u7f6e\uff1a<br \/>\noplog\u5728local\u5e93\uff1a local\u3002oplog<br \/>\nmaster\/slave \u67b6\u6784\u4e0b\uff1alocal.oplog.$main;<br \/>\nreplica sets \u67b6\u6784\u4e0b\uff1alocal.oplog.rs<br \/>\n\u53c2\u6570\u8bf4\u660e<br \/>\n$ mongodump &#8211;help &#8211;oplog use oplog for taking a point-in-time snapshot<br \/>\n\u8be5\u53c2\u6570\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u5728\u5bfc\u51fa\u7684\u540c\u65f6\u751f\u6210\u4e00\u4e2aoplog.bson\u6587\u4ef6\uff0c\u5b58\u653e\u5728\u4f60\u5f00\u59cb\u8fdb\u884cdump\u5230dump\u7ed3\u675f\u4e4b\u95f4\u6240\u6709\u7684oplog\u3002<br \/>\noplog \u5b98\u65b9\u8bf4\u660e<a href=\\\"https:\/\/docs.mongodb.com\/manual\/core\/replica-set-oplog\/\\\">https:\/\/docs.mongodb.com\/manual\/core\/replica-set-oplog\/<\/a><br \/>\n\u7b80\u5355\u5730\u8bf4\uff0c\u5728replica set\u4e2doplog\u662f\u4e00\u4e2a\u5b9a\u5bb9\u96c6\u5408\uff08capped collection\uff09\uff0c\u5b83\u7684\u9ed8\u8ba4\u5927\u5c0f\u662f\u78c1\u76d8\u7a7a\u95f4\u76845%\uff08\u53ef\u4ee5\u901a\u8fc7&#8211;oplogSizeMB\u53c2\u6570\u4fee\u6539\uff09\uff0c\u4f4d\u4e8elocal\u5e93\u7684db.oplog.rs\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u770b\u770b\u91cc\u9762\u5230\u5e95\u6709\u4e9b\u4ec0\u4e48\u5185\u5bb9\u3002<br \/>\n\u5176\u4e2d\u8bb0\u5f55\u7684\u662f\u6574\u4e2amongod\u5b9e\u4f8b\u4e00\u6bb5\u65f6\u95f4\u5185\u6570\u636e\u5e93\u7684\u6240\u6709\u53d8\u66f4\uff08\u63d2\u5165\/\u66f4\u65b0\/\u5220\u9664\uff09\u64cd\u4f5c\u3002\u5f53\u7a7a\u95f4\u7528\u5b8c\u65f6\u65b0\u8bb0\u5f55\u81ea\u52a8\u8986\u76d6\u6700\u8001\u7684\u8bb0\u5f55\u3002<br \/>\n\u6240\u4ee5\u4ece\u65f6\u95f4\u8f74\u4e0a\u770b\uff0coplog\u7684\u8986\u76d6\u8303\u56f4\u5927\u6982\u662f\u8fd9\u6837\u7684\uff1a<br \/>\n\u5176\u8986\u76d6\u8303\u56f4\u88ab\u79f0\u4f5coplog\u65f6\u95f4\u7a97\u53e3\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u56e0\u4e3aoplog\u662f\u4e00\u4e2a\u5b9a\u5bb9\u96c6\u5408\uff0c\u6240\u4ee5\u65f6\u95f4\u7a97\u53e3\u80fd\u8986\u76d6\u7684\u8303\u56f4\u4f1a\u56e0\u4e3a\u4f60\u5355\u4f4d\u65f6\u95f4\u5185\u7684\u66f4\u65b0\u6b21\u6570\u4e0d\u540c\u800c\u53d8\u5316\u3002\u60f3\u8981\u67e5\u770b\u5f53\u524d\u7684oplog\u65f6\u95f4\u7a97\u53e3\u9884\u8ba1\u503c.<br \/>\nsh1:PRIMARY&gt; rs.printReplicationInfo() configured oplog size: 2048MB &lt;&#8211;\u96c6\u5408\u5927\u5c0f log length start to end: 305451secs (84.85hrs) &lt;&#8211;\u9884\u8ba1\u7a97\u53e3\u8986\u76d6\u65f6\u95f4 oplog first event time: Thu Jan 04 2018 19:39:05 GMT+0800 (CST) oplog last event time: Mon Jan 08 2018 08:29:56 GMT+0800 (CST) now: Mon Jan 08 2018 16:33:25 GMT+0800 (CST)<br \/>\noplog\u6709\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u7279\u6027\u2014\u2014\u5e42\u7b49\u6027\uff08idempotent\uff09\u3002\u5373\u5bf9\u4e00\u4e2a\u6570\u636e\u96c6\u5408\uff0c\u4f7f\u7528oplog\u4e2d\u8bb0\u5f55\u7684\u64cd\u4f5c\u91cd\u653e\u65f6\uff0c\u65e0\u8bba\u88ab\u91cd\u653e\u591a\u5c11\u6b21\uff0c\u5176\u7ed3\u679c\u4f1a\u662f\u4e00\u6837\u7684\u3002<br \/>\n\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679coplog\u4e2d\u8bb0\u5f55\u7684\u662f\u4e00\u4e2a\u63d2\u5165\u64cd\u4f5c\uff0c\u5e76\u4e0d\u4f1a\u56e0\u4e3a\u4f60\u91cd\u653e\u4e86\u4e24\u6b21\uff0c\u6570\u636e\u5e93\u4e2d\u5c31\u5f97\u5230\u4e24\u6761\u76f8\u540c\u7684\u8bb0\u5f55\u3002\u8fd9\u662f\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u7279\u6027.<\/p>\n<h3>1.3.2 oplog.bson\u4f5c\u7528<\/h3>\n<p>\u4e0eoplog\u76f8\u5173\u7684\u53c2\u6570<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\\\"29%\\\">\u53c2\u6570<\/td>\n<td width=\\\"70%\\\">\u53c2\u6570\u8bf4\u660e<\/td>\n<\/tr>\n<tr>\n<td width=\\\"29%\\\">&#8211;oplogReplay<\/td>\n<td width=\\\"70%\\\">\u91cd\u653eoplog.bson\u4e2d\u7684\u64cd\u4f5c\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td width=\\\"29%\\\">&#8211;oplogLimit<\/td>\n<td width=\\\"70%\\\">\u4e0e&#8211;oplogReplay\u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u53ef\u4ee5\u9650\u5236\u91cd\u653e\u5230\u7684\u65f6\u95f4\u70b9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9996\u5148\u8981\u660e\u767d\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u6570\u636e\u4e4b\u95f4\u4e92\u76f8\u6709\u4f9d\u8d56\u6027\uff0c\u6bd4\u5982\u96c6\u5408A\u4e2d\u5b58\u653e\u4e86\u8ba2\u5355\uff0c\u96c6\u5408B\u4e2d\u5b58\u653e\u4e86\u8ba2\u5355\u7684\u6240\u6709\u660e\u7ec6\uff0c\u90a3\u4e48\u53ea\u6709\u4e00\u4e2a\u8ba2\u5355\u6709\u5b8c\u6574\u7684\u660e\u7ec6\u65f6\u624d\u662f\u6b63\u786e\u7684\u72b6\u6001\u3002<br \/>\n\u5047\u8bbe\u5728\u4efb\u610f\u4e00\u4e2a\u65f6\u95f4\u70b9\uff0cA\u548cB\u96c6\u5408\u7684\u6570\u636e\u90fd\u662f\u5b8c\u6574\u5bf9\u5e94\u5e76\u4e14\u6709\u610f\u4e49\u7684\uff08\u5bf9\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u8981\u505a\u5230\u8fd9\u70b9\u5e76\u4e0d\u5bb9\u6613\uff0c\u4e14\u5bf9\u4e8eMongoDB\u6765\u8bf4\u8fd9\u6837\u7684\u6570\u636e\u7ed3\u6784\u5e76\u975e\u5408\u7406\u3002\u4f46\u6b64\u5904\u6211\u4eec\u5047\u8bbe\u8fd9\u4e2a\u6761\u4ef6\u6210\u7acb\uff09\uff0c\u90a3\u4e48\u5982\u679cA\u5904\u4e8e\u65f6\u95f4\u70b9x\uff0c\u800cB\u5904\u4e8ex\u4e4b\u540e\u7684\u4e00\u4e2a\u65f6\u95f4\u70b9y\u65f6\uff0c\u53ef\u4ee5\u60f3\u8c61A\u548cB\u4e2d\u7684\u6570\u636e\u6781\u6709\u53ef\u80fd\u4e0d\u5bf9\u5e94\u800c\u5931\u53bb\u610f\u4e49\u3002<br \/>\nmongodump\u7684\u8fdb\u884c\u8fc7\u7a0b\u4e2d\u5e76\u4e0d\u4f1a\u628a\u6570\u636e\u5e93\u9501\u6b7b\u4ee5\u4fdd\u8bc1\u6574\u4e2a\u5e93\u51bb\u7ed3\u5728\u4e00\u4e2a\u56fa\u5b9a\u7684\u65f6\u95f4\u70b9\uff0c\u8fd9\u5728\u4e1a\u52a1\u4e0a\u5e38\u5e38\u662f\u4e0d\u5141\u8bb8\u7684\u3002\u6240\u4ee5\u5c31\u6709\u4e86dump\u7684\u6700\u7ec8\u7ed3\u679c\u4e2dA\u96c6\u5408\u662f10\u70b9\u6574\u7684\u72b6\u6001\uff0c\u800cB\u96c6\u5408\u5219\u662f10\u70b9\u96f61\u5206\u7684\u72b6\u6001\u8fd9\u79cd\u60c5\u51b5\u3002<br \/>\n\u8fd9\u6837\u7684\u5907\u4efd\u5373\u4f7f\u6062\u590d\u56de\u53bb\uff0c\u53ef\u4ee5\u60f3\u8c61\u5f97\u5230\u7684\u7ed3\u679c\u6050\u6015\u610f\u4e49\u6709\u9650\u3002<br \/>\n\u90a3\u4e48\u4e0a\u9762\u8fd9\u4e2aoplog.bson\u7684\u610f\u4e49\u5c31\u5728\u8fd9\u91cc\u4f53\u73b0\u51fa\u6765\u4e86\u3002\u5982\u679c\u5728dump\u6570\u636e\u7684\u57fa\u7840\u4e0a\uff0c\u518d\u91cd\u505a\u4e00\u904doplog\u4e2d\u8bb0\u5f55\u7684\u6240\u6709\u64cd\u4f5c\uff0c\u8fd9\u65f6\u7684\u6570\u636e\u5c31\u53ef\u4ee5\u4ee3\u8868dump\u7ed3\u675f\u65f6\u90a3\u4e2a\u65f6\u95f4\u70b9\uff08point-in-time\uff09\u7684\u6570\u636e\u5e93\u72b6\u6001\u3002<\/p>\n<h3>1.3.3 \u3010\u6a21\u62df\u3011mongodump\u4f7f\u7528<\/h3>\n<p>\u9996\u5148\u6211\u4eec\u6a21\u62df\u4e00\u4e2a\u4e0d\u65ad\u6709\u63d2\u5165\u64cd\u4f5c\u7684\u96c6\u5408foo\uff0c<br \/>\nuse clsn for(var i = 0; i &lt; 10000; i++) { db.clsn.insert({a: i}); }<br \/>\n\u7136\u540e\u5728\u63d2\u5165\u8fc7\u7a0b\u4e2d\u6a21\u62df\u4e00\u6b21mongodump\u5e76\u6307\u5b9a&#8211;oplog\u3002<br \/>\nmongodump -h 10.0.0.152 &#8211;port 28021 &#8211;oplog -o \/home\/mongod\/backup\/oplog<br \/>\n\u6ce8\u610f\uff1a&#8211;oplog\u9009\u9879\u53ea\u5bf9\u5168\u5e93\u5bfc\u51fa\u6709\u6548\uff0c\u6240\u4ee5\u4e0d\u80fd\u6307\u5b9a-d\u9009\u9879\u3002<br \/>\n\u56e0\u4e3a\u6574\u4e2a\u5b9e\u4f8b\u7684\u53d8\u66f4\u64cd\u4f5c\u90fd\u4f1a\u96c6\u4e2d\u5728local\u5e93\u4e2d\u7684oplog.rs\u96c6\u5408\u4e2d\u3002<br \/>\n\u6839\u636e\u4e0a\u9762\u6240\u8bf4\uff0c\u4ecedump\u5f00\u59cb\u7684\u65f6\u95f4\u7cfb\u7edf\u5c06\u8bb0\u5f55\u6240\u6709\u7684oplog\u5230oplog.bson\u4e2d\uff0c\u6240\u4ee5\u6211\u4eec\u5f97\u5230\u8fd9\u4e9b\u6587\u4ef6\uff1a<br \/>\n[mongod@MongoDB ~]$ ll \/home\/mongod\/backup\/oplog total 8 drwxrwxr-x 2 mongod mongod 4096 Jan 8 16:49 admin drwxrwxr-x 2 mongod mongod 4096 Jan 8 16:49 clsn -rw-rw-r&#8211; 1 mongod mongod 77256 Jan 8 16:49 oplog.bson<br \/>\n\u67e5\u770boplog.bson\u4e2d\u7b2c\u4e00\u6761\u548c\u6700\u540e\u4e00\u6761\u5185\u5bb9<br \/>\n[mongod@MongoDB oplog]$ bsondump oplog.bson &gt;\/tmp\/oplog.bson.tmp [mongod@MongoDB oplog]$ head -1 \/tmp\/oplog.bson.tmp {\\&#8221;ts\\&#8221;:{\\&#8221;$timestamp\\&#8221;:{\\&#8221;t\\&#8221;:1515401553,\\&#8221;i\\&#8221;:666}},\\&#8221;t\\&#8221;:{\\&#8221;$numberLong\\&#8221;:\\&#8221;5\\&#8221;},\\&#8221;h\\&#8221;:{\\&#8221;$numberLong\\&#8221;:\\&#8221;5737315465472464503\\&#8221;},\\&#8221;v\\&#8221;:2,\\&#8221;op\\&#8221;:\\&#8221;i\\&#8221;,\\&#8221;ns\\&#8221;:\\&#8221;clsn.clsn1\\&#8221;,\\&#8221;o\\&#8221;:{\\&#8221;_id\\&#8221;:{\\&#8221;$oid\\&#8221;:\\&#8221;5a533151cc075bd0aa461327\\&#8221;},\\&#8221;a\\&#8221;:3153.0}} [mongod@MongoDB oplog]$ tail -1 \/tmp\/oplog.bson.tmp {\\&#8221;ts\\&#8221;:{\\&#8221;$timestamp\\&#8221;:{\\&#8221;t\\&#8221;:1515401556,\\&#8221;i\\&#8221;:34}},\\&#8221;t\\&#8221;:{\\&#8221;$numberLong\\&#8221;:\\&#8221;5\\&#8221;},\\&#8221;h\\&#8221;:{\\&#8221;$numberLong\\&#8221;:\\&#8221;-7438621314956315593\\&#8221;},\\&#8221;v\\&#8221;:2,\\&#8221;op\\&#8221;:\\&#8221;i\\&#8221;,\\&#8221;ns\\&#8221;:\\&#8221;clsn.clsn1\\&#8221;,\\&#8221;o\\&#8221;:{\\&#8221;_id\\&#8221;:{\\&#8221;$oid\\&#8221;:\\&#8221;5a533154cc075bd0aa4615de\\&#8221;},\\&#8221;a\\&#8221;:3848.0}}<br \/>\n\u6700\u7ec8dump\u51fa\u7684\u6570\u636e\u65e2\u4e0d\u662f\u6700\u5f00\u59cb\u7684\u72b6\u6001\uff0c\u4e5f\u4e0d\u662f\u6700\u540e\u7684\u72b6\u6001\uff0c\u800c\u662f\u4e2d\u95f4\u67d0\u4e2a\u968f\u673a\u72b6\u6001\u3002\u8fd9\u6b63\u662f\u56e0\u4e3a\u96c6\u5408\u4e0d\u65ad\u53d8\u5316\u9020\u6210\u7684\u3002<br \/>\n\u4f7f\u7528mongorestore\u6765\u6062\u590d<br \/>\n[mongod@MongoDB oplog]$ mongorestore -h 10.0.0.152 &#8211;port 28021 &#8211;oplogReplay &#8211;drop \/home\/mongod\/backup\/oplog 2018-01-08T16:59:18.053+0800 building a list of dbs and collections to restore from \/home\/mongod\/backup\/oplog dir 2018-01-08T16:59:18.066+0800 reading metadata for clsn.clsn from \/home\/mongod\/backup\/oplog\/clsn\/clsn.metadata.json 2018-01-08T16:59:18.157+0800 restoring clsn.clsn from \/home\/mongod\/backup\/oplog\/clsn\/clsn.bson 2018-01-08T16:59:18.178+0800 reading metadata for clsn.clsn1 from \/home\/mongod\/backup\/oplog\/clsn\/clsn1.metadata.json 2018-01-08T16:59:18.216+0800 restoring clsn.clsn1 from \/home\/mongod\/backup\/oplog\/clsn\/clsn1.bson 2018-01-08T16:59:18.669+0800 restoring indexes for collection clsn.clsn1 from metadata 2018-01-08T16:59:18.679+0800 finished restoring clsn.clsn1 (3165 documents) 2018-01-08T16:59:19.850+0800 restoring indexes for collection clsn.clsn from metadata 2018-01-08T16:59:19.851+0800 finished restoring clsn.clsn (10000 documents) 2018-01-08T16:59:19.851+0800 replaying oplog 2018-01-08T16:59:19.919+0800 done<br \/>\n\u6ce8\u610f\u9ec4\u5b57\u4f53\uff0c\u7b2c\u4e00\u53e5\u8868\u793aclsn.clsn1\u96c6\u5408\u4e2d\u6062\u590d\u4e863165\u4e2a\u6587\u6863\uff1b\u7b2c\u4e8c\u53e5\u8868\u793a\u91cd\u653e\u4e86oplog\u4e2d\u7684\u6240\u6709\u64cd\u4f5c\u3002\u6240\u4ee5\u7406\u8bba\u4e0aclsn1\u5e94\u8be5\u670916857\u4e2a\u6587\u6863\uff083165\u4e2a\u6765\u81eaclsn.bson\uff0c\u5269\u4e0b\u7684\u6765\u81eaoplog.bson\uff09\u3002\u9a8c\u8bc1\u4e00\u4e0b\uff1a<br \/>\nsh1:PRIMARY&gt; db.clsn1.count() 3849<br \/>\n\u8fd9\u5c31\u662f\u5e26oplog\u7684mongodump\u7684\u771f\u6b63\u4f5c\u7528\u3002<\/p>\n<h3>1.3.4 \u4ece\u522b\u5904\u800c\u6765\u7684oplog<\/h3>\n<p>oplog\u6709\u4e24\u79cd\u6765\u6e90\uff1a<br \/>\n1\u3001mongodump\u65f6\u52a0\u4e0a&#8211;oplog\u9009\u9879\uff0c\u81ea\u52a8\u751f\u6210\u7684oplog\uff0c\u8fd9\u79cd\u65b9\u5f0f\u7684oplog\u76f4\u63a5 &#8211;oplogReplay \u5c31\u53ef\u4ee5\u6062\u590d<br \/>\n2\u3001\u4ece\u522b\u5904\u800c\u6765\uff0c\u9664\u4e86&#8211;oplog\u4e4b\u5916\uff0c\u4eba\u4e3a\u83b7\u53d6\u7684oplog<br \/>\n\u4f8b\u5982\uff1a<br \/>\nmongodump &#8211;port 28021 -d local -c oplog.rs<br \/>\n\u65e2\u7136dump\u51fa\u7684\u6570\u636e\u914d\u5408oplog\u5c31\u53ef\u4ee5\u628a\u6570\u636e\u5e93\u6062\u590d\u5230\u67d0\u4e2a\u72b6\u6001\uff0c\u90a3\u662f\u4e0d\u662f\u62e5\u6709\u4e00\u4efd\u4ece\u67d0\u4e2a\u65f6\u95f4\u70b9\u5f00\u59cb\u5907\u4efd\u7684dump\u6570\u636e\uff0c\u518d\u52a0\u4e0a\u4ecedump\u5f00\u59cb\u4e4b\u540e\u7684oplog\uff0c\u5982\u679coplog\u8db3\u591f\u957f\uff0c\u662f\u4e0d\u662f\u5c31\u53ef\u4ee5\u628a\u6570\u636e\u5e93\u6062\u590d\u5230\u5176\u540e\u7684\u4efb\u610f\u72b6\u6001\u4e86\uff1f\u662f\u7684\uff01<br \/>\n\u4e8b\u5b9e\u4e0areplica set\u6b63\u662f\u4f9d\u8d56oplog\u7684\u91cd\u653e\u673a\u5236\u5728\u5de5\u4f5c\u3002\u5f53secondary\u7b2c\u4e00\u6b21\u52a0\u5165replica set\u65f6\u505a\u7684initial sync\u5c31\u76f8\u5f53\u4e8e\u662f\u5728\u505amongodump\uff0c\u6b64\u540e\u53ea\u9700\u8981\u4e0d\u65ad\u5730\u540c\u6b65\u548c\u91cd\u653eoplog.rs\u4e2d\u7684\u6570\u636e\uff0c\u5c31\u8fbe\u5230\u4e86secondary\u4e0eprimary\u540c\u6b65\u7684\u76ee\u7684\u3002<br \/>\n\u65e2\u7136oplog\u4e00\u76f4\u90fd\u5728oplog.rs\u4e2d\u5b58\u5728\uff0c\u6211\u4eec\u4e3a\u4ec0\u4e48\u8fd8\u9700\u8981\u5728mongodump\u65f6\u6307\u5b9a&#8211;oplog\u5462\uff1f\u9700\u8981\u7684\u65f6\u5019\u4eceoplog.rs\u4e2d\u62ff\u4e0d\u5c31\u5b8c\u4e86\u5417\uff1f\u7b54\u6848\u662f\u80af\u5b9a\u7684\uff0c\u4f60\u786e\u5b9e\u53ef\u4ee5\u53eadump\u6570\u636e\uff0c\u4e0d\u9700\u8981oplog\u3002<br \/>\n\u5728\u9700\u8981\u7684\u65f6\u5019\u53ef\u4ee5\u518d\u4eceoplog.rs\u4e2d\u53d6\u3002\u4f46\u524d\u63d0\u662foplog\u65f6\u95f4\u7a97\u53e3\u5fc5\u987b\u80fd\u591f\u8986\u76d6dump\u7684\u5f00\u59cb\u65f6\u95f4\u3002<br \/>\n\u53ca\u65f6\u70b9\u6062\u590d\u573a\u666f\u6a21\u62df<br \/>\n\u6a21\u62df\u751f\u4ea7\u73af\u5883<br \/>\nfor(i=0;i&lt;300000;i++){ db.oplog.insert({\\&#8221;id\\&#8221;:i,\\&#8221;name\\&#8221;:\\&#8221;shenzheng\\&#8221;,\\&#8221;age\\&#8221;:70,\\&#8221;date\\&#8221;:new Date()}); }<br \/>\n\u63d2\u5165\u6570\u636e\u7684\u540c\u65f6\u5907\u4efd<br \/>\nmongodump -h 10.0.0.152 &#8211;port 28021 &#8211;oplog -o \/home\/mongod\/backup\/config<br \/>\n\u5907\u4efd\u5b8c\u6210\u540e\u8fdb\u884c\u6b21\u9519\u8bef\u7684\u64cd\u4f5c<br \/>\ndb.oplog.remove({});<br \/>\n\u5907\u4efdoplog.rs\u6587\u4ef6<br \/>\nmongodump -h 10.0.0.152 &#8211;port 28021 -d local -c oplog.rs -o \/home\/mongod\/backup\/config\/oplog<br \/>\n\u6062\u590d\u4e4b\u524d\u5907\u4efd\u7684\u6570\u636e<br \/>\nmongorestore -h 10.0.0.152 &#8211;port 28021&#8211;oplogReplay \/home\/mongod\/backup\/config<br \/>\n\u622a\u53d6oplog\uff0c\u627e\u5230\u53d1\u751f\u8bef\u5220\u9664\u7684\u65f6\u95f4\u70b9<br \/>\nbsondump oplog.rs.bson |egrep \\&#8221;\\\\\\&#8221;op\\\\\\&#8221;:\\\\\\&#8221;d\\\\\\&#8221;\\\\,\\\\\\&#8221;ns\\\\\\&#8221;:\\\\\\&#8221;test\\\\.oplog\\\\\\&#8221;\\&#8221; |head -1 \\&#8221;t\\&#8221;:1515379110,\\&#8221;i\\&#8221;:1<br \/>\n\u590d\u5236oplog\u5230\u5907\u4efd\u76ee\u5f55<br \/>\ncp \/home\/mongod\/backup\/config\/oplog\/oplog.rs.bson \/home\/mongod\/backup\/config\/oplog.bson<br \/>\n\u8fdb\u884c\u6062\u590d\uff0c\u6dfb\u52a0\u4e4b\u524d\u627e\u5230\u7684\u8bef\u5220\u9664\u7684\u70b9\uff08limt\uff09<br \/>\nmongorestore -h 10.0.0.152 &#8211;port 28021 &#8211;oplogReplay &#8211;oplogLimit \\&#8221;1515379110:1\\&#8221; \/home\/mongod\/backup\/config<br \/>\n\u81f3\u6b64\u4e00\u6b21\u6062\u590d\u5c31\u5b8c\u6210\u4e86<\/p>\n<h3>1.3.5 mongodb\u7684\u5907\u4efd\u51c6\u5219<\/h3>\n<p>\u53ea\u9488\u5bf9replica\u6216master\/slave\uff0c\u6ee1\u8db3\u8fd9\u4e9b\u51c6\u5219MongoDB\u5c31\u53ef\u4ee5\u8fdb\u884cpoint-in-time\u6062\u590d\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u4efb\u610f\u4e24\u6b21\u6570\u636e\u5907\u4efd\u7684\u65f6\u95f4\u95f4\u9694\uff08\u7b2c\u4e00\u6b21\u5907\u4efd\u5f00\u59cb\u5230\u7b2c\u4e8c\u6b21\u5907\u4efd\u7ed3\u675f\uff09\u4e0d\u80fd\u8d85\u8fc7oplog\u65f6\u95f4\u7a97\u53e3\u8986\u76d6\u8303\u56f4\u3002<\/li>\n<li>\u5728\u4e0a\u6b21\u6570\u636e\u5907\u4efd\u7684\u57fa\u7840\u4e0a\uff0c\u5728oplog\u65f6\u95f4\u7a97\u53e3\u6ca1\u6709\u6ed1\u51fa\u4e0a\u6b21\u5907\u4efd\u7ed3\u675f\u7684\u65f6\u95f4\u70b9\u524d\u8fdb\u884c\u5b8c\u6574\u7684oplog\u5907\u4efd\u3002\u8bf7\u5145\u5206\u8003\u8651oplog\u5907\u4efd\u9700\u8981\u7684\u65f6\u95f4\uff0c\u6743\u8861\u670d\u52a1\u5668\u7a7a\u95f4\u60c5\u51b5\u786e\u5b9aoplog\u5907\u4efd\u95f4\u9694\u3002<\/li>\n<\/ol>\n<p>\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<ol>\n<li>\u8003\u8651\u5230oplog\u65f6\u95f4\u7a97\u53e3\u662f\u4e2a\u53d8\u5316\u503c\uff0c\u8bf7\u5173\u6ce8oplog\u65f6\u95f4\u7a97\u53e3\u7684\u5177\u4f53\u65f6\u95f4\u3002<\/li>\n<li>\u5728\u9760\u8fd1oplog\u65f6\u95f4\u7a97\u53e3\u6ed1\u52a8\u51fa\u6709\u6548\u65f6\u95f4\u4e4b\u524d\u5fc5\u987b\u8981\u6709\u8db3\u591f\u7684\u65f6\u95f4dump\u51fa\u9700\u8981\u7684oplog.rs\uff0c\u8bf7\u9884\u7559\u8db3\u591f\u7684\u65f6\u95f4\uff0c\u4e0d\u8981\u9876\u6ee1\u65f6\u95f4\u7a97\u53e3\u518d\u5907\u4efd\u3002<\/li>\n<li>\u5f53\u707e\u96be\u53d1\u751f\u65f6\uff0c\u7b2c\u4e00\u4ef6\u4e8b\u60c5\u5c31\u662f\u8981\u505c\u6b62\u6570\u636e\u5e93\u7684\u5199\u5165\u64cd\u4f5c\uff0c\u4ee5\u5f80oplog\u6ed1\u51fa\u65f6\u95f4\u7a97\u53e3\u3002\u7279\u522b\u662f\u50cf\u4e0a\u8ff0\u8fd9\u6837\u7684remove({})\u64cd\u4f5c\uff0c\u77ac\u95f4\u5c31\u4f1a\u63d2\u5165\u5927\u91cfd\u8bb0\u5f55\u4ece\u800c\u5bfc\u81f4oplog\u8fc5\u901f\u6ed1\u51fa\u65f6\u95f4\u7a97\u53e3\u3002<\/li>\n<\/ol>\n<p>\u5206\u7247\u96c6\u7fa4\u7684\u5907\u4efd\u6ce8\u610f\u4e8b\u9879<br \/>\n1\u3001\u5907\u4efd\u4ec0\u4e48\uff1f<br \/>\n\uff081\uff09configserver<br \/>\n\uff082\uff09\u6bcf\u4e00\u4e2ashard\u8282\u70b9<br \/>\n2\u3001\u5907\u4efd\u9700\u8981\u6ce8\u610f\u4ec0\u4e48\uff1f<br \/>\n\uff081\uff09\u5143\u6570\u636e\u548c\u771f\u5b9e\u6570\u636e\u8981\u6709\u5bf9\u7b49\u6027\uff08blancer\u8fc1\u79fb\u7684\u95ee\u9898\uff0c\u4f1a\u9020\u6210config\u548cshard\u5907\u4efd\u4e0d\u4e00\u81f4\uff09<br \/>\n\uff082\uff09\u4e0d\u540c\u90e8\u5206\u5907\u4efd\u7ed3\u675f\u65f6\u95f4\u70b9\u4e0d\u4e00\u6837\uff0c\u6062\u590d\u51fa\u6765\u7684\u6570\u636e\u5c31\u662f\u6709\u95ee\u9898\u7684\u3002<\/p>\n<h2>1.4 MongoDB\u76d1\u63a7<\/h2>\n<p>\u4e3a\u4ec0\u4e48\u8981\u76d1\u63a7\uff1f<br \/>\n\u76d1\u63a7\u53ca\u65f6\u83b7\u5f97\u5e94\u7528\u7684\u8fd0\u884c\u72b6\u6001\u4fe1\u606f\uff0c\u5728\u95ee\u9898\u51fa\u73b0\u65f6\u53ca\u65f6\u53d1\u73b0\u3002<br \/>\n\u76d1\u63a7\u4ec0\u4e48\uff1f<br \/>\nCPU\u3001\u5185\u5b58\u3001\u78c1\u76d8I\/O\u3001\u5e94\u7528\u7a0b\u5e8f\uff08MongoDB\uff09\u3001\u8fdb\u7a0b\u76d1\u63a7\uff08ps -aux\uff09\u3001\u9519\u8bef\u65e5\u5fd7\u76d1\u63a7<\/p>\n<h3>1.4.1 MongoDB\u96c6\u7fa4\u76d1\u63a7\u65b9\u5f0f<\/h3>\n<p>db.serverStatus()<br \/>\n\u67e5\u770b\u5b9e\u4f8b\u8fd0\u884c\u72b6\u6001\uff08\u5185\u5b58\u4f7f\u7528\u3001\u9501\u3001\u7528\u6237\u8fde\u63a5\u7b49\u4fe1\u606f\uff09<br \/>\n\u901a\u8fc7\u6bd4\u5bf9\u524d\u540e\u5feb\u7167\u8fdb\u884c\u6027\u80fd\u5206\u6790<br \/>\n\\&#8221;connections\\&#8221; # \u5f53\u524d\u8fde\u63a5\u5230\u672c\u673a\u5904\u4e8e\u6d3b\u52a8\u72b6\u6001\u7684\u8fde\u63a5\u6570 \\&#8221;activeClients\\&#8221; # \u8fde\u63a5\u5230\u5f53\u524d\u5b9e\u4f8b\u5904\u4e8e\u6d3b\u52a8\u72b6\u6001\u7684\u5ba2\u6237\u7aef\u6570\u91cf \\&#8221;locks\\&#8221; # \u9501\u76f8\u5173\u53c2\u6570 \\&#8221;opcounters\\&#8221; # \u542f\u52a8\u4e4b\u540e\u7684\u53c2\u6570 \\&#8221;opcountersRepl\\&#8221; # \u590d\u5236\u60f3\u5173 \\&#8221;storageEngine\\&#8221; # \u67e5\u770b\u6570\u636e\u5e93\u7684\u5b58\u50a8\u5f15\u64ce \\&#8221;mem\\&#8221; # \u5185\u5b58\u76f8\u5173<br \/>\n\u72b6\u6001:<br \/>\ndb.stats()<br \/>\n\u663e\u793a\u4fe1\u606f\u8bf4\u660e\uff1a<br \/>\n\\&#8221;db\\&#8221; : \\&#8221;test\\&#8221; ,\u8868\u793a\u5f53\u524d\u662f\u9488\u5bf9\\&#8221;test\\&#8221;\u8fd9\u4e2a\u6570\u636e\u5e93\u7684\u63cf\u8ff0\u3002\u60f3\u8981\u67e5\u770b\u5176\u4ed6\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u5148\u8fd0\u884c$ use databasename(e.g $use admiin). \u3000\\&#8221;collections\\&#8221; : 3,\u8868\u793a\u5f53\u524d\u6570\u636e\u5e93\u6709\u591a\u5c11\u4e2acollections.\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884cshow collections\u67e5\u770b\u5f53\u524d\u6570\u636e\u5e93\u5177\u4f53\u6709\u54ea\u4e9bcollection. \u3000\\&#8221;objects\\&#8221; : 13\uff0c\u8868\u793a\u5f53\u524d\u6570\u636e\u5e93\u6240\u6709collection\u603b\u5171\u6709\u591a\u5c11\u884c\u6570\u636e\u3002\u663e\u793a\u7684\u6570\u636e\u662f\u4e00\u4e2a\u4f30\u8ba1\u503c\uff0c\u5e76\u4e0d\u662f\u975e\u5e38\u7cbe\u786e\u3002 \u3000\\&#8221;avgObjSize\\&#8221; : 36,\u8868\u793a\u6bcf\u884c\u6570\u636e\u662f\u5927\u5c0f\uff0c\u4e5f\u662f\u4f30\u8ba1\u503c\uff0c\u5355\u4f4d\u662fbytes \u3000\\&#8221;dataSize\\&#8221; : 468,\u8868\u793a\u5f53\u524d\u6570\u636e\u5e93\u6240\u6709\u6570\u636e\u7684\u603b\u5927\u5c0f\uff0c\u4e0d\u662f\u6307\u5360\u6709\u78c1\u76d8\u5927\u5c0f\u3002\u5355\u4f4d\u662fbytes \u3000\\&#8221;storageSize\\&#8221; : 13312,\u8868\u793a\u5f53\u524d\u6570\u636e\u5e93\u5360\u6709\u78c1\u76d8\u5927\u5c0f\uff0c\u5355\u4f4d\u662fbytes,\u56e0\u4e3amongodb\u6709\u9884\u5206\u914d\u7a7a\u95f4\u673a\u5236\uff0c\u4e3a\u4e86\u9632\u6b62\u5f53\u6709\u5927\u91cf\u6570\u636e\u63d2\u5165\u65f6\u5bf9\u78c1\u76d8\u7684\u538b\u529b,\u56e0\u6b64\u4f1a\u4e8b\u5148\u591a\u5206\u914d\u78c1\u76d8\u7a7a\u95f4\u3002 \u3000\\&#8221;numExtents\\&#8221; : 3,\u4f3c\u4e4e\u6ca1\u6709\u4ec0\u4e48\u771f\u5b9e\u610f\u4e49\u3002\u6211\u5f04\u660e\u767d\u4e4b\u540e\u518d\u8be6\u7ec6\u8865\u5145\u8bf4\u660e\u3002 \u3000\\&#8221;indexes\\&#8221; : 1 ,\u8868\u793asystem.indexes\u8868\u6570\u636e\u884c\u6570\u3002 \u3000\\&#8221;indexSize\\&#8221; : 8192,\u8868\u793a\u7d22\u5f15\u5360\u6709\u78c1\u76d8\u5927\u5c0f\u3002\u5355\u4f4d\u662fbytes \\&#8221;fileSize\\&#8221; : 201326592\uff0c\u8868\u793a\u5f53\u524d\u6570\u636e\u5e93\u9884\u5206\u914d\u7684\u6587\u4ef6\u5927\u5c0f\uff0c\u4f8b\u5982test.0,test.1\uff0c\u4e0d\u5305\u62ectest.ns\u3002<\/p>\n<h3>1.4.2 mongostat<\/h3>\n<p>\u5b9e\u65f6\u6570\u636e\u5e93\u72b6\u6001\uff0c\u8bfb\u5199\u3001\u52a0\u9501\u3001\u7d22\u5f15\u547d\u4e2d\u3001\u7f3a\u9875\u4e2d\u65ad\u3001\u8bfb\u5199\u7b49\u5f85\u961f\u5217\u7b49\u60c5\u51b5\u3002<br \/>\n\u6bcf\u79d2\u5237\u65b0\u4e00\u6b21\u72b6\u6001\u503c\uff0c\u5e76\u80fd\u63d0\u4f9b\u826f\u597d\u7684\u53ef\u8bfb\u6027\uff0c\u901a\u8fc7\u8fd9\u4e9b\u53c2\u6570\u53ef\u4ee5\u89c2\u5bdf\u5230MongoDB\u7cfb\u7edf\u6574\u4f53\u6027\u80fd\u60c5\u51b5\u3002<br \/>\n[mongod@MongoDB oplog]$ mongostat -h 10.0.0.152 &#8211;port 28017 insert query update delete getmore command flushes mapped vsize res faults qr|qw ar|aw netIn netOut conn set repl time *0 *0 *0 *0 0 1|0 0 303.0M 13.0M 0 0|0 0|0 143b 8k 1 RTR 2018-01-08T17:28:42+08:00<br \/>\n\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\\\"14%\\\">\u53c2\u6570<\/td>\n<td width=\\\"85%\\\">\u53c2\u6570\u8bf4\u660e<\/td>\n<\/tr>\n<tr>\n<td width=\\\"14%\\\">insert<\/td>\n<td width=\\\"85%\\\">\u6bcf\u79d2\u63d2\u5165\u91cf<\/td>\n<\/tr>\n<tr>\n<td width=\\\"14%\\\">query<\/td>\n<td width=\\\"85%\\\">\u6bcf\u79d2\u67e5\u8be2\u91cf<\/td>\n<\/tr>\n<tr>\n<td width=\\\"14%\\\">update<\/td>\n<td width=\\\"85%\\\">\u6bcf\u79d2\u66f4\u65b0\u91cf<\/td>\n<\/tr>\n<tr>\n<td width=\\\"14%\\\">delete<\/td>\n<td width=\\\"85%\\\">\u6bcf\u79d2\u5220\u9664\u91cf<\/td>\n<\/tr>\n<tr>\n<td width=\\\"14%\\\">conn<\/td>\n<td width=\\\"85%\\\">\u5f53\u524d\u8fde\u63a5\u6570<\/td>\n<\/tr>\n<tr>\n<td width=\\\"14%\\\">qr|qw<\/td>\n<td width=\\\"85%\\\">\u5ba2\u6237\u7aef\u67e5\u8be2\u6392\u961f\u957f\u5ea6\uff08\u8bfb|\u5199\uff09\u6700\u597d\u4e3a0\uff0c\u5982\u679c\u6709\u5806\u79ef\uff0c\u6570\u636e\u5e93\u5904\u7406\u6162\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\\\"14%\\\">ar|aw<\/td>\n<td width=\\\"85%\\\">\u6d3b\u8dc3\u5ba2\u6237\u7aef\u6570\u91cf\uff08\u8bfb|\u5199\uff09<\/td>\n<\/tr>\n<tr>\n<td width=\\\"14%\\\">time<\/td>\n<td width=\\\"85%\\\">\u5f53\u524d\u65f6\u95f4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>mongotop\u547d\u4ee4\u8bf4\u660e\uff1a<br \/>\n[mongod@MongoDB oplog]$ mongotop -h 127.0.0.1:27017 2018-01-08T17:32:56.623+0800 connected to: 127.0.0.1:27017 ns total read write 2018-01-08T17:32:57+08:00 admin.system.roles 0ms 0ms 0ms admin.system.users 0ms 0ms 0ms admin.system.version 0ms 0ms 0ms app.user 0ms 0ms 0ms automationcore.automation.job.status 0ms 0ms 0ms automationcore.config.automation 0ms 0ms 0ms automationcore.config.automationTemplates 0ms 0ms 0ms automationcore.config.automationTemplates_archive 0ms 0ms 0ms automationcore.config.automation_archive 0ms 0ms 0ms automationstatus.lastAgentStatus 0ms 0ms 0ms<br \/>\nmongotop\u91cd\u8981\u6307\u6807<br \/>\nns\uff1a\u6570\u636e\u5e93\u547d\u540d\u7a7a\u95f4\uff0c\u540e\u8005\u7ed3\u5408\u4e86\u6570\u636e\u5e93\u540d\u79f0\u548c\u96c6\u5408\u3002 total\uff1amongod\u5728\u8fd9\u4e2a\u547d\u4ee4\u7a7a\u95f4\u4e0a\u82b1\u8d39\u7684\u603b\u65f6\u95f4\u3002 read\uff1a\u5728\u8fd9\u4e2a\u547d\u4ee4\u7a7a\u95f4\u4e0amongod\u6267\u884c\u8bfb\u64cd\u4f5c\u82b1\u8d39\u7684\u65f6\u95f4\u3002 write\uff1a\u5728\u8fd9\u4e2a\u547d\u540d\u7a7a\u95f4\u4e0amongod\u8fdb\u884c\u5199\u64cd\u4f5c\u82b1\u8d39\u7684\u65f6\u95f4\u3002<\/p>\n<h3>1.4.3 db\u7ea7\u522b\u547d\u4ee4<\/h3>\n<p>db.currentOp()<br \/>\n\u67e5\u770b\u6570\u636e\u5e93\u5f53\u524d\u6267\u884c\u4ec0\u4e48\u64cd\u4f5c\u3002<br \/>\n\u7528\u4e8e\u67e5\u770b\u957f\u65f6\u95f4\u8fd0\u884c\u8fdb\u7a0b\u3002<br \/>\n\u901a\u8fc7\uff08\u6267\u884c\u65f6\u957f\u3001\u64cd\u4f5c\u3001\u9501\u3001\u7b49\u5f85\u9501\u65f6\u957f)\u7b49\u6761\u4ef6\u8fc7\u6ee4\u3002<br \/>\n\u5982\u679c\u53d1\u73b0\u4e00\u4e2a\u64cd\u4f5c\u592a\u957f\uff0c\u628a\u6570\u636e\u5e93\u5361\u6b7b\u7684\u8bdd\uff0c\u53ef\u4ee5\u7528\u8fd9\u4e2a\u547d\u4ee4\u6740\u6b7b\u4ed6\uff1a&gt; db.killOp(608605)<br \/>\ndb.setProfilingLevel()<br \/>\n\u8bbe\u7f6eserver\u7ea7\u522b\u6162\u65e5\u5fd7<br \/>\n\u6253\u5f00profiling\uff1a<br \/>\n0:\u4e0d\u4fdd\u5b58<br \/>\n1:\u4fdd\u5b58\u6162\u67e5\u8be2\u65e5\u5fd7<br \/>\n2:\u4fdd\u5b58\u6240\u6709\u67e5\u8be2\u65e5\u5fd7<br \/>\n\u6ce8\u610f:\u7ea7\u522b\u662f\u5bf9\u5e94\u5f53\u524d\u7684\u6570\u636e\u5e93\uff0c\u800c\u9608\u503c\u662f\u5168\u5c40\u7684\u3002<br \/>\n\u67e5\u770bprofiling\u72b6\u6001<br \/>\n\u67e5\u770b\u6162\u67e5\u8be2\uff1asystem.profile<br \/>\n\u5173\u95edprofiling<br \/>\n\u4f01\u4e1a\u5de5\u5177ops manager\u5b98\u65b9\u6587\u6863\uff1a&nbsp;<a href=\\\"https:\/\/www.cnblogs.com\/clsn\/p\/%20https:\/\/docs.opsmanager.mongodb.com\/v3.6\/\\\">https:\/\/docs.opsmanager.mongodb.com\/v3.6\/<\/a><\/p>\n<h2>1.5 MongoDB\u96c6\u7fa4\u6027\u80fd\u4f18\u5316\u65b9\u6848<\/h2>\n<h3>1.5.1 \u4f18\u5316\u65b9\u5411<\/h3>\n<p>\u786c\u4ef6\uff08\u5185\u5b58\u3001SSD\uff09<br \/>\n\u6536\u7f29\u6570\u636e<br \/>\n\u589e\u52a0\u65b0\u7684\u673a\u5668\u3001\u65b0\u7684\u526f\u672c\u96c6<br \/>\n\u96c6\u7fa4\u5206\u7247\u952e\u9009\u62e9<br \/>\nchunk\u5927\u5c0f\u8bbe\u7f6e<br \/>\n\u9884\u5206\u7247\uff08\u9884\u5148\u5206\u914d\u5b58\u50a8\u7a7a\u95f4\uff09<\/p>\n<h3>1.5.2 \u5b58\u50a8\u5f15\u64ce\u65b9\u9762<\/h3>\n<p>WiredTiger\u662f3.0\u4ee5\u540e\u7684\u9ed8\u8ba4\u5b58\u50a8\u5f15\u64ce\uff0c\u7ec6\u7c92\u5ea6\u7684\u5e76\u53d1\u63a7\u5236\u548c\u6570\u636e\u538b\u7f29\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u6027\u80fd\u548c\u5b58\u50a8\u6548\u7387\u30023.0\u4ee5\u524d\u9ed8\u8ba4\u7684MMAPv1\u4e5f\u63d0\u9ad8\u4e86\u6027\u80fd\u3002<br \/>\n\u5728MongoDB\u590d\u5236\u96c6\u4e2d\u53ef\u4ee5\u7ec4\u5408\u591a\u949f\u5b58\u50a8\u5f15\u64ce\uff0c\u5404\u4e2a\u5b9e\u4f8b\u5b9e\u73b0\u4e0d\u540c\u7684\u5e94\u7528\u9700\u6c42\u3002<\/p>\n<h3>1.5.3 \u5176\u4ed6\u4f18\u5316\u5efa\u8bae<\/h3>\n<p>\u6536\u7f29\u6570\u636e<br \/>\n\u9884\u5206\u7247<br \/>\n\u589e\u52a0\u65b0\u7684\u673a\u5668\u3001\u65b0\u7684\u526f\u672c\u96c6<br \/>\n\u96c6\u7fa4\u5206\u7247\u952e\u9009\u62e9<br \/>\nchunk\u5927\u5c0f\u8bbe\u7f6e<\/p>\n<h2>1.6 \u9644\u5f55\uff1aAliyun \u5907\u4efd\u7b56\u7565<\/h2>\n<h3>1.6.1 MongoDB\u4e91\u6570\u636e\u5e93\u5907\u4efd\/\u6062\u590d<\/h3>\n<p><img src=\\\"https:\/\/images2017.cnblogs.com\/blog\/1190037\/201801\/1190037-20180108183457535-611170065.png\\\"><br \/>\n\u5907\u4efd\u7b56\u7565\uff1a<\/p>\n<ol>\n<li>\u4ecehidden\u8282\u70b9\u5907\u4efd<\/li>\n<li>\u6bcf\u5929\u4e00\u6b21\u5168\u91cf\u5907\u4efd<\/li>\n<li>\u6301\u7eed\u62c9\u53d6oplog\u589e\u91cf\u5907\u4efd<\/li>\n<li>\u5b9a\u671f\u5de1\u68c0\u5907\u4efd\u6709\u6548\u6027<\/li>\n<li>\u6062\u590d\u65f6\u514b\u9686\u5230\u65b0\u5b9e\u4f8b<\/li>\n<\/ol>\n<h3>1.6.2 \u5168\u91cf\u5907\u4efd\u65b9\u6cd5<\/h3>\n<p><img src=\\\"https:\/\/images2017.cnblogs.com\/blog\/1190037\/201801\/1190037-20180108183559394-794158819.png\\\"><\/p>\n<h3>1.6.3 \u903b\u8f91\u5907\u4efd\u6d41\u7a0b &#8211; mongodump<\/h3>\n<p><img src=\\\"https:\/\/images2017.cnblogs.com\/blog\/1190037\/201801\/1190037-20180108183607176-300071779.png\\\"><br \/>\n\u7279\u70b9\uff1a<\/p>\n<ol>\n<li>\u5168\u91cf\u904d\u5386\u6240\u6709\u6570\u636e\u3001<\/li>\n<li>\u5907\u4efd\u3001\u6062\u590d\u6162<\/li>\n<li>\u5bf9\u4e1a\u52a1\u5f71\u54cd\u8f83\u5927<\/li>\n<li>\u65e0\u9700\u5907\u4efd\u7d22\u5f15\u3001\u6062\u590d\u65f6\u91cd\u5efa<\/li>\n<li>\u901a\u7528\u6027\u5f3a<\/li>\n<\/ol>\n<h3>1.6.4 \u7269\u7406\u5907\u4efd\u6d41\u7a0b<\/h3>\n<p><img class=\\\"aligncenter\\\" src=\\\"https:\/\/images2017.cnblogs.com\/blog\/1190037\/201801\/1190037-20180108183621379-438094970.png\\\"><br \/>\n\u5907\u4efd\u7279\u70b9<\/p>\n<ol>\n<li>\u62f7\u8d1d\u6570\u636e\u76ee\u5f55\u6240\u6709\u6587\u4ef6\uff0c\u6548\u7387\u9ad8<\/li>\n<li>\u5907\u4efd\u3001\u6062\u590d\u5feb<\/li>\n<li>\u5bf9\u4e1a\u52a1\u5f71\u54cd\u8f83\u5c0f<\/li>\n<li>\u8ddf\u6570\u636e\u5e93\u7248\u672c\u3001\u914d\u7f6e\u5f3a\u5173\u8054<\/li>\n<\/ol>\n<h3>1.6.5 \u903b\u8f91\u5907\u4efd vs \u7269\u7406\u5907\u4efd<\/h3>\n<table>\n<tbody>\n<tr>\n<td width=\\\"18%\\\"><\/td>\n<td width=\\\"42%\\\">\u903b\u8f91\u5907\u4efd<\/td>\n<td width=\\\"39%\\\">\u7269\u7406\u5907\u4efd<\/td>\n<\/tr>\n<tr>\n<td width=\\\"18%\\\">\u5907\u4efd\u6548\u7387<\/td>\n<td width=\\\"42%\\\">\u4f4e<br \/>\n\u6570\u636e\u5e93\u63a5\u53e3\u8bfb\u53d6\u6570\u636e<\/td>\n<td width=\\\"39%\\\">\u9ad8<br \/>\n\u62f7\u8d1d\u7269\u7406\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td width=\\\"18%\\\">\u6062\u590d\u6548\u7387<\/td>\n<td width=\\\"42%\\\">\u4f4e<br \/>\n\u4e0b\u8f7d\u5907\u4efd\u96c6&nbsp;+&nbsp;&nbsp;\u5bfc\u5165\u6570\u636e&nbsp;+&nbsp;&nbsp;\u5efa\u7acb\u7d22\u5f15<\/td>\n<td width=\\\"39%\\\">\u9ad8<br \/>\n\u4e0b\u8f7d\u5907\u4efd\u96c6&nbsp;+&nbsp;&nbsp;\u542f\u52a8\u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td width=\\\"18%\\\">\u5907\u4efd\u5f71\u54cd<\/td>\n<td width=\\\"42%\\\">\u5927<br \/>\n\u76f4\u63a5\u4e0e\u4e1a\u52a1\u4e89\u62a2\u8d44\u6e90<\/td>\n<td width=\\\"39%\\\">\u5c0f<\/td>\n<\/tr>\n<tr>\n<td width=\\\"18%\\\">\u5907\u4efd\u96c6\u5927\u5c0f<\/td>\n<td width=\\\"42%\\\">\u6bd4\u539f\u5e93\u5c0f<br \/>\n\u65e0\u9700\u5907\u4efd\u7d22\u5f15\u6570\u636e<\/td>\n<td width=\\\"39%\\\">\u4e0e\u539f\u5e93\u76f8\u540c<\/td>\n<\/tr>\n<tr>\n<td width=\\\"18%\\\">\u517c\u5bb9\u6027<\/td>\n<td width=\\\"42%\\\">\u517c\u5bb9\u7edd\u5927\u90e8\u5206\u7248\u672c<br \/>\n\u53ef\u8de8\u5b58\u50a8\u5f15\u64ce<\/td>\n<td width=\\\"39%\\\">\u4f9d\u8d56\u5b58\u50a8\u5e03\u5c40<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>1.1 MongoDB\u7684\u5e38\u7528\u547d\u4ee4 mongoexport \/ mongoimport mongodump \/  &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5416\"> <span class=\"screen-reader-text\">MongoDB\u7684\u5907\u4efd\u4e0e\u6062\u590d<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[107,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"1.1 MongoDB\u7684\u5e38\u7528\u547d\u4ee4 mongoexport \/ mongoimport mongodump \/ &hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5416"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5416"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5416\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5416"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}