Skip to content

Commit 66bf198

Browse files
author
Sam Kleinman
committed
new recovery tutorial edits
1 parent 122daa0 commit 66bf198

File tree

1 file changed

+61
-26
lines changed

1 file changed

+61
-26
lines changed

aspiration/tutorial/recover-data-following-unexpected-shutdown.txt

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Recover MongoDB Data following Unexpected Shutdown
44

55
.. default-domain:: mongodb
66

7-
If MongoDB does not shut down cleanly using the :option:`--shutdown
8-
<mongod --shutdown>` option, the on disk representation of the data
9-
files will likely reflect an inconsistent state which leads to data
10-
corruption.
7+
If MongoDB does not shutdown cleanly [#clean-shutdown]_ the on disk
8+
representation of the data files will likely reflect an inconsistent
9+
state which leads to data corruption.
1110

1211
To prevent data inconsistency and corruption, always shut down the
1312
database cleanly, and use the :ref:`durability journaling
@@ -19,6 +18,15 @@ power loss or other system failure.
1918
If you do not have journaling enabled, use the following procedure to
2019
recover data that may be in an inconsistent state.
2120

21+
.. seealso:: The ":doc:`/administration`" documents and the
22+
documentation of the :setting:`repair`, :setting:`repairpath`, and
23+
:setting:`journal` settings.
24+
25+
.. [#clean-shutdown] To ensure a clean shut down, use the
26+
:option:`mongod --shutdown` option, your control script,
27+
"Control-C" (when running :program:`mongod` in interactive mode,)
28+
or ``kill mongod`` or ``kill -2 mongod``.
29+
2230
Process
2331
-------
2432

@@ -29,39 +37,50 @@ When you are aware of a :program:`mongod` instance running without
2937
journaling that stops unexpectedly you should always run the repair
3038
operation before starting MongoDB again.
3139

32-
If the ``mongod.lock`` file exists in the data directory, specified by
33-
:setting:`dbpath` and ``/data/db`` by default, then :program:`mongod`
34-
will refuse to start, and you will find the following message in your
35-
log:
40+
If the ``mongod.lock`` file has data in the data directory specified
41+
by :setting:`dbpath`, ``/data/db`` by default, then :program:`mongod`
42+
will refuse to start, and you will find a message that contains the
43+
following line in your MongoDB log our output:
44+
45+
.. code-block:: none
46+
47+
Unclean shutdown detected.
48+
49+
This indicates that you need to remove the lockfile and run repair. If
50+
you run repair when the ``mongodb.lock`` file exists without the
51+
:option:`mongod --repairpath` option, you will see a message that
52+
contains the following line:
3653

3754
.. code-block:: none
3855

39-
**************
40-
old lock file: /data/db/mongod.lock. probably means unclean shutdown
41-
recommend removing file and running --repair
42-
see: http://dochub.mongodb.org/core/repair for more information
43-
*************
56+
old lock file: /data/db/mongod.lock. probably means unclean shutdown
4457

45-
Running repair will remove the lock file and allow the database to
46-
start normally.
58+
You must remove the lockfile **and** run the repair operation before
59+
starting the database normally using the following procedure.
4760

4861
Overview
4962
~~~~~~~~
5063

5164
There are two processes to repair data files that result from an
5265
unexpected shutdown:
5366

54-
#. Use just the :option:`--repair <mongod --repair>` option.
55-
:program:`mongod` will read the existing data files, write the
56-
existing data to new files and replace the existing, possibly
57-
corrupt, files with new files.
58-
5967
#. Use the :option:`--repair <mongod --repair>` option in
6068
conjunction with the :option:`--repairpath <mongod --repairpath>`
6169
option. :program:`mongod` will read the existing data files, and
6270
write the existing data to new data files. This does not modify or
6371
alter the existing data files.
6472

73+
You do not need to remove the ``mongod.lock`` file before using
74+
this procedure.
75+
76+
#. Use the :option:`--repair <mongod --repair>` option.
77+
:program:`mongod` will read the existing data files, write the
78+
existing data to new files and replace the existing, possibly
79+
corrupt, files with new files.
80+
81+
You must remove the ``mongod.lock`` file before using this
82+
procedure.
83+
6584
Procedures
6685
~~~~~~~~~~
6786

@@ -83,7 +102,7 @@ option to preserve the original data files unmodified:
83102

84103
.. code-block:: sh
85104

86-
mongod --dbpath /data/db2
105+
mongod --dbpath /data/db0
87106

88107
Once you confirm that the data files are operational you may delete
89108
or archive the data files in the ``/data/db`` directory.
@@ -92,6 +111,21 @@ To repair your data files without preserving the original files, do
92111
not use the :option:`--repairpath <mongod --repairpath>` option, as in
93112
the following procedure:
94113

114+
#. Remove the stale lock file:
115+
116+
.. code-block:: sh
117+
118+
rm /data/db/mongod.lock
119+
120+
Replace ``/data/db`` with your :setting:`dbpath` where your MongoDB
121+
instance's data files reside.
122+
123+
.. warning::
124+
125+
After you remove the ``mongod.lock`` file you *must* run the
126+
:option:`--repair <mongod --repair>` process before using your
127+
database.
128+
95129
#. Start :program:`mongod` using :option:`--repair <mongod --repair>`
96130
to read the existing data files.
97131

@@ -113,11 +147,12 @@ the following procedure:
113147
---------------
114148

115149
In normal operation, you should **never** remove the ``mongod.lock``
116-
file, and instead use one of the above methods to recover the database
117-
and remove the lock files. In dire situations you can remove the
118-
lockfile, and start the database using the possibly corrupt files, and
119-
attempt to recover data from the database; however, it's impossible to
120-
predict the state of the database in these situations.
150+
file and start :program:`mongod`. Instead use one of the above methods
151+
to recover the database and remove the lock files. In dire you
152+
situations can remove the lockfile, and start the database using the
153+
possibly corrupt files, and attempt to recover data from the database;
154+
however, it's impossible to predict the state of the database in these
155+
situations.
121156

122157
If you are not running with journaling, and your database shuts down
123158
unexpectedly for *any* reason, you should always assume that your

0 commit comments

Comments
 (0)