MongoDB 4.2 完整备份和新服务器上的增量备份还原



只是一个在这里提问的新手。我希望我的问题不会违反任何规则。

我创建了一个完整备份(fsyncLock((,使用"tar czvf",fysncUnlock(((的快照和增量备份(mongodump -d local -c oplog.rs -q "(timestamp-range("(,通过以下链接每小时在contab(00 * * * *(中运行一次:

Mongodb 增量备份

还使用本机命令mongodump(fsyncLock((,mongodump host dump/,fysncUnlock(((进行完整备份,并使用我上面提到的增量备份的相同策略。

我可以毫无问题地还原完整备份,对于本机 mongodump 完整备份,只需创建一个新实例并还原即可。对于 tar 文件快照,只需解压缩,"mongod -d mongo.cnf",并强制重新配置(rs.reconfig(cfg, {force: true}((副本集,因为在启动时将显示"rs1:OTHER>"。在那之后,我设法使其"主要>",甚至只先运行 1 个实例。

问题是在恢复我的每小时增量备份时,它在运行以下命令时显示此错误:

> mongorestore --port 26017 -uroot --authenticationDatabase admin
> --oplogReplay 20191204-incre/2019-12-04-00:00:01/ Enter password:
> 
> 2019-12-04T14:23:05.456+0800  preparing collections to restore from
> 2019-12-04T14:23:05.456+0800  replaying oplog
> 2019-12-04T14:23:05.609+0800  Failed: restore error: error handling
> transaction oplog entry: error replaying transaction: error extracting
> transaction ops: applyOps field: no such field
> 2019-12-04T14:23:05.609+0800  0 document(s) restored successfully. 0
> document(s) failed to restore.

当我将文件"oplog.rs.bson"重命名为"oplog.bson"并运行以下命令时:

> mongorestore --port 26017 -uroot --authenticationDatabase admin
> --oplogReplay --oplogFile=20191204-incre/2019-12-04-01:00:01/local/oplog.bson 20191204-incre/2019-12-04-01:00:01/ Enter password:
> 
> 2019-12-04T14:10:22.739+0800  preparing collections to restore from
> 2019-12-04T14:10:22.741+0800  restoring to existing collection
> local.oplog without dropping 2019-12-04T14:10:22.741+0800 restoring
> local.oplog from 20191204-incre/2019-12-04-01:00:01/local/oplog.bson
> 2019-12-04T14:10:22.791+0800  no indexes to restore
> 2019-12-04T14:10:22.791+0800  finished restoring local.oplog (1839
> documents, 0 failures) 2019-12-04T14:10:22.791+0800   replaying oplog
> 
> 2019-12-04T14:10:22.915+0800  Failed: restore error: error handling
> transaction oplog entry: error replaying transaction: error extracting
> transaction ops: applyOps field: no such field
> 2019-12-04T14:10:22.915+0800  1839 document(s) restored successfully. 0
> document(s) failed to restore.

它成功地恢复了oplog,但在"local.oplog"而不是"local.oplog.rs"下,它实际上没有在各自的database.collection上重放日志。

rs1:PRIMARY> use local
rs1:PRIMARY> show tables
oplog
oplog.rs
rs1:PRIMARY> db.oplog.count()
3679

我做错了哪一部分?谢谢!

只需将您的.bson文件移出"本地"文件夹即可。然后删除(rm("本地"文件夹并继续mongorestore。

最新更新