Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Mongo restore using filesystem snapshot

Hi,

Can anyone tell me how to restore a replica set using filesystem snapshot (copy of dbpath) without downtime ?

I have simulated by following below process.

  1. Took entire dbpath snapshot
  2. Dropped a database from Primary
  3. Tried restoring it in rolling manner

It’s obvious that even if we will replace secondaries data files with the snapshot, it will again re-issue drop command from Primary’s oplog.

I have found out below process but it will need completed downtime.

  1. Stop all replica set nodes
  2. Replaca data files with recent snapshot
  3. Start all nodes

Is there any other workaround to get back the original data without downtime using only the snapshot ?

Also, is it possible to recover specific DB from snapshots ?

Hi,

Unfortunately I agree with you that I don’t see a method to do a “rolling restore”. A replica set can be used to perform a rolling maintenance, but a restore is a different matter entirely since it is a contradiction of what a replica set is.

Let me explain: all nodes in a replica set should contain the same data, since the main function of a secondary is to be able to take over the primary’s function at a moment’s notice. Therefore, a secondary that has a different data than the primary is by definition not a secondary anymore, so not really part of the replica set anymore.

So it’s not possible to do a rolling restore without downtime (at least when using filesystem snapshot). It is entirely possible if you have a backup of that specific database, though, as all you need to do to restore it is to insert that database into the primary again, so a likely scenario is:

  1. Restore the snapshot to a new standalone server, unconnected to the replica set
  2. Dump the desired database using e.g. mongodump
  3. Restore the database to the replica set’s primary
  4. The secondaries should replicate the restored database

Since filesystem snapshot takes a snapshot of the volume, I don’t believe it’s possible to recover a specific content of the filesystem (database or otherwise) unless the snapshot was restored first.

Best regards,
Kevin

1 Like