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

时间:2019-12-04 07:05:26

标签: mongodb bash database-backups

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

我创建了每小时运行一次的完整备份(fsyncLock(),使用“ tar czvf”,fysncUnlock()的快照)和增量备份(mongodump -d local -c oplog.rs -q“(时间戳范围)”)通过以下链接可以在contab(00 * * * *)中进行操作:

Mongodb incremental backups

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

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

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

> 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.

它成功恢复了操作日志,但是在“ local.oplog”下而不是在“ local.oplog.rs”下,并且确实没有在其各自的数据库中重放日志。

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

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

1 个答案:

答案 0 :(得分:0)

只需将您的.bson文件移出“本地”文件夹。然后删除(rm)“本地”文件夹,然后继续进行mongorestore。