How to Restore from .gz backup using mongorestore?

Restore from .gz backup

Restore from .gz backup / mongorestore to create new DB from .gz backup files

Taking a backup of stage and restoring it to our local database is a common practice followed to test and replicate any issue found on stage or prod. Due to data being transferred from the different channels the team which creates backup or dump of stage/prod DB provides backup as zipped data. So when we restore from .gz backup it becomes more important to unzip data before it gets created to our local mongo store.

  • Command to Restore from .gz backup

The below-mentioned command could be used to restore database dump/backup to a new database.

mongorestore --gzip --archive= directoryname_of_db_import/ --db db_name_to_import

In the above command to create a new database from the .gz dump file directoryname_of_db_import is the location of the directory where the .g files are stored, whereas db_name_to_import is the name of the DB which you would like to keep.

After running this command you will be able to create a new database from the .gz dump files.

If the above solution doesn’t work for you, you can try some other solutions mentioned in the link here.

What is mongorestore?

The mongorestore is a command-line utility used to restore a binary backup created by mongodump command. By default, mongorestore command looks for a database backup in the dump/ directory. mongorestore can restore either an entire database backup or a subset of the backup.

Happy Coding 🙂

How to Restore from .gz backup using mongorestore?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top