MongoDB – Import, Backup and Database Restoration

Import bulk data into mongoDB:

The import file looks like:

Bulk operations (useful in sharded environment): Ordered and Unordered

The output:

Backup the database:

The backup process can be done while database is operational.

! The .bson files can be versioned via git.

To restore the database:

Restore of the documents is conditioned by _id: ObjectId(); If the document already exists into current collection, the restore document will be skipped.

In order to find and remove cities based on condition use below statements:

MongoDB Backup options:
  • One mongod process with mongodump
  • One mongod process with file backup system (file system snapshot using LVM (journaling enabled !!!!!)
  • Two or more mongod process with redundant data (running replica 1 | running replica 2) – provides resilience to system failure. Multiple machines are identified as nodes in a replica set. These nodes communicate to identify a master to handle write requests and slaves for read requests. All data is replicated to all nodes.
  • One mongod process with MMS backup – point-in-time backup

If you want to create a hot backup you can use mongodump –oplog and restore with mongorestore –oplogReplay.

For sharded clusters, there are few ops you need to perform during backup: