In many cases, we will want to have a node that holds a copy of our data at an earlier point in time. This helps to recover from a big subset of human errors, like accidentally dropping a collection, or an upgrade going horrendously wrong.
A delayed replica set member has to be priority = 0 and hidden = true. A delayed replica set member can vote for elections, but will never be visible to clients (hidden = true) and will never become a primary (priority = 0).
An example is as follows:
> cfg = rs.conf()
> cfg.members[0].priority = 0
> cfg.members[0].hidden = true
> cfg.members[0].slaveDelay = 7200
> rs.reconfig(cfg)
This will set the members[0] to a delay of 2 hours. Two important factors for deciding the delta time period between the primary and delayed secondary server are as follows:
- Enough oplog size in the primary
- Enough time for the maintenance to finish before the delayed member starts picking up data
The following table shows the delay of the replica set in hours:
Maintenance window, in hours | Delay | Oplog size on primary, in hours |
0.5 | [0.5,5) | 5 |