In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
First, we need to introduce the role of the mongodb local library.
The local library is the system library of MongoDB, which records information such as timestamps and indexes and replication sets.
Test:PRIMARY > use local
Switched to db local
Test:PRIMARY > show tables
System.replset
Me
Startup_log
Replset.minvalid
Oplog.rs
Replset.election
Test:PRIMARY >
What is recorded separately by each collection under the local library
The me collection under the local library holds the server name
The replset.minvalid collection under the local library holds the timestamp of the latest operation in the database.
The startup_log collection under the local library records the startup information of each mongod.
The system.indexes collection under the local library records all index information for the current library
The system.replset under the local library records the member configuration information of the replication set rs.conf () reads this collection
The oplog.rs collection under the local library records all operations, and MongoDB synchronizes data through oplog.rs. When the Primary node inserts a piece of data, there will be one more record in the oplog.rs collection
Op: operation type, insert corresponding I; update corresponding u; delete corresponding d; but in one case, n, which means no operation (no-op), tightly represents a message message.
For example:
Query the insert record in oplog, corresponding to the record whose op is I:
Test:PRIMARY > db.oplog.rs.find ({"op": "I"}). Pretty (). Limit (3)
Check the update operation command:
Test:PRIMARY > db.oplog.rs.find ({"op": "u"}). Pretty (). Limit (3)
Test:PRIMARY >
Check the delete operation command:
Test:PRIMARY > db.oplog.rs.find ({"op": "d"}). Pretty (). Limit (3)
Check the operation according to the time range:
For example:
Find the operation record after September 1, 2017:
Test:PRIMARY > db.oplog.rs.find ({"o.createTime": {$gte:new Date)}) .limit (3)
Check the operation records between September 1 and October 31, 2017:
Test:PRIMARY > db.oplog.rs.find ({"o.createTime": {$gte:new Date), $lte:new Date}) .limit (3)
Let's check all the oplog records that operate on the chenfeng table
Test:PRIMARY > db.oplog.rs.find ({ns: "testdb.chenfeng"})
Check the timestamp of the operation:
Db.oplog.rs.find ({"op": "I", "ns": "testdb.chenfeng",}, {ts:1}) .pretty ()
{"ts": Timestamp (1509246747, 1)}
{"ts": Timestamp (1509246747, 2)}
{"ts": Timestamp (1509246747, 3)}
{"ts": Timestamp (1509246747, 4)}
{"ts": Timestamp (1509246747, 5)}
Timestamp of the current operation time point:
Test:PRIMARY > rs.status (). Members [0] .optime.ts
Timestamp (1509247609, 3001)
How to back up oplog collections:
[root@192 new] # mongodump-- host localhost-- port 9336-uadmin-padmin-- authenticationDatabase=admin-d local-c oplog.rs-o / root/new
2017-10-29T12:36:45.605+0800 writing local.oplog.rs to local/oplog.rs.bson
2017-10-29T12:36:48.606+0800 [#...] Local.oplog.rs 398917Compact 4937240 (8.1%)
2017-10-29T12:36:51.610+0800 [# #.] Local.oplog.rs 812569 Compact 4937240 (16.5%)
2017-10-29T12:36:54.611+0800 [#.] Local.oplog.rs 1208741 Compact 4937240 (24.5%)
2017-10-29T12:36:57.607+0800 [#.] Local.oplog.rs 1570342 Compact 4937240 (31.8%)
2017-10-29T12:37:00.617+0800 [#.] Local.oplog.rs 1948323 Compact 4937240 (39.5%)
2017-10-29T12:37:03.606+0800 [#.] Local.oplog.rs 2346269 Compact 4937240 (47.5%)
2017-10-29T12:37:06.606+0800 [#.] Local.oplog.rs 2741569 Compact 4937240 (55.5%)
2017-10-29T12:37:09.609+0800 [#.] Local.oplog.rs 3137392 Compact 4937240 (63.5%)
2017-10-29T12:37:12.606+0800 [#.] Local.oplog.rs 3533685 Compact 4937240 (71.6%)
2017-10-29T12:37:15.610+0800 [#.] Local.oplog.rs 3897290Compact 4937240 (78.9%)
2017-10-29T12:37:19.672+0800 [#.] Local.oplog.rs 3947430 Compact 4937240 (80.0%)
2017-10-29T12:37:21.609+0800 [#....] Local.oplog.rs 4147978 amp 4937240 (84.0%)
2017-10-29T12:37:24.607+0800 [#...] Local.oplog.rs 4518546 Compact 4937240 (91.5%)
2017-10-29T12:37:27.606+0800 [# #.] Local.oplog.rs 4910376 Compact 4937240 (99.5%)
2017-10-29T12:37:27.758+0800 writing local.oplog.rs metadata to local/oplog.rs.metadata.json
2017-10-29T12:37:27.770+0800 done dumping local.oplog.rs (4937240 documents)
Use bsondump to check the operation record:
Check the insert operation:
# bsondump oplog.rs.bson | grep "\" op\ ":\" I\ "" | head
Check and delete operation:
# bsondump oplog.rs.bson | grep "\" op\ ":\" d\ "" | head
Check update operation:
[root@192 local] # bsondump oplog.rs.bson | grep "\" op\ ":\" u\ "" | head
Restore the oplog collection command:
Mongorestore-host localhost-port 9336-uadmin-padmin-authenticationDatabase=admin-d local-c oplog.rs / root/new/local/oplog.rs.bson
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.