简体   繁体   English

如何恢复mongodb中的dump备份

[英]How to restore dump backup in mongodb

I have restore-63bbdc996664dc2524cce24d.tar file, I am restoring it in the MongoDB database我有 restore-63bbdc996664dc2524cce24d.tar 文件,我正在 MongoDB 数据库中恢复它

tried these commands试过这些命令

mongodump --db test --gzip --archive=restore-63bbdc996664dc2524cce24d.tar mongodump --db test --gzip --archive=restore-63bbdc996664dc2524cce24d.tar

mongodump --db test --archive=restore-63bbdc996664dc2524cce24d.tar mongodump --db 测试 --archive=restore-63bbdc996664dc2524cce24d.tar

mongodump --host localhost --port 27017 --db test --gzip --archive=restore-63bbdc996664dc2524cce24d.tar mongodump --host localhost --port 27017 --db test --gzip --archive=restore-63bbdc996664dc2524cce24d.tar

mongorestore --drop C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz -v mongorestore --drop C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz -v

error => Failed: file C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz does not have.bson extension错误=> 失败:文件 C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz 没有 .bson 扩展名

I also tried to convert this file to bson by the command我还尝试通过命令将此文件转换为 bson

bsondump --outFile=C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz coll.bson bsondump --outFile=C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz coll.bson

Can anyone please tell me what should I do to restore the database?谁能告诉我我应该怎么做才能恢复数据库?

Thanks in advance for any comment or answer.提前感谢您的任何评论或回答。

After spending a lot of time on it finally I got the solution花了很多时间之后终于找到了解决方案

1. Extract the tar file
2. Run the below command

mongod --port your_port --dbpath your_extracted_tar_folder

note: port is optional, it will run 27027 default port 
3. Go and connect on the same port that you pass
  1. Extract the archive file using tar -xvf restore-63bbdc996664dc2524cce24d.tar使用tar -xvf restore-63bbdc996664dc2524cce24d.tar提取存档文件
  2. Use mongorestore --db test --drop <path/to/extracted/bson/files> to restore the dump.使用mongorestore --db test --drop <path/to/extracted/bson/files>恢复转储。

Keep in mind that this command will drop any existing collections in that database before restoring, so make sure you have taken necessary backups.请记住,此命令将在还原之前删除该数据库中任何现有的 collections,因此请确保您已进行必要的备份。

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

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