We did some wrong update on a few fields in some documents , can we do mongodump now and restore fresh until before the change with oplogReply or the backup need to be taken before the action?
let say we have: 17:00h update on field
18:00h mongodump
19:00h mongorestore with oplogReply until 16:59h
Is this possible ?
CodePudding user response:
Okey , fixed , based on following steps:
Mongodump the oplog from any of the members of affected rset:
mongodump --db local -c oplog.rs --port 10001 --out /dump 2022-01-20T21:33:52.233 0100 writing local.oplog.rs to /dump/local/oplog.rs.bson 2022-01-20T21:33:52.235 0100 done dumping local.oplog.rs (627 documents)Find the entry before the faulty change:
bsondump /dump/local/oplog.rs ( check the timestamp until where the oplog reply need to happen ) {"op":"n","ns":"","o":{"msg":"periodic noop"},"ts": {"$timestamp":{"t":1642710669,"i":1}},"t": {"$numberLong":"1"},"v":{"$numberLong":"2"},"wall":{"$date":{"$numberLong":"1642710669341"}}}Copy the oplog to different file:
cp /dump/local/oplog.rs.bson /dump/oplogReply the oplog to timestamp before faulty entry to the PRIMARY replicaSet member:
mongorestore --port 10001 --oplogReplay --oplogLimit 1642710669:1 --oplogFile /dump/oplogNow you will see in the database the last faulty changes are removed.
