kubernetes 如何在replicaSet上恢复mongodb备份?

f5emj3cl  于 2022-11-21  发布在  Kubernetes
关注(0)|答案(1)|浏览(210)

我做了一个mongodb(版本4)的本地备份,方法是:

mongodump -u adminUser --authenticationDatabase admin --gzip --archive=/tmp/file.gz --db <dbname>

现在我想将这些数据恢复到我的远程mongodb,它是一个副本集,有两个副本运行在kubernetes集群上。
通常我会用

mongorestore -u adminUser --authenticationDatabase admin --gzip --archive=/tmp/file.gz

但如何在副本集体系结构上执行此恢复?
是否必须在任何Pod示例上运行shell?

kubectl exec -it <pod-name> -n mongodb -- bash
pbossiut

pbossiut1#

需要连接到副本集。需要在连接字符串uri中设置副本集:

mongorestore --uri="mongodb://adminUser:password@hostname1,hostname2,hostname3/?authSource=admin&replicaSet=<replSetName>"

根据文档,您还可以使用--host参数指定副本集

mongorestore -u adminUser --authenticationDatabase admin --host=<replSetName>/hostname1,hostname2,hostname3

mongorestore将连接到“主”成员,数据将还原到该成员,然后复制到“辅助”成员。
如果必须还原大量数据,请考虑通过从其他成员复制数据文件进行同步

相关问题