Schedule Backup Window for Sharded Clusters

Overview

In a sharded cluster, the balancer process is responsible fordistributing sharded data around the cluster, so that eachshard has roughly the same amount of data.

However, when creating backups from a sharded cluster it is importantthat you disable the balancer while taking backups to ensure that nochunk migrations affect the content of the backup captured by thebackup procedure. Using the procedure outlined in the sectionDisable the Balancer you can manually stop thebalancer process temporarily. As an alternative, you canuse the following procedure to define a balancing window so that the balanceris always disabled during your automated backup operation.

Tip

mongodump and mongorestorecannot be part of a backup strategy for 4.2+ sharded clustersthat have sharded transactions in progress as these tools cannotguarantee a atomicity guarantees of data across the shards.

For 4.2+ sharded clusters with in-progress sharded transactions, forcoordinated backup and restore processes that maintain the atomicityguarantees of transactions across shards, see:

Procedure

If you have an automated backup schedule, you can disable allbalancing operations for a period of time. For instance, consider thefollowing command:

  1. use config
  2. db.settings.update( { _id : "balancer" }, { $set : { activeWindow : { start : "06:00", stop : "23:00" } } }, true )

This operation configures the balancer to run between 6:00am and11:00pm, server time. Schedule your backup operation to run andcomplete outside of this time. Ensure that the backup can completeoutside the window when the balancer is running and that thebalancer can effectively balance the collection among the shardsin the window allotted to each.