{"id":1096,"date":"2018-09-19T05:30:02","date_gmt":"2018-09-19T05:30:02","guid":{"rendered":"http:\/\/www.ipcpu.com\/?p=1096"},"modified":"2018-11-14T05:32:57","modified_gmt":"2018-11-14T05:32:57","slug":"mongodb-inrease","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2018\/09\/mongodb-inrease\/","title":{"rendered":"MongoDB\u589e\u91cf\u5907\u4efd"},"content":{"rendered":"
<\/div>\n

MongoDB\u589e\u91cf\u5907\u4efd.md
\n<\/p>\n

\u6982\u8ff0<\/h2>\n

MongoDB\u526f\u672c\u96c6\u6709oplog\u7528\u6765\u4e3b\u5907\u540c\u6b65\uff0c\u589e\u91cf\u5907\u4efd\u5c31\u662f\u5bf9\u6307\u5b9a\u65f6\u95f4\u6bb5\u7684oplog\u8fdb\u884cdump\uff0c\u7136\u540e\u5728\u67d0\u4e2a\u5168\u91cf\u5907\u4efd\u57fa\u7840\u4e0a\u8fdb\u884c\u56de\u653e\uff0c\u539f\u7406\u548cMySQLbinlog\u589e\u91cf\u5907\u4efd\u4e00\u81f4\u3002<\/p>\n

OPlog<\/h2>\n

Oplog\u662f\u4e00\u79cd\u7279\u6b8a\u7684Capped collections\uff0c\u7279\u6b8a\u4e4b\u5904\u5728\u4e8e\u5b83\u662f\u7cfb\u7edf\u7ea7Collection\uff0c\u8bb0\u5f55\u4e86\u6570\u636e\u5e93\u7684\u6240\u6709\u64cd\u4f5c\uff0c\u96c6\u7fa4\u4e4b\u95f4\u4f9d\u9760Oplog\u8fdb\u884c\u6570\u636e\u540c\u6b65\u3002Oplog\u7684\u5168\u540d\u662flocal.oplog.rs\uff0c\u4f4d\u4e8elocal\u6570\u636e\u4e0b\u3002<\/p>\n

Oplog\u8bb0\u5f55\u7684\u64cd\u4f5c\u8bb0\u5f55\u662f\u5e42\u7b49\u7684(idempotent)\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u591a\u6b21\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\u800c\u4e0d\u4f1a\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u6216\u4e0d\u4e00\u81f4\u3002<\/p>\n

\u8fd9\u91cc\u6211\u4eec\u7b80\u5355\u4ecb\u7ecd\u4e0boplog\u7684\u683c\u5f0f<\/p>\n

\n
{\"ts\":{\"$timestamp\":{\"t\":1541685325,\"i\":2}},\"t\":{\"$numberLong\":\"11\"},\"h\":{\"$numberLong\":\"169245588685612356\"},\"v\":2,\"op\":\"u\",\"ns\":\"iip_shard.qasprope\r\nrties\",\"o2\":{\"_id\":{\"$oid\":\"5be2647ff3e24f580d732aec\"}},\"o\":{\"$set\":{\"officialReadAt\":{\"$date\":\"2018-11-08T13:55:25.516Z\"}}}}<\/code><\/pre>\n<\/div>\n

\u5b57\u6bb5\u5185\u5bb9\u5982\u4e0b\uff0c<\/p>\n

\n

ts\uff1a\u64cd\u4f5c\u53d1\u751f\u65f6\u7684\u65f6\u95f4\u6233\uff0c\u8fd9\u4e2a\u65f6\u95f4\u6233\u5305\u542b\u4e24\u90e8\u5206\u5185\u5bb9t\u548ci\uff0ct\u662f\u6807\u51c6\u7684\u65f6\u95f4\u6233\uff08\u81ea1970\u5e741\u67081\u65e5 00:00:00 GMT \u4ee5\u6765\u7684\u6beb\u79d2\u6570\uff09\u800ci\u662f\u4e00\u4e2a\u5e8f\u53f7\uff0c\u76ee\u7684\u662f\u4e3a\u4e86\u4fdd\u8bc1 t \u4e0e i \u7ec4\u5408\u51fa\u7684 Mongo \u65f6\u95f4\u6233 ts \u53ef\u4ee5\u552f\u4e00\u7684\u786e\u5b9a\u4e00\u6761\u64cd\u4f5c\u8bb0\u5f55
\n op\uff1a\u64cd\u4f5c\u7c7b\u578b\uff0c\u63d2\u5165\u5bf9\u5e94i\uff1b\u66f4\u65b0\u5bf9\u5e94u\uff1b\u5220\u9664\u5bf9\u5e94d\uff1b\u4f46\u6709\u4e00\u79cd\u60c5\u51b5\u662fn\uff0c\u5b83\u8868\u793a\u65e0\u64cd\u4f5c\uff08no-op\uff09\uff0c\u7d27\u7d27\u4ee3\u8868\u4e00\u4e2a\u6d88\u606f\u4fe1\u606f\u3002
\n ns\uff1a\u8fd9\u4e2a\u64cd\u4f5c\u7684\u5e93\u548ccollection\u7684\u7ec4\u5408
\n o\u4e0eo2\uff1a\u4ed6\u4eec\u90fd\u662f\u64cd\u4f5c\u76f8\u5173\u7684\u6570\u636e\u5185\u5bb9<\/p>\n<\/blockquote>\n

\u5bf9\u4e8e\u4e0d\u540c\u7684\u7248\u672c\u7684MongoDB\uff0c\u5176oplog\u7684\u683c\u5f0f\u4e5f\u4e0d\u4e00\u6837\uff0c\u8fd9\u70b9\u9700\u8981\u683c\u5916\u6ce8\u610f\uff08\u6b64\u6587\u4f7f\u7528\u7684\u7248\u672c\u662f3.4.0\uff09\u3002<\/p>\n

Timestamps\u683c\u5f0f\u8be6\u89e3<\/h2>\n

MongoDB\u6709\u4e00\u79cd\u7279\u6b8a\u7684\u65f6\u95f4\u683c\u5f0fTimestamps\uff0c\u4ec5\u7528\u4e8e\u5185\u90e8\u4f7f\u7528\uff0c\u4f8b\u5982\u4e0a\u9762Oplog\u8bb0\u5f55\uff1a<\/p>\n

\n
Timestamp(1503110518, 1)<\/code><\/pre>\n<\/div>\n

Timestamps\u957f\u5ea6\u4e3a64\u4f4d\uff1a<\/p>\n

\n

\u524d32\u4f4d\u662ftime_t\u503c\uff0c\u8868\u793a\u4eceepoch\u65f6\u95f4\u81f3\u4eca\u7684\u79d2\u6570
\n \u540e32\u4f4d\u662fordinal\u503c\uff0c\u8be5\u503c\u662f\u4e00\u4e2a\u987a\u5e8f\u589e\u957f\u7684\u5e8f\u6570\uff0c\u8868\u793a\u67d0\u4e00\u79d2\u5185\u7684\u7b2c\u51e0\u6b21\u64cd\u4f5c<\/p>\n<\/blockquote>\n

\u589e\u91cf\u5bfc\u51fa\u6570\u636e<\/h2>\n

\u4e86\u89e3\u4e86\u6570\u636e\u7ed3\u6784\uff0c\u6211\u4eec\u53ef\u4ee5\u6267\u884cdump\u5bfc\u51fa\u76f8\u5173\u7684\u6570\u636e\u4e86\uff0c\u5982\u4e0b\uff0c<\/p>\n

\n
 mongodump --port 27018 -d local -c oplog.rs -o dump --query \"{ts : { \\$gte : { \\$timestamp : { t : 1519869600, i : 1 } }, \\$lte : { \\$timestamp : { t : 1519956000, i : 1 } } }} \"\r\n\r\n##@@\u53d6\u51fa1519869600\u52301519956000\u4e4b\u95f4\u7684oplog<\/code><\/pre>\n<\/div>\n

TIPS\uff1a\u5bfc\u51fa\u7684bson\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4bsondump oplog.rs.bson \u8f6c\u6362\u6210JSON\u683c\u5f0f\u3002<\/p>\n

\u56de\u653eOPlog<\/p>\n

\n
mongorestore --port 27018 -d local -c oplog.rs oplog.bson<\/code><\/pre>\n<\/div>\n

\u53c2\u8003\u8d44\u6599<\/h2>\n

https:\/\/github.com\/journeyapps\/mongo-oplog-backup\/blob\/master\/lib\/mongo_oplog_backup\/backup.rb<\/a>
\n
https:\/\/cloud.tencent.com\/developer\/article\/1128027<\/a><\/p>\n

<\/p>\n

<\/div>\n
<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n

<\/wiz_tmp_tag><\/p>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » MongoDB\u589e\u91cf\u5907\u4efd<\/a><\/p>","protected":false},"excerpt":{"rendered":"

MongoDB\u589e\u91cf\u5907\u4efd.md \u6982\u8ff0 MongoDB\u526f\u672c\u96c6\u6709oplog\u7528\u6765\u4e3b\u5907\u540c\u6b65\uff0c\u589e\u91cf\u5907\u4efd\u5c31\u662f\u5bf9\u6307\u5b9a\u65f6\u95f4\u6bb5\u7684oplog\u8fdb\u884cdump\uff0c\u7136\u540e\u5728\u67d0\u4e2a\u5168\u91cf\u5907\u4efd\u57fa\u7840\u4e0a\u8fdb\u884c\u56de\u653e\uff0c\u539f\u7406\u548cMySQLbinlog\u589e\u91cf\u5907\u4efd\u4e00\u81f4\u3002 OPlog Oplog\u662f\u4e00\u79cd\u7279\u6b8a\u7684Capped collections\uff0c\u7279\u6b8a\u4e4b\u5904\u5728\u4e8e\u5b83\u662f\u7cfb\u7edf\u7ea7Collection\uff0c\u8bb0\u5f55\u4e86\u6570\u636e\u5e93\u7684\u6240\u6709\u64cd\u4f5c\uff0c\u96c6\u7fa4\u4e4b\u95f4\u4f9d\u9760Oplog\u8fdb\u884c\u6570\u636e\u540c\u6b65\u3002Oplog\u7684\u5168\u540d\u662flocal.oplog.rs\uff0c\u4f4d\u4e8elocal\u6570\u636e\u4e0b\u3002 Oplog\u8bb0\u5f55\u7684\u64cd\u4f5c\u8bb0\u5f55\u662f\u5e42\u7b49\u7684(idempotent)\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u591a\u6b21\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\u800c\u4e0d\u4f1a\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u6216\u4e0d\u4e00\u81f4\u3002 \u8fd9\u91cc\u6211\u4eec\u7b80\u5355\u4ecb\u7ecd\u4e0boplog\u7684\u683c\u5f0f {“ts”:{“$timestamp”:{“t”:1541685325,”i”:2}},”t”:{“$numberLong”:”11″},”h”:{“$numberLong”:”169245588685612356″},”v”:2,”op”:”u”,”ns”:”iip_shard.qasprope rties”,”o2″:{“_id”:{“$oid”:”5be2647ff3e24f580d732aec”}},”o”:{“$set”:{“officialReadAt”:{“$date”:”2018-11-08T13:55:25.516Z”}}}} \u5b57\u6bb5\u5185\u5bb9\u5982\u4e0b\uff0c ts\uff1a\u64cd\u4f5c\u53d1\u751f\u65f6\u7684\u65f6\u95f4\u6233\uff0c\u8fd9\u4e2a\u65f6\u95f4\u6233\u5305\u542b\u4e24\u90e8\u5206\u5185\u5bb9t\u548ci\uff0ct\u662f\u6807\u51c6\u7684\u65f6\u95f4\u6233\uff08\u81ea1970\u5e741\u67081\u65e5 00:00:00 GMT \u4ee5\u6765\u7684\u6beb\u79d2\u6570\uff09\u800ci\u662f\u4e00\u4e2a\u5e8f\u53f7\uff0c\u76ee\u7684\u662f\u4e3a\u4e86\u4fdd\u8bc1 t \u4e0e i \u7ec4\u5408\u51fa\u7684 Mongo \u65f6\u95f4\u6233 ts \u53ef\u4ee5\u552f\u4e00\u7684\u786e\u5b9a\u4e00\u6761\u64cd\u4f5c\u8bb0\u5f55 op\uff1a\u64cd\u4f5c\u7c7b\u578b\uff0c\u63d2\u5165\u5bf9\u5e94i\uff1b\u66f4\u65b0\u5bf9\u5e94u\uff1b\u5220\u9664\u5bf9\u5e94d\uff1b\u4f46\u6709\u4e00\u79cd\u60c5\u51b5\u662fn\uff0c\u5b83\u8868\u793a\u65e0\u64cd\u4f5c\uff08no-op\uff09\uff0c\u7d27\u7d27\u4ee3\u8868\u4e00\u4e2a\u6d88\u606f\u4fe1\u606f\u3002 ns\uff1a\u8fd9\u4e2a\u64cd\u4f5c\u7684\u5e93\u548ccollection\u7684\u7ec4\u5408 o\u4e0eo2\uff1a\u4ed6\u4eec\u90fd\u662f\u64cd\u4f5c\u76f8\u5173\u7684\u6570\u636e\u5185\u5bb9 \u5bf9\u4e8e\u4e0d\u540c\u7684\u7248\u672c\u7684MongoDB\uff0c\u5176oplog\u7684\u683c\u5f0f\u4e5f\u4e0d\u4e00\u6837\uff0c\u8fd9\u70b9\u9700\u8981\u683c\u5916\u6ce8\u610f\uff08\u6b64\u6587\u4f7f\u7528\u7684\u7248\u672c\u662f3.4.0\uff09\u3002 Timestamps\u683c\u5f0f\u8be6\u89e3 MongoDB\u6709\u4e00\u79cd\u7279\u6b8a\u7684\u65f6\u95f4\u683c\u5f0fTimestamps\uff0c\u4ec5\u7528\u4e8e\u5185\u90e8\u4f7f\u7528\uff0c\u4f8b\u5982\u4e0a\u9762Oplog\u8bb0\u5f55\uff1a Timestamp(1503110518, 1) Timestamps\u957f\u5ea6\u4e3a64\u4f4d\uff1a \u524d32\u4f4d\u662ftime_t\u503c\uff0c\u8868\u793a\u4eceepoch\u65f6\u95f4\u81f3\u4eca\u7684\u79d2\u6570 \u540e32\u4f4d\u662fordinal\u503c\uff0c\u8be5\u503c\u662f\u4e00\u4e2a\u987a\u5e8f\u589e\u957f\u7684\u5e8f\u6570\uff0c\u8868\u793a\u67d0\u4e00\u79d2\u5185\u7684\u7b2c\u51e0\u6b21\u64cd\u4f5c \u589e\u91cf\u5bfc\u51fa\u6570\u636e \u4e86\u89e3\u4e86\u6570\u636e\u7ed3\u6784\uff0c\u6211\u4eec\u53ef\u4ee5\u6267\u884cdump\u5bfc\u51fa\u76f8\u5173\u7684\u6570\u636e\u4e86\uff0c\u5982\u4e0b\uff0c mongodump –port 27018 -d local -c oplog.rs -o dump –query “{ts : { \\$gte : { \\$timestamp : { […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,13],"tags":[184,17,130,185],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1096"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1096"}],"version-history":[{"count":2,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1096\/revisions"}],"predecessor-version":[{"id":1103,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1096\/revisions\/1103"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}