@@ -4,10 +4,9 @@ Recover MongoDB Data following Unexpected Shutdown
4
4
5
5
.. default-domain:: mongodb
6
6
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.
11
10
12
11
To prevent data inconsistency and corruption, always shut down the
13
12
database cleanly, and use the :ref:`durability journaling
@@ -19,6 +18,15 @@ power loss or other system failure.
19
18
If you do not have journaling enabled, use the following procedure to
20
19
recover data that may be in an inconsistent state.
21
20
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
+
22
30
Process
23
31
-------
24
32
@@ -29,39 +37,50 @@ When you are aware of a :program:`mongod` instance running without
29
37
journaling that stops unexpectedly you should always run the repair
30
38
operation before starting MongoDB again.
31
39
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:
36
53
37
54
.. code-block:: none
38
55
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
44
57
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 .
47
60
48
61
Overview
49
62
~~~~~~~~
50
63
51
64
There are two processes to repair data files that result from an
52
65
unexpected shutdown:
53
66
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
-
59
67
#. Use the :option:`--repair <mongod --repair>` option in
60
68
conjunction with the :option:`--repairpath <mongod --repairpath>`
61
69
option. :program:`mongod` will read the existing data files, and
62
70
write the existing data to new data files. This does not modify or
63
71
alter the existing data files.
64
72
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
+
65
84
Procedures
66
85
~~~~~~~~~~
67
86
@@ -83,7 +102,7 @@ option to preserve the original data files unmodified:
83
102
84
103
.. code-block:: sh
85
104
86
- mongod --dbpath /data/db2
105
+ mongod --dbpath /data/db0
87
106
88
107
Once you confirm that the data files are operational you may delete
89
108
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
92
111
not use the :option:`--repairpath <mongod --repairpath>` option, as in
93
112
the following procedure:
94
113
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
+
95
129
#. Start :program:`mongod` using :option:`--repair <mongod --repair>`
96
130
to read the existing data files.
97
131
@@ -113,11 +147,12 @@ the following procedure:
113
147
---------------
114
148
115
149
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.
121
156
122
157
If you are not running with journaling, and your database shuts down
123
158
unexpectedly for *any* reason, you should always assume that your
0 commit comments