Backup

MongoDB 基於時間戳轉儲 oplog

  • June 12, 2020

我正在嘗試oplog.rs從本地數據庫中轉儲,基於timestamp.

直接從 mongo shell 查詢,但不能從 mongodump

從 mongo shell 查詢

RS1:PRIMARY> db.oplog.rs.find({"ts" : {$gt : Timestamp(1591199252, 0)}})
{ "ts" : Timestamp(1591199252, 1), "t" : NumberLong(2), "h" : NumberLong(0), "v" : 2, "op" : "n", "ns" : "", "wall" : ISODate("2020-06-03T15:47:32.975Z"), "o" : { "msg" : "periodic noop" } }
...

Mongodump 以 anerror或 with結尾0 dumped documents(取決於時間戳值的單引號):

1. 輸出錯誤

$ mongodump $credentials -d local -c oplog.rs --query '{"ts": {"$gt": Timestamp(1591199252, 0)}}' --out ~/test/ 
2020-06-11T16:54:36.317+0200    Failed: error parsing query as Extended JSON: invalid JSON input. Position: 15. Character: T

2. 輸出 0 個轉儲文件

$ mongodump $credentials -d local -c oplog.rs --query '{"ts": {"$gt": "Timestamp(1591199252, 0)"}}' --out ~/test/
2020-06-11T16:59:28.264+0200    writing local.oplog.rs to
2020-06-11T16:59:30.232+0200    done dumping local.oplog.rs (0 documents)

Mongodump 不了解時間戳功能,所以…

mongodump $credentials -d local -c oplog.rs --query '{"ts":{"$timestamp":{"t":1591199252,"i":0}}}' --out /test/

引用自:https://dba.stackexchange.com/questions/268964