Skip to content

DOCS-1594: tutorial for restoring database into RS #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/includes/toc-administration-backup-and-recovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ description: |
system-level file snapshot tool, such as :term:`LVM` or native
storage appliance tools.
---
file: /tutorial/restore-database-from-backup-file
description: |
Describes procedure for restoring a replica set from an archived
backup such as a :program:`mongodump` or `MMS Backup <mms.mongodb.com>`_ file.
---
file: /administration/backup-sharded-clusters
description: |
Detailed procedures and considerations for backing up sharded
Expand Down
80 changes: 80 additions & 0 deletions source/tutorial/restore-database-from-backup-file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
=====================================
Restore a Database into a Replica Set
=====================================

.. default-domain:: mongodb

Restore Database into a Single Node Replica Set
-----------------------------------------------

#. Obtain backup files, for example, from a :program:`mongodump`, or
an MMS Backup restore. See
:doc:`/tutorial/backup-databases-with-binary-database-dumps/` for
more about restoring with :program:`mongodump` or `Restore from a
Stored Snapshot
<http://mms.mongodb.com/help/backup/tutorial/restore-from-point-in-time-snapshot/>`_
in the MMS documentation for instructions detailing how to restore
using MMS Backup.

#. Start a :program:`mongod` using your new data directory as its
``dbpath``:

.. code-block:: sh

mongod --dbpath /data/db

#. Convert your standalone :program:`mongod` process to a single node
replica set by shutting down the :program:`mongod` instance, and
restarting it with the ``--replSet`` option, as in the following
example:

.. code-block:: sh

mongod --dbpath /data/db --replSet <replName>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't oplogSize option be mentioned?


#. Connect to the :program:`mongod` instance.

#. User :method:`rs.initiate()` to initiate the new replica set.


Add Members to the Replica Set
------------------------------

You restore the secondary members of a replica set in two ways: by
manually copying the database files into their data directory, or
through :ref:`initial sync <replica-set-initial-sync>`. The following
sections provide instructions for each approach.

.. note::

If your database is large, initial sync can take a long time to
complete. For large databases, it might be preferable to copy the
database files onto each host.

Copy Database Files and Restart :program:`mongod` Instance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#. Shut down your :program:`mongod` instance.

#. Copy your :term:`primary's <primary>` data directory (generally,
``/data/db``) to the data directories of the other members of the
replica set. These will become :term:`secondaries <secondary>`.

#. In a :program:`mongo` shell connected to the :term:`primary`, add
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they will need to restart primary mongod first.

the :term:`secondaries <secondary>` to the replica set using
:method:`rs.add()`. For more information about deploying a replica
set, see: :doc:`/tutorial/deploy-replica-set`.

Update Secondaries using Initial Sync
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you do not want to manually copy the data directories onto each
member of your replica set, you can choose to add members to the
replica set and catch them up using initial sync.

#. Ensure that the data directories on the prospective replica set
members are empty.

#. Add the members to the replica set. :ref:`Initial Sync
<replica-set-initial-sync>` will copy the data from the
:term:`primary` to the other members of the replica set.