Want to do an incremental backup for mongodb. Journaling? Oplog?

Alex Lopatin picture Alex Lopatin · Aug 15, 2012 · Viewed 15k times · Source

I want to daily backups for a single mongodb database, probably with mongodump. To not lose any data, I would like this to be incremental so if something goes wrong in the middle of the day, I need to be able to replay changes for that day up til the point of failure after doing a mongorestore.

Am I understanding correctly that I need to use an oplog for this? Or is journaling the answer? I tried doing the following:

  1. Turning my mongo database into a replica set of just one, so that it creates an oplog. (This feels pretty hacky)
  2. Restarting mongod with the --oplog option
  3. Performing changes that should be recorded in the oplog

However nothing ever gets stored in the oplog. What is the best way to do such incremental backups? I'm basically looking for a similar approach to replaying the mysql binlog.

Thanks

Answer

Jenna picture Jenna · Aug 16, 2012

MongoDB doesn't provide an incremental backup option out of the box, but it's possible to do a file snapshot and replay the oplog. Did you set up your server as a replica set following the steps outlined in the documentation? http://www.mongodb.org/display/DOCS/Replica+Sets+-+Basics

Could you also tell us the purpose of these backups? Have you considered adding a second node to your replica set for data durability?

If you've walked through the steps to set up the server as a member of a replica set, can you run rs.status() in the shell?

One other note (just to clarify)- journaling is not meant to be a backup strategy; journaling merely ensures that the database can return to a consistent state in the event of failover. Running with journaling enabled is highly recommended.

Here is the MongoDB documentation for backups: http://www.mongodb.org/display/DOCS/Backups