Skip to content

Commit c93a468

Browse files
kennethdyerjeff-allen-mongojason-price-mongodbjason-price-mongodb
authored
DOCSP-33214 Sharded Cluster Backup (#4976)
* DOCSP-33214 Self-Managed Backups for Sharded Clusters * Backup procedure prep * Backups * Fixes build issue * Tests tutorial * Adds before you begin content * minor text edits * Fixes per Jeff * Fixes rendering error * Fixes rendering error * Fixes rendering error * Fixes per Jeff * Fixes per Jeff * Fixes per Jeff Co-authored-by: Jeff Allen <[email protected]> * Fixes per Jeff * Fixes per Jeff * Fixes per Nandinin * Fixes per Nandinin * Fixes per Nandini * Fixes per Maria * fixes per Maria * Fixes per Ashley * Fixes per Nandini * Fixes per Nandini * Docsp-34017-bucket-rounding-seconds additional updates saved file (#5326) * DOCSP-34017-bucket-rounding-seconds * DOCSP-34017-bucket-rounding-seconds * DOCSP-34017-bucket-rounding-seconds * DOCSP-34017-bucket-rounding-seconds * DOCSP-34017-bucket-rounding-seconds * DOCSP-34017-bucket-rounding-seconds --------- Co-authored-by: jason-price-mongodb <[email protected]> * Removes artifact from another branch * Removes artifact from another branch * Fixes per Tim * Fixes per Tim * Fixes per Tim * Fixes per Tim * Fixes per Tim * Fixes per Jason * Fixes per Jason * fixes per Jason * Fixes per Jason * Fixes per Jason --------- Co-authored-by: Jeff Allen <[email protected]> Co-authored-by: jason-price-mongodb <[email protected]> Co-authored-by: jason-price-mongodb <[email protected]>
1 parent cba97a8 commit c93a468

File tree

2 files changed

+216
-5
lines changed

2 files changed

+216
-5
lines changed
Lines changed: 214 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,224 @@
11
.. _backup-sharded-dumps:
22

3-
=============================================
4-
Back Up a Sharded Cluster with Database Dumps
5-
=============================================
3+
============================================
4+
Back Up Sharded Clusters with Database Dumps
5+
============================================
66

77
.. default-domain:: mongodb
88

9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
914

15+
Starting in MongoDB 7.1, you can back up data on sharded clusters
16+
using :program:`mongodump`.
1017

18+
About this Task
19+
---------------
1120

12-
.. note::
21+
:program:`mongodump` is a utility that creates a binary export of database
22+
content. You can use the ``mongodump`` utility to take self-managed backups of
23+
a sharded cluster.
1324

14-
.. include:: /includes/extracts/sharded-clusters-backup-restore-mongodump-mongorestore-restriction.rst
25+
To take a consistent backup of a sharded cluster with ``mongodump``, you must
26+
first stop the balancer, stop writes, and stop any DDL operations on the
27+
cluster. This ensures that the cluster remains in a consistent state for the
28+
duration of the backup.
29+
30+
MongoDB provides backup and restore operations that can run with the balancer
31+
and running transactions through the following services:
32+
33+
- `MongoDB Atlas <https://www.mongodb.com/atlas/database?tck=docs_server>`_
34+
35+
- `MongoDB Cloud Manager <https://www.mongodb.com/cloud/cloud-manager?tck=docs_server>`_
1536

37+
- `MongoDB Ops Manager <https://www.mongodb.com/products/ops-manager?tck=docs_server>`_
38+
39+
Before you Begin
40+
----------------
41+
42+
This task uses :program:`mongodump` to back up a sharded cluster. Ensure
43+
that you have a cluster running that contains data in sharded collections.
44+
45+
Admin Privileges
46+
~~~~~~~~~~~~~~~~
47+
48+
To perform these tasks, your user must have the :authaction:`fsync`
49+
authorization, which allows the user to run the :dbcommand:`fsync` and
50+
:dbcommand:`fsyncUnlock` commands.
51+
52+
Steps
53+
-----
54+
55+
To take a self-managed backup of a sharded cluster, complete the following
56+
steps:
57+
58+
.. procedure::
59+
:style: normal
60+
61+
.. step:: Find a Backup Window
62+
63+
To find a good time to perform a backup, monitor your application
64+
and database usage to find a time when chunk migrations, resharding,
65+
and DDL operations are unlikely to occur, as these can cause an
66+
inconsistent backup.
67+
68+
For more information, see :ref:`sharded-schedule-backup`.
69+
70+
.. step:: Stop the Balancer
71+
72+
To prevent chunk migrations from distruping the backup, use
73+
the :method:`sh.stopBalancer` method to stop the balancer:
74+
75+
.. code-block:: javascript
76+
77+
sh.stopBalancer()
78+
79+
If a balancing round is currently in progress, the operation waits for
80+
balancing to complete.
81+
82+
To confirm that the balancer is stopped, use the
83+
:method:`sh.getBalancerState` method:
84+
85+
.. io-code-block::
86+
87+
.. input::
88+
:language: javascript
89+
90+
sh.getBalancerState()
91+
92+
.. output::
93+
:language: javascript
94+
95+
false
96+
97+
The command returns ``false`` when the balancer is stopped.
98+
99+
.. step:: Lock the Cluster
100+
101+
The sharded cluster must be locked during the backup process to protect
102+
the database from writes, which may cause inconsistencies in the backup.
103+
104+
To lock a sharded cluster, use the :method:`db.fsyncLock` method:
105+
106+
.. code-block:: javascript
107+
108+
db.getSiblingDB("admin").fsyncLock()
109+
110+
To confirm the lock, on :program:`mongos` and the primary
111+
:program:`mongod` of the config servers, run the following
112+
aggregation pipeline and ensure that all of the shards are
113+
locked:
114+
115+
.. io-code-block::
116+
117+
.. input::
118+
:language: javascript
119+
120+
db.getSiblingDB("admin").aggregate( [
121+
{ $currentOp: { } },
122+
{ $facet: {
123+
"locked": [
124+
{ $match: { $and: [
125+
{ fsyncLock: { $exists: true } },
126+
{ fsyncLock: true }
127+
] } }],
128+
"unlocked": [
129+
{ $match: { fsyncLock: { $exists: false } } }
130+
]
131+
} },
132+
{ $project: {
133+
"fsyncLocked": { $gt: [ { $size: "$locked" }, 0 ] },
134+
"fsyncUnlocked": { $gt: [ { $size: "$unlocked" }, 0 ] }
135+
} }
136+
] )
137+
138+
.. output::
139+
:language: json
140+
141+
[ { fsyncLocked: true }, { fsyncUnlocked: false } ]
142+
143+
.. step:: Take Backup
144+
145+
To back up the sharded cluster, use ``mongodump`` to connect to
146+
:program:`mongos` and perform the backup:
147+
148+
.. code-block:: bash
149+
150+
mongodump \
151+
--host mongos.example.net \
152+
--port 27017 \
153+
--username user \
154+
--password "passwd" \
155+
--out /opt/backups/example-cluster-1
156+
157+
.. step:: Unlock the Cluster
158+
159+
After the backup completes, you can unlock the cluster to allow writes
160+
to resume.
161+
162+
To unlock the cluster, use the :method:`db.fsyncUnlock` method:
163+
164+
.. code-block:: bash
165+
166+
db.getSibling("admin").fsyncUnlock()
167+
168+
To confirm the unlock, on :program:`mongos` and the primary
169+
:program:`mongod` of the config servers, run the following
170+
aggregation pipeline and ensure that all shards are unlocked:
171+
172+
.. io-code-block::
173+
174+
.. input::
175+
:language: javascript
176+
177+
db.getSiblingDB("admin").aggregate( [
178+
{ $currentOp: { } },
179+
{ $facet: {
180+
"locked": [
181+
{ $match: { $and: [
182+
{ fsyncLock: { $exists: true } },
183+
{ fsyncLock: true }
184+
] } }],
185+
"unlocked": [
186+
{ $match: { fsyncLock: { $exists: false } } }
187+
]
188+
} },
189+
{ $project: {
190+
"fsyncLocked": { $gt: [ { $size: "$locked" }, 0 ] },
191+
"fsyncUnlocked": { $gt: [ { $size: "$unlocked" }, 0 ] }
192+
} }
193+
] )
194+
195+
.. output::
196+
:language: json
197+
198+
[ { fsyncLocked: false }, { fsyncUnlocked: true } ]
199+
200+
.. step:: Restart the Balancer
201+
202+
To restart the balancer, use the :method:`sh.startBalancer` method:
203+
204+
.. code-block:: javascript
205+
206+
sh.startBalancer()
207+
208+
To confirm that the balancer is running, use the
209+
:method:`sh.getBalancerState` method:
210+
211+
.. io-code-block::
212+
213+
.. input::
214+
:language: javascript
215+
216+
sh.getBalancerState()
217+
218+
.. output::
219+
:language: javascript
220+
221+
true
222+
223+
The command returns ``true`` when the balancer is running.
224+

source/tutorial/schedule-backup-window-for-sharded-clusters.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _sharded-schedule-backup:
2+
13
===========================================
24
Schedule Backup Window for Sharded Clusters
35
===========================================

0 commit comments

Comments
 (0)