Friday 17 April 2015

MongoDB backup tipoff

Using MongoDB for distributed storage and management is suitable when it has been identified that the data is largely going to be looked up and occasionally updated but in any case not going to serve online transactions. But, as with any other database system, back-up mechanisms are just as important here.

I have always used mongoexport and mongoimport to export the mongodb collection data and import it back into another collection. But, I didn't know that it was not a reliable means to backup collection data and restore it when needed.

Here is what I observed. Upon mongoexport with version 2.6, some fields get missed out for some documents.  Further, mongoexport doesn't reliably capture data type information either. For example, NumberLong is not imported back as NumberLong when platform changes occur between the machine from where the data is exported and the machine where it is imported back. For my own use case, this later led to data look up issues when using Morphia.

Always use MongoDump and MongoRestore when you want to backup your data and import it back again. I found it to be reliable as it also stores the data type information explicitly.