Skip to content

Commit 6849344

Browse files
author
Sam Kleinman
committed
DOCS-356 repair revision
1 parent b919998 commit 6849344

File tree

5 files changed

+44
-43
lines changed

5 files changed

+44
-43
lines changed

source/includes/note-repair.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. note::
2+
3+
When using :term:`journaling <journal>`, there is almost never
4+
any need to run :dbcommand:`repairDatabase`. In the event of an
5+
unclean shutdown, the server will be able restore the data files
6+
to a pristine state automatically.

source/includes/warning-repair.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. warning::
2+
3+
In general, if you have an intact copy of your data, such as
4+
would exist on a very recent backup or an intact member of a
5+
:term:`replica set`, **do not** use :dbcommand:`repairDatabase`
6+
or related options like :func:`db.repairDatabase()` in the
7+
:program:`mongo` shell or :option:`mongod --repair`. Restore
8+
from an intact copy of your data.

source/reference/commands.txt

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,18 +1454,23 @@ Administration
14541454

14551455
.. dbcommand:: repairDatabase
14561456

1457+
.. include:: /includes/warning-repair.rst
1458+
1459+
.. include:: /includes/note-repair.rst
1460+
14571461
The :dbcommand:`repairDatabase` command checks and repairs errors and
14581462
inconsistencies with the data storage. The command is analogous to
14591463
a ``fsck`` command for file systems.
14601464

14611465
If your :program:`mongod` instance is not running with journaling
1462-
and you experience an unexpected system restart or crash, you
1466+
the system experiences an unexpected system restart or crash, and
1467+
you have *no* other intact replica set members with this data, you
14631468
should run the :dbcommand:`repairDatabase` command to ensure that
14641469
there are no errors in the data storage.
14651470

14661471
As a side effect, the :dbcommand:`repairDatabase` command will
1467-
compact the database, providing functionality equivalent to the
1468-
:dbcommand:`compact` command. Use the following syntax.
1472+
compact the database, as the :dbcommand:`compact` command. Use the
1473+
following syntax.
14691474

14701475
.. code-block:: javascript
14711476

@@ -1485,6 +1490,9 @@ Administration
14851490

14861491
- Use the shell to run the above command, as above.
14871492

1493+
- Use the :func:`db.repairDatabase()` in the :program:`mongo`
1494+
shell.
1495+
14881496
- Run :program:`mongod` directly from your system's shell. Make sure
14891497
that :program:`mongod` isn't already running, and that you issue
14901498
this command as a user that has access to MongoDB's data
@@ -1499,23 +1507,12 @@ Administration
14991507
.. note::
15001508

15011509
This command will fail if your database is not a master or
1502-
primary. If you need to repair a secondary or slave node,
1503-
first restart the node as a standalone mongod by omitting the
1504-
:option:`--replSet <mongod --replSet>` or :option:`--slave
1505-
<mongod --slave>` options, as necessary.
1506-
1507-
- You may use the following shell helper:
1508-
1509-
.. code-block:: javascript
1510-
1511-
db.repairDatabase();
1512-
1513-
.. note::
1514-
1515-
When using :term:`journaling <journal>`, there is almost never any need to
1516-
run :dbcommand:`repairDatabase`. In the event of an unclean
1517-
shutdown, the server will be able restore the data files to a
1518-
pristine state automatically.
1510+
primary. In most cases, you should recover a currupt secondary
1511+
using the data from an existing intact node. If you need to
1512+
repair a secondary or slave node, first restart the node as a
1513+
standalone mongod by omitting the :option:`--replSet <mongod
1514+
--replSet>` or :option:`--slave <mongod --slave>` options, as
1515+
necessary.
15191516

15201517
.. dbcommand:: shutdown
15211518

source/reference/javascript.txt

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,26 +1014,18 @@ Database
10141014

10151015
Removes the specified username from the database.
10161016

1017-
.. function:: db.repairDatabase()
10181017

1019-
Checks and repairs errors and inconsistencies with the data
1020-
storage. This function is analogous to a ``fsck`` operation for
1021-
file systems. Additionally, the function compacts the database to
1022-
minimize the current database's storage utilization, similar to the
1023-
:dbcommand:`compact` command.
1018+
.. function:: db.repairDatabase()
10241019

1025-
This function has the same effect as using the run-time option
1026-
":option:`mongod --repair`," but only operates on the current
1027-
database.
1020+
.. include:: /includes/warning-repair.rst
10281021

1029-
This command provides a wrapper around the database command
1030-
":dbcommand:`repairDatabase`".
1031-
1032-
.. warning::
1022+
.. include:: /includes/note-repair.rst
10331023

1034-
In general, if you have an intact :term:`replica set` member,
1035-
do not use :func:`db.repairDatabase()` and restore from the
1036-
other replica member.
1024+
:func:`db.repairDatabase()` provides a wrapper around the database
1025+
command :dbcommand:`repairDatabase`, and has the same effect as
1026+
the run-time option :option:`mongod --repair` option, limited to
1027+
*only* the current database. See :dbcommand:`repairDatabase` for
1028+
full documentation.
10371029

10381030
.. function:: db.runCommand(command)
10391031

source/reference/mongod.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,12 @@ Options
334334

335335
.. option:: --repair
336336

337-
Runs a repair routine on all databases.
337+
Runs a repair routine on all databases. This is a similar operation
338+
to the :dbcommand:`repairDatabase` database command.
338339

339-
.. note::
340+
.. include:: /includes/warning-repair.rst
340341

341-
Because :program:`mongod` rewrites all of the database files
342-
during the repair routine, if you do not run :option:`--repair`
343-
under the same user account as :program:`mongod` usually runs,
344-
you will need to run ``chown`` on your database files to correct
345-
the permissions before starting :program:`mongod` again.
342+
.. include:: /includes/note-repair.rst
346343

347344
.. versionchanged:: 2.1.2
348345

@@ -357,6 +354,7 @@ Options
357354
:program:`mongod` cleanly and restart with the :option:`--repair`
358355
option.
359356

357+
360358
.. option:: --repairpath <path>
361359

362360
Specifies the root directory containing MongoDB data files, to use

0 commit comments

Comments
 (0)