简体   繁体   English

在 mongodb 中是否可以备份和恢复数据库中的特定集合?

[英]in mongodb is it possible to backup and restore a specific collection in database?

In mongodb is it possible to backup and restore a single collection in database?.在 mongodb 中是否可以备份和恢复数据库中的单个集合? Recently came across a database which which started as VM1 (primary) and VM2 (secondary) which at some point it time has failed over to VM2 (new primary) and VM1(New Secondary).最近遇到了一个数据库,它以 VM1(主)和 VM2(辅助)开始,在某个时候它已故障转移到 VM2(新主)和 VM1(新辅助)。 When I took over the database looked at the collection in a database notices one of the collections in the database VM1 is not there in VM2.当我接管数据库时,查看了数据库中的集合,发现数据库 VM1 中的 collections 之一不在 VM2 中。

Is there a way I can backup that specific collection in the database delete the collection and then import it to VM2 (New Primary) in the same database?有没有办法可以备份数据库中的特定集合删除集合,然后将其导入同一数据库中的 VM2(新主)?

To export a specific collection use the below syntax要导出特定集合,请使用以下语法

mongodump --port 27020 mongodump --port 27020
--db test --db 测试
--collection restaurants ——收藏餐厅
--out /mydata/restoredata/ --out /mydata/restoredata/

To import to another VM - do the below要导入另一个 VM - 执行以下操作

mongorestore --port 27017 --db test2 --collection rest2 /mydata/restoredata/test/restaurants.bson --drop mongorestore --port 27017 --db test2 --collection rest2 /mydata/restoredata/test/restaurants.bson --drop

More details here -更多细节在这里 -

https://docs.cloudmanager.mongodb.com/tutorial/restore-single-database/ https://docs.cloudmanager.mongodb.com/tutorial/restore-single-database/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM