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
database, execute the following (assuming we want to export the data to a local directory calleddump
in the current directory):$ mongodump -o dump -oplog -h localhost -port 27017
Verify that there is data in the
dump
directory. All files will be...