[英]mongodump --oplog and per database restore
I need to be able to restore a single database , even a single collection from a backup. 我需要能够从备份还原 单个数据库 ,甚至单个集合。 Since
mongodump --oplog
only applies to a full instance (Replica Set), I made the following procedure to filter only the entries from the db that I want to restore from the oplog.bson generated by the --oplog option. 由于
mongodump --oplog
仅适用于一个完整实例(副本集),我做了如下过程从我想从由--oplog选项生成的oplog.bson恢复DB只过滤条目。 Could someone tell me if this is correct or if I'm missing something? 有人可以告诉我这是正确的还是我缺少什么?
First I restore only the db (the db is test in this example) that I need 首先,我仅还原需要的数据库(此示例中的数据库为test )
mongorestore -d test dump/test
Restore into a random collection the oplog.bson file generated by the --oplog option 将--oplog选项生成的oplog.bson文件还原到随机集合中
mongorestore -d oplog -c oplog dump/oplog.bson
Dump from the restored oplog.bson collection only the documents that refer to the db that I'm restoring 从还原的oplog.bson集合中仅转储引用我正在还原的db的文档
mongodump -d oplog -c oplog -q "{ns:/^test[.]/}" -o oplog
Restore with the --oplogReplay option using the last dump with filtered operations 使用--oplogReplay选项使用最后一个具有过滤操作的转储进行还原
mongorestore --oplogReplay oplog/oplog
Finally I drop the temporary oplog collection. 最后,我删除了临时oplog集合。
mongo --eval "db.getSisterDB('oplog').dropDatabase()"
Thanks in advance! 提前致谢!
Basically, that's one way to do it.. Or you can do extra export
after dumping specific database. 基本上,这是做到这一点的一种方法。或者,您可以在转储特定数据库后进行额外的
export
。
mongoexport -d local -c oplog.rs --query="{ns:/^test[.]/}" -o oplog.dump
2017-10-10T11:51:50.780+0300 connected to: localhost
2017-10-10T11:51:51.737+0300 local.oplog.rs 0
2017-10-10T11:51:51.938+0300 local.oplog.rs 3
2017-10-10T11:51:51.938+0300 exported 3 records
And you have now direct json
dump file what you can read back 现在您有了直接的
json
转储文件,您可以读回
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.