Is this a valid backup strategy for MongoDB?

I've got a single dedicated server with a MongoDB database of around 10GB. I need to do daily backups, but I can't have downtime with the database. Is it possible to use a replica set on a single disk (with 2 instances of mongod running on different ports), and simply take the secondary one offline and backup the data files to an offsite storage such as S3 (journaling is turned on)? Or would using master/slave be better than a replica set?

Is this viable, and if so, what potential problems could I have? If not, how do I conceptualize this to work?


Solution 1:

ReplicaSet will work in this scenario. However, I cannot tell if having two MongoDB instances at the same server is a good idea -- this depends on the server hardware/software and load.

To make sure your backup MongoDB node does not become master, set its priority parameter to 0, e.g.

rs.add({_id: 1, host: "localhost:<port>", priority: 0})

NOTE: if you cannot have downtime, you SHOULD have at least 2 primary MongoDB nodes in ReplicaSet, see article

Solution 2:

One strategy to consider is using the "hidden" option on the backup node on your replicaset. From the MongoDB blog:

Hidden servers won’t appear in isMaster() results. This also means that they will not be used if a driver automatically distributes reads to slaves. A hidden server must have a priority of 0 (you can’t have a hidden primary). To add a hidden member, run:

rs.add({"_id" : num, "host" : hostname, "priority" : 0, "hidden" : true})