Script Hooks: How to Protect MongoDB with Retrospect

Overview

MongoDB is a popular NoSQL document database on Windows, Mac, and Linux with scalability and flexibility for querying and indexing. It stores data in JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time, and the document model maps to the objects in your application code, making data easy to work with. Ad hoc queries, indexing, and real time aggregation provide powerful ways to access and analyze your data. MongoDB is a distributed database at its core, so high availability, horizontal scaling, and geographic distribution are built in and easy to use. Finally, MongoDB is free and open-source.

With Retrospect, you can protect your live, running MongoDB instance with no downtime. There are two ways to protect MongoDB: backing up its underlying data after quiescing the instance or backing up a data export. We’ll walk through how to do both.

Protect MongoDB via Underlying Data

By default, MongoDB stores data at /data/db on Linux and Mac systems and at C:\data\db on Windows systems. Alternatively, you can specify the location in mongod.conf.

To protect the underlying data while your MongoDB instance is running, we will use Retrospect’s Script Hooks to lock the database from writes before the backup using the StartSource trigger and MongoDB’s db.fsyncLock() and unlock the database after the backup completes using the EndSource trigger and MongoDB’s db.fsyncUnlock(). The database is still readable during this time, but all writes are prevented. You can selectively protect only the MongoDB data store on the system by using a rule/selector to only include the data store path.

Backup Steps

To protect MongoDB, Retrospect or Retrospect Client needs to be running on the same system.

Restore Steps

Protect MongoDB via Data Export

To protect the MongoDB instance via an exported data folder, we will use Retrospect’s Script Hooks to export the data before the backup using the StartSource trigger and MongoDB’s mongodump. Restoring the dump requires MongoDB’s mongorestore. You can selectively protect only the exported MongoDB data store on the system by using a rule/selector to only include the data export path.

Backup Steps

To protect MongoDB, Retrospect or Retrospect Client needs to be running on the same system.