简体   繁体   中英

How to restore dump backup in mongodb

I have restore-63bbdc996664dc2524cce24d.tar file, I am restoring it in the MongoDB database

tried these commands

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

mongodump --db test --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

error => Failed: file C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz does not have.bson extension

I also tried to convert this file to bson by the command

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
  2. Use mongorestore --db test --drop <path/to/extracted/bson/files> to restore the dump.

Keep in mind that this command will drop any existing collections in that database before restoring, so make sure you have taken necessary backups.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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