|
| 1 | +--- |
| 2 | +stepnum: 1 |
| 3 | +level: 4 |
| 4 | +title: "Start the Temporary Standalone Instance on the Ephemeral Port." |
| 5 | +ref: start-as-standalone |
| 6 | +content: | |
| 7 | +
|
| 8 | + Start the |mongod| process in standalone mode as a temporary measure. |
| 9 | + This allows you to add new configuration parameters to the |
| 10 | + ``system.replset`` collection in subsequent steps. |
| 11 | + |
| 12 | + Use the ``<ephemeralPort>`` for the temporary standalone |mongod| process |
| 13 | + in all steps in this procedure where it is mentioned. This port must |
| 14 | + differ from the source and target host ports. |
| 15 | +
|
| 16 | + Run the |mongod| process as follows. Depending on your path, you may |
| 17 | + need to specify the path to the |mongod| binary. |
| 18 | +
|
| 19 | + .. code-block:: sh |
| 20 | +
|
| 21 | + mongod --dbpath </path/to/datafiles> \ |
| 22 | + --port <ephemeralPort> \ |
| 23 | +
|
| 24 | + If you are restoring |
| 25 | + from a namespace-filtered snapshot, use the ``--restore`` option. |
| 26 | +
|
| 27 | + .. code-block:: sh |
| 28 | +
|
| 29 | + mongod --dbpath </path/to/datafiles> \ |
| 30 | + --port <ephemeralPort> \ |
| 31 | + --restore |
| 32 | +
|
| 33 | + After the |mongod| process starts accepting connections, continue. |
| 34 | +
|
| 35 | +--- |
| 36 | +stepnum: 2 |
| 37 | +level: 4 |
| 38 | +title: "Connect to the Temporary Standalone Instance with {+mongosh+}." |
| 39 | +ref: connect-on-ephemeral-port |
| 40 | +content: | |
| 41 | +
|
| 42 | + From the host running this |mongod| process, start {+mongosh+}. Depending |
| 43 | + on your path, you may need to specify the path to {+mongosh+}. |
| 44 | + |
| 45 | + To connect to the |mongod| listening to localhost on |
| 46 | + the same ``<ephemeralPort>`` specified in the previous step, run: |
| 47 | +
|
| 48 | + .. code-block:: sh |
| 49 | +
|
| 50 | + mongosh --port <ephemeralPort> |
| 51 | +
|
| 52 | + After {+mongosh+} connects to |mongod|, continue. |
| 53 | +
|
| 54 | +--- |
| 55 | +stepnum: 3 |
| 56 | +level: 4 |
| 57 | +title: "Remove Replica Set-Related Collections from the ``local`` Database." |
| 58 | +ref: remove-replset-config |
| 59 | +content: | |
| 60 | +
|
| 61 | + .. include:: /includes/fact-restore-manual-user-role.rst |
| 62 | +
|
| 63 | + Run the following commands to remove the previous replica set |
| 64 | + configuration and other non-oplog, replication-related collections. |
| 65 | +
|
| 66 | + .. code-block:: javascript |
| 67 | +
|
| 68 | + db.getSiblingDB("local").replset.minvalid.drop() |
| 69 | + db.getSiblingDB("local").replset.oplogTruncateAfterPoint.drop() |
| 70 | + db.getSiblingDB("local").replset.election.drop() |
| 71 | + db.getSiblingDB("local").system.replset.remove({}) |
| 72 | +
|
| 73 | + A successful response should look like this: |
| 74 | +
|
| 75 | + .. code-block:: javascript |
| 76 | + :copyable: false |
| 77 | +
|
| 78 | + > db.getSiblingDB("local").replset.minvalid.drop() |
| 79 | + true |
| 80 | + > db.getSiblingDB("local").replset.oplogTruncateAfterPoint.drop() |
| 81 | + true |
| 82 | + > db.getSiblingDB("local").replset.election.drop() |
| 83 | + true |
| 84 | + > db.getSiblingDB("local").system.replset.remove({}) |
| 85 | + WriteResult({ "nRemoved" : 1 }) |
| 86 | +
|
| 87 | +--- |
| 88 | +stepnum: 4 |
| 89 | +level: 4 |
| 90 | +title: "Add a New Replica Set Configuration." |
| 91 | +ref: add-new-replset-config |
| 92 | +content: | |
| 93 | +
|
| 94 | + Insert the following document into the ``system.replset`` collection |
| 95 | + in the ``local`` database. Change the following variables: |
| 96 | +
|
| 97 | + - ``<replaceMeWithTheReplicaSetName>`` to the name of your replica set. This |
| 98 | + name does not have to be the same as the old name. |
| 99 | + - ``<host>`` to the host serving this replica set member. |
| 100 | + - ``<finalPortNewReplicaSet>`` to the final port for the new |
| 101 | + replica set. This must be a different port than the |
| 102 | + ``<ephemeralPort>`` that you specified in Step 11 of this procedure. |
| 103 | +
|
| 104 | + Ensure that you include and configure all members of the new replica |
| 105 | + set in the ``members`` array. |
| 106 | +
|
| 107 | + .. code-block:: javascript |
| 108 | + :linenos: |
| 109 | +
|
| 110 | + db.getSiblingDB("local").system.replset.insertOne({ |
| 111 | + "_id" : "<replaceMeWithTheReplicaSetName>", |
| 112 | + "version" : NumberInt(1), |
| 113 | + "protocolVersion" : NumberInt(1), |
| 114 | + "members" : [ |
| 115 | + { |
| 116 | + "_id" : NumberInt(0), |
| 117 | + "host" : "<host>:<finalPortNewReplicaSet>" |
| 118 | + }, |
| 119 | + { |
| 120 | + . . . |
| 121 | + }, |
| 122 | + . . . |
| 123 | + ], |
| 124 | + "settings" : { |
| 125 | +
|
| 126 | + } |
| 127 | + }) |
| 128 | +
|
| 129 | + A successful response should look like this: |
| 130 | +
|
| 131 | + .. code-block:: javascript |
| 132 | + :copyable: false |
| 133 | +
|
| 134 | + { "acknowledged" : true, "insertedId" : "<yourReplicaSetName>" } |
| 135 | +
|
| 136 | +--- |
| 137 | +stepnum: 5 |
| 138 | +level: 4 |
| 139 | +title: "Insert the Minimum Valid Timestamp." |
| 140 | +ref: set-minvalid-timestamp |
| 141 | +content: | |
| 142 | +
|
| 143 | + Issue the following command: |
| 144 | +
|
| 145 | + .. code-block:: javascript |
| 146 | +
|
| 147 | + db.getSiblingDB("local").replset.minvalid.insertOne({ |
| 148 | + "_id" : ObjectId(), |
| 149 | + "t" : NumberLong(-1), |
| 150 | + "ts" : Timestamp(0,1) |
| 151 | + }) |
| 152 | +
|
| 153 | + A successful response should look like this: |
| 154 | +
|
| 155 | + .. code-block:: javascript |
| 156 | + :copyable: false |
| 157 | +
|
| 158 | + { "acknowledged" : true, "insertedId" : ObjectId("<yourObjectId>") } |
| 159 | +
|
| 160 | +--- |
| 161 | +stepnum: 6 |
| 162 | +level: 4 |
| 163 | +title: "Set the Restore Point to the Values in ``Restore Timestamp`` from ``restoreInfo.txt``." |
| 164 | +ref: set-restore-point |
| 165 | +content: | |
| 166 | + Set the ``oplogTruncateAfterPoint`` document to the |
| 167 | + values provided in the ``Restore Timestamp`` field of the |
| 168 | + :ref:`restoreInfo.txt <com-restore-info-rs>` file. |
| 169 | +
|
| 170 | + The ``Restore Timestamp`` field in that file contains two |
| 171 | + values. In the following example, the first value is the |
| 172 | + timestamp, and the second value is the increment. |
| 173 | +
|
| 174 | + .. code-block:: sh |
| 175 | + :copyable: false |
| 176 | + :linenos: |
| 177 | + :emphasize-lines: 2 |
| 178 | + |
| 179 | + ... |
| 180 | + Restore timestamp: (1609947369, 2) |
| 181 | + Last Oplog Applied: Wed Jan 06 15:36:09 GMT 2021 (1609947369, 1) |
| 182 | + MongoDB Version: 4.2.11 |
| 183 | + ... |
| 184 | +
|
| 185 | + The following example code uses the timestamp value and increment value from the previous example. |
| 186 | +
|
| 187 | + .. code-block:: javascript |
| 188 | +
|
| 189 | + truncateAfterPoint = Timestamp(1609947369,2) |
| 190 | + db.getSiblingDB("local").replset.oplogTruncateAfterPoint.insertOne({ |
| 191 | + "_id": "oplogTruncateAfterPoint", |
| 192 | + "oplogTruncateAfterPoint": truncateAfterPoint |
| 193 | + }) |
| 194 | +
|
| 195 | + A successful response should look like this: |
| 196 | +
|
| 197 | + .. code-block:: javascript |
| 198 | + :copyable: false |
| 199 | +
|
| 200 | + WriteResult({ "nInserted" : 1 }) |
| 201 | +
|
| 202 | + .. note:: Restoring MongoDB 4.2 Snapshots using MongoDB 4.4 |
| 203 | +
|
| 204 | + If you try to restore a MongoDB 4.2 snapshot with a |mongod| |
| 205 | + running MongoDB 4.4, your oplog may contain unneeded documents. |
| 206 | +
|
| 207 | + To resolve this issue, you can either: |
| 208 | +
|
| 209 | + - Decrement the timestamp by 1. |
| 210 | + - Restore using MongoDB 4.2. |
| 211 | + - Have |mms| run an automated restore. |
| 212 | +
|
| 213 | + This issue doesn't apply to MongoDB 4.4 or later snapshots. |
0 commit comments