我被赋予了为mongodb replicaset设置增量备份的任务,当然我开始搜索它并且在mongodb文档上找不到任何内容,但我确实发现这个question鼓励开发我自己的解决方案,因为没有发现Tayra非常活跃。
我读到了关于oplog的内容,并意识到开发一些东西来重放日志非常容易,但事实证明我没有像mongorestore
那样为我做这件事。
现在我有了一个使用bash脚本的工作解决方案,这很简单,这就是我在这里询问我的逻辑中是否存在任何缺陷,或者将来会咬我的事情的原因。
以下我实施的方式:
完整备份程序:
db.fsyncLock()
db.oplog.rs.find().sort({$natural:-1}).limit(1).next().ts
db.fsyncUnlock()
增量备份程序:
mongodump --host <secondary> -d local -c oplog.rs -o /mnt/mongo-test_backup/1 --query '{ "ts" : { $gt : Timestamp(1437725201, 50) } }'
完整备份恢复程序:
local*
和mongod.lock
此恢复技术称为reconfigure by breaking mirror local
数据库恢复增量备份:
当我们创建增量备份时,它会像这样存储它:
/mnt/mongo-test_backup/1/local/oplog.rs.bson
/mnt/mongo-test_backup/1/local/oplog.rs.metadata.json
我们在oplog.rs.bson上进行了操作,但是我们必须重命名它,所以步骤如下:
cd /mnt/mongo-test_backup/1/local
rm *.json
mv oplog.rs.bson oplog.bson
mongorestore -h <primary> --port <port> --oplogReplay /mnt/mongo-test_backup/1/local
我把它全部编写成脚本,我可能会在github上提交它。
问题是逻辑中是否存在任何缺陷。我有点怀疑,因为程序很直接,但我无法在任何地方找到它。