Back up and restore data in Mongo using out-of-the-box tools
In this recipe, we will look at some basic backup and restore operations using utilities such as mongodump
and mongorestore
to back up and restore files.
Getting ready
We will start a single instance of mongod. Refer to the recipe Installing single node MongoDB in Chapter 1, Installing and Starting the Server, to start a mongo instance and connect to it from a mongo shell. We will need some data to backup. If you already have some data in your test database, that will be fine. If not, create some from the countries.geo.json
file available in the code bundle using the following command:
$ mongoimport -c countries -d test --drop countries.geo.json
How to do it…
- With the data in the
test
Get MongoDB Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.