@@ -7,15 +7,15 @@ Backup and Restoration Strategies
7
7
This document provides an inventory of database backup strategies for
8
8
use with MongoDB.
9
9
10
- - The :ref:`backup-overview` and :ref:`backup-considerations` sections
11
- describe the approaches for backing up your MongoDB environment.
10
+ - :ref:`backup-overview` and :ref:`backup-considerations` describe the
11
+ approaches for backing up your MongoDB environment.
12
12
13
- - The :ref:`block-level-backup` or :ref:`database-dumps` sections
14
- describe specific strategies.
13
+ - :ref:`block-level-backup` and :ref:`database-dumps` describe specific
14
+ strategies.
15
15
16
- - The :ref:`backups-with-sharding-and-replication` section describes
17
- considerations specific to :term:`replica sets <replica set>` and
18
- :term:`sharded clusters <sharded cluster>`.
16
+ - :ref:`backups-with-sharding-and-replication` describes considerations
17
+ specific to :term:`replica sets <replica set>` and :term:`sharded
18
+ clusters <sharded cluster>`.
19
19
20
20
.. _backup-overview:
21
21
@@ -29,11 +29,13 @@ up a new or replacement database instance.
29
29
30
30
With MongoDB, there are two major approaches to backups:
31
31
32
- - Using system-level tools, like disk image snapshots. See
33
- :ref:`block-level-backup`.
32
+ - Using system-level tools, like disk image snapshots.
34
33
35
- - Using various capacities present in the :program:`mongodump` tool. See
36
- :ref:`database-dumps`.
34
+ See :ref:`block-level-backup`.
35
+
36
+ - Using various capacities present in the :program:`mongodump` tool.
37
+
38
+ See :ref:`database-dumps`.
37
39
38
40
The methods described in this document operate by copying the data file
39
41
on the disk level. If your system does not provide functionality for
@@ -149,8 +151,8 @@ Snapshots have the following limitations:
149
151
150
152
.. _backup-with-journaling:
151
153
152
- With Journaling
153
- ~~~~~~~~~~~~~~~
154
+ Backup With Journaling
155
+ ~~~~~~~~~~~~~~~~~~~~~~
154
156
155
157
If your system has snapshot capability and your :program:`mongod` instance
156
158
has journaling enabled, then you can use any kind of file system or
@@ -164,7 +166,7 @@ volume/block level snapshot tool to create backups.
164
166
MongoDB.
165
167
166
168
To enable journaling on all other builds, specify
167
- " :setting:`journal` = ``true`` in the configuration or use the
169
+ :setting:`journal` = ``true`` in the configuration or use the
168
170
:option:`--journal <mongod --journal>` run-time option for
169
171
:program:`mongod`.
170
172
@@ -177,12 +179,11 @@ LVM-based setups *within* a cloud/virtualized environment.
177
179
.. note::
178
180
179
181
Running :term:`LVM` provides additional flexibility and enables the
180
- possibility of using snapshots to backup MongoDB.
182
+ possibility of using snapshots to back up MongoDB.
181
183
182
- If you use Amazon's EBS service in a software RAID 10 (e.g. 1+0)
183
- configuration, use :term:`LVM` to capture a consistent disk image.
184
-
185
- Also consider, :ref:`backup-amazon-software-raid`.
184
+ If you use Amazon's EBS service in a software RAID 10 configuration, use
185
+ :term:`LVM` to capture a consistent disk image. Also, see the special
186
+ considerations described in :ref:`backup-amazon-software-raid`.
186
187
187
188
The following sections provide an overview of a simple backup process
188
189
using :term:`LVM` on a Linux system. While the tools, commands, and paths may
@@ -313,8 +314,12 @@ Remote Backup Storage
313
314
`````````````````````
314
315
315
316
You can implement off-system backups using the :ref:`combined process
316
- <backup-restore-from-snapshot>` and SSH. Consider the following
317
- procedure:
317
+ <backup-restore-from-snapshot>` and SSH.
318
+
319
+ This sequence is identical to procedures explained above, except that it
320
+ archives and compresses the backup on a remote system using SSH.
321
+
322
+ Consider the following procedure:
318
323
319
324
.. code-block:: sh
320
325
@@ -324,51 +329,48 @@ procedure:
324
329
ssh
[email protected] tar -xzf /opt/backup/mdb-snap01.tar.gz | dd of=/dev/vg0/mdb-new
325
330
mount /dev/vg0/mdb-new /srv/mongodb
326
331
327
- This sequence is identical to procedures explained above, except that
328
- it archives and compresses the backup on a remote system using SSH.
329
-
330
332
.. _backup-without-journaling:
331
333
332
- Without Journaling
333
- ~~~~~~~~~~~~~~~~~~
334
+ Backup Without Journaling
335
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
334
336
335
337
If your :program:`mongod` instance does not run with journaling
336
338
enabled, or if your journal is on a separate volume, obtaining a
337
- functional backup of a consistent state is more complicated. Flush all
339
+ functional backup of a consistent state is more complicated. As described in this section, you must flush all
338
340
writes to disk and lock the database to prevent writes during the
339
- backup process. If you have a :term:`replica set` configuration, use a
341
+ backup process. If you have a :term:`replica set` configuration, then for your backup, use a
340
342
:term:`secondary` that is not receiving reads (i.e. :term:`hidden
341
- member`) for backup purposes .
343
+ member`).
342
344
343
- You can flush writes to disk, and "lock" the database to prevent
344
- further writes with the :method:`db.fsyncLock()` command in the
345
- :program:`mongo` shell, as follows :
345
+ 1. To flush writes to disk and to "lock" the database ( to prevent
346
+ further writes), issue the :method:`db.fsyncLock()` method in the
347
+ :program:`mongo` shell:
346
348
347
- .. code-block:: javascript
349
+ .. code-block:: javascript
348
350
349
- db.fsyncLock();
351
+ db.fsyncLock();
350
352
351
- Perform the :ref:`backup operation described above
352
- <lvm-backup-operation>` at this point. To unlock the database after
353
- the snapshot has completed, use the following command in the
354
- :program:`mongo` shell:
353
+ #. Perform the backup operation described in :ref:`lvm-backup-operation`.
355
354
356
- .. code-block:: javascript
355
+ #. To unlock the database after the snapshot has completed, use the
356
+ following command in the :program:`mongo` shell:
357
357
358
- db.fsyncUnlock();
358
+ .. code-block:: javascript
359
359
360
- .. note::
360
+ db.fsyncUnlock();
361
361
362
- Version 1.9.0 added :method:`db.fsyncLock()` and
363
- :method:`db.fsyncUnlock()` helpers to the :program:`mongo` shell.
364
- Prior to this version, use the following commands:
362
+ .. note::
365
363
366
- .. code-block:: javascript
364
+ Version 1.9.0 added :method:`db.fsyncLock()` and
365
+ :method:`db.fsyncUnlock()` helpers to the :program:`mongo` shell.
366
+ Prior to this version, use the following commands:
367
+
368
+ .. code-block:: javascript
367
369
368
- db.runCommand( { fsync: 1, lock: true } );
369
- db.runCommand( { fsync: 1, lock: false } );
370
+ db.runCommand( { fsync: 1, lock: true } );
371
+ db.runCommand( { fsync: 1, lock: false } );
370
372
371
- .. include:: /includes/note-disable-profiling-fsynclock.rst
373
+ .. include:: /includes/note-disable-profiling-fsynclock.rst
372
374
373
375
.. _backup-amazon-software-raid:
374
376
@@ -383,24 +385,23 @@ tool. As a result you may:
383
385
- Flush all writes to disk and create a write lock to ensure
384
386
consistent state during the backup process.
385
387
386
- If you choose this option see the section on ":ref:`Backup without
387
- Journaling <backup-without-journaling>`"
388
+ If you choose this option see :ref:`backup-without-journaling`.
388
389
389
390
- Configure LVM to run and hold your MongoDB data files on top of the
390
391
RAID within your system.
391
392
392
- If you choose this option see the section that outlines the
393
- " :ref:`LVM backup operation < lvm-backup-operation>`"
393
+ If you choose this option, perform the LVM backup operation described
394
+ in :ref:`lvm-backup-operation`.
394
395
395
396
.. _database-dumps:
396
397
397
398
Using Binary Database Dumps for Backups
398
399
---------------------------------------
399
400
400
401
This section describes the process for writing the entire contents of
401
- your MongoDB instance to a file in a binary format. This command
402
- provides the best option for full system database backups if
403
- disk-level snapshots are not available .
402
+ your MongoDB instance to a file in a binary format. If
403
+ disk-level snapshots are not available, this approach
404
+ provides the best option for full system database backups .
404
405
405
406
.. seealso::
406
407
@@ -415,15 +416,14 @@ disk-level snapshots are not available.
415
416
Database Dump with :program:`mongodump`
416
417
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
417
418
418
- The :program:`mongodump` utility performs a live backup the data, or
419
+ The :program:`mongodump` utility can perform a live backup of data or
419
420
can work against an inactive set of database
420
421
files. The :program:`mongodump` utility can create a dump for an entire
421
- server/database/collection (or part of a collection using of query,)
422
+ server/database/collection (or part of a collection using of query),
422
423
even when the database is running and active. If you run
423
- :program:`mongodump` without any arguments the command will connect to
424
+ :program:`mongodump` without any arguments, the command will connect to
424
425
the local database instance (e.g. ``127.0.0.1`` or ``localhost``) and
425
- create a database backup in in the current directory named
426
- ``dump/``.
426
+ create a database backup named ``dump/`` and place it in the current directory.
427
427
428
428
.. include:: /includes/note-mongodump-compatibility-2.2.rst
429
429
@@ -438,11 +438,11 @@ database dump. For example:
438
438
This command creates a dump in of the database in the ``dump/``
439
439
directory of only the collection named ``collection`` in the
440
440
database named ``test``. :program:`mongodump` provides the
441
- " :option:`--oplog <mongodump --oplog>`" option that forces the dump
441
+ :option:`--oplog <mongodump --oplog>` option that forces the dump
442
442
operation to use the operation log to take a point-in-time snapshot of
443
443
the database.
444
444
445
- With " :option:`--oplog <mongodump --oplog>`" , :program:`mongodump`
445
+ With :option:`--oplog <mongodump --oplog>`, :program:`mongodump`
446
446
copies all the data from the source database, as well as all of the
447
447
:term:`oplog` entries from the beginning of the backup procedure to
448
448
until the backup procedure completes. This backup procedure, in
@@ -451,7 +451,7 @@ restore a backup that reflects a consistent and specific moment in
451
451
time.
452
452
453
453
If your MongoDB instance is not running, you can use the
454
- " :option:`--dbpath <mongodump --dbpath>`" option to specify the
454
+ :option:`--dbpath <mongodump --dbpath>` option to specify the
455
455
location to your MongoDB instance's database files. :program:`mongodump`
456
456
reads from the data files directly with this operation. This
457
457
locks the data directory to prevent conflicting writes. The
@@ -463,8 +463,8 @@ configuration. Consider the following example:
463
463
464
464
mongodump --dbpath /srv/mongodb
465
465
466
- Additionally, the " :option:`--host <mongodump --host>`" and
467
- " :option:`--port <mongodump --port>`" options allow you to specify a
466
+ Additionally, the :option:`--host <mongodump --host>` and
467
+ :option:`--port <mongodump --port>` options allow you to specify a
468
468
non-local host to connect to capture the dump. Consider the following
469
469
example:
470
470
@@ -490,7 +490,7 @@ the ``dump-2011-10-25`` directory to the :program:`mongod` instance
490
490
running on the localhost interface. By default, :program:`mongorestore`
491
491
will look for a database dump in the ``dump/`` directory and restore
492
492
that. If you wish to restore to a non-default host, the
493
- " :option:`--host <mongorestore --host>`" and " :option:`--port <mongorestore --port>`"
493
+ :option:`--host <mongorestore --host>` and :option:`--port <mongorestore --port>`
494
494
options allow you to specify a non-local host to connect to capture
495
495
the dump. Consider the following example:
496
496
@@ -536,14 +536,14 @@ interacting with your shell environment.
536
536
Here, :program:`mongorestore` restores the database dump located in
537
537
``dump/`` folder into the data files located at ``/srv/mongodb``, with
538
538
the :option:`--dbpath <mongorestore --dbpath>` option. Additionally,
539
- the " :option:`--journal <mongorestore --journal>`" option ensures that
539
+ the :option:`--journal <mongorestore --journal>` option ensures that
540
540
:program:`mongorestore` records all operation in the durability
541
541
:term:`journal`. The journal prevents data file corruption if anything
542
542
(e.g. power failure, disk failure, etc.) interrupts the restore
543
543
operation.
544
544
545
- .. seealso:: " :doc:`/reference/mongodump`" and
546
- " :doc:`/reference/mongorestore`."
545
+ .. seealso:: :doc:`/reference/mongodump` and
546
+ :doc:`/reference/mongorestore`.
547
547
548
548
.. _backups-with-sharding-and-replication:
549
549
@@ -653,8 +653,8 @@ following sequence:
653
653
.. note::
654
654
655
655
In this situation :program:`mongodump` will read from
656
- :term:`secondary` nodes. See: " :ref:`mongodump feature
657
- <mongodump-behavior>`" for more information.
656
+ :term:`secondary` nodes. See: :ref:`mongodump feature
657
+ <mongodump-behavior>` for more information.
658
658
659
659
2. Record a backup of all shards
660
660
0 commit comments