7

Simple question:

$ mongorestore --gzip ./Mongo_DB_dump/restore-8f05kcbfhfbce745735eff49.tar.gz
2020-07-09T18:10:48.207-0500    Failed: file .\Mongo_DB_dump\restore-8f05kcbfhfbce745735eff49.tar.gz does not have .bson extension
2020-07-09T18:10:48.209-0500    0 document(s) restored successfully. 0 document(s) failed to restore.

How can I restore a database using a ´tar.gz´ file if I don't know the name of the database? I'm trying to import a dump from a production instance (MongoDB Cloud) into my local environment. I don't have any previous version of the database in my local if that's relevant.

Edit

I also tried to use mongostore --gzip using the .tar.gz file and also I tried extracting the contents into a .tar file but, with both files I got the following error:

2020-07-09T22:33:07.127-0500    Failed: file .\Mongo_DB_dump\restore-8f05kcbfhfbce745735eff49.tar.gz does not have .bson extension
2020-07-09T22:33:07.128-0500    0 document(s) restored successfully. 0 document(s) failed to restore.

I also tried using /archive:<path-to-file> unsuccessfully:

$ mongorestore --gzip /archive:./Mongo_DB_dump/restore-8f05kcbfhfbce745735eff49.tar.gz
2020-07-09T22:52:59.076-0500    Failed: stream or file does not appear to be a mongodump archive
2020-07-09T22:52:59.077-0500    0 document(s) restored successfully. 0 document(s) failed to restore.

I even attempted to change blindlessly the .tar extension into .bson but that didn't worked out of course:

2020-07-09T22:08:24.175-0500    checking for collection data in Mongo_DB_dump\restore-8f05kcbfhfbce745735eff49.bson
2020-07-09T22:08:24.601-0500    restoring Mongo_DB_dump.restore-8f05kcbfhfbce745735eff49 from Mongo_DB_dump\restore-8f05kcbfhfbce745735eff49.bson
2020-07-09T22:08:24.664-0500    finished restoring Mongo_DB_dump.restore-8f05kcbfhfbce745735eff49 (0 documents, 0 failures)
2020-07-09T22:08:24.664-0500    Failed: Mongo_DB_dump.restore-8f05kcbfhfbce745735eff49: error restoring from Mongo_DB_dump\restore-8f05kcbfhfbce745735eff49.bson: reading bson input: invalid BSONSize: 1953719666 bytes
2020-07-09T22:08:24.664-0500    0 document(s) restored successfully. 0 document(s) failed to restore.
halfer
  • 19,824
  • 17
  • 99
  • 186
Metafaniel
  • 29,318
  • 8
  • 40
  • 67
  • 3
    [mongorestore --gzip](https://docs.mongodb.com/manual/reference/program/mongorestore/index.html#cmdoption-mongorestore-gzip) is used to restore from compressed files created by `mongodump --gzip`. – prasad_ Jul 10 '20 at 03:30
  • @prasad_ Hi, thanks for trying to help. I updated my question accordingly. Thanks! – Metafaniel Jul 10 '20 at 03:43

3 Answers3

14

Just in case someone else run into this problem:

I am currently using db version v4.4.5 and restored the backup in 2 different ways:

  1. If you already have a dumped archive file and compressed it dump.tar.gz , then you can just decompress/extract the archive file first and then restore it with command:

mongorestore --host=localhost --port=27017 --archive dump.tar

  1. Or else, you can directly restore the dump.tar.gz using command:

mongorestore --host=localhost --port=27017 --gzip --archive=dump.tar.gz

Thanks

mudit maurya
  • 141
  • 1
  • 4
0

I just extracted the contents of the .tar.gz file to C:\ProgramData\MongoDB\data\db and overwrite everything there... I'm not very convinced about this one, but at least I was able to work because this way I got the database, collections and documents visible to Mongo Shell. Please share a better answer if you know it.

Metafaniel
  • 29,318
  • 8
  • 40
  • 67
0

On Mac (Big Sur, Intel), I found my MongoDB files in /usr/local/var/mongodb. I then backed up my current mongodb folder and then replaced its contents with the decompressed contents (individual files and folders) of the .tar.gz backup file.

I then restarted my local MongoDB service.

This replaces all of the current data you have locally with the archived file's contents.

This answer is built on top of @Metafaniel's OC.

dmitrizzle
  • 774
  • 6
  • 15