-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Tutorial copy db #79
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
Tutorial copy db #79
Changes from all commits
2e8f15d
c2638f3
515cdb9
c67ffd4
66721b0
fda47bb
8450a69
6f2ee44
414738f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
=========================================== | ||
Copy Databases Between ``mongod`` Instances | ||
=========================================== | ||
|
||
.. default-domain:: mongodb | ||
|
||
Sypnosis | ||
-------- | ||
|
||
In some situations, you may need to copy a :term:`database` from one | ||
MongoDB instance to another. For example, you may use these commands | ||
to support migrations and data warehousing, seeding test environments, | ||
or to help perform backups. The :dbcommand:`copydb` and | ||
:dbcommand:`clone` function in MongoDB can help in these situations. | ||
|
||
This document oulines the procedure to copy MongoDB databases using | ||
the :dbcommand:`copydb` and :dbcommand:`clone` command. | ||
|
||
The :dbcommand:`copydb` and :dbcommand:`clone` are faster than | ||
:program:`mongodump` and :program:`mongorestore` because the commands | ||
do not require intermediate files. | ||
|
||
.. note:: | ||
|
||
:dbcommand:`copydb` and :dbcommand:`clone` do not produce | ||
point-in-time snapshots of the source database. Write traffic to | ||
the source or destination database during the copy process may | ||
result in databases with different contents. | ||
|
||
Considerations | ||
-------------- | ||
|
||
- You must run :dbcommand:`copydb` or :dbcommand:`clone` on the | ||
destination server. | ||
|
||
- You can use :dbcommand:`copydb` or :dbcommand:`clone` with unsharded | ||
databases in a :term:`shard cluster` when you're connected directly | ||
to the :program:`mongod` instance. | ||
|
||
- You can run :dbcommand:`copydb` or :dbcommand:`clone` commands on a | ||
:term:`secondary` member. | ||
|
||
- There must be enough free disk storage on the destination server for | ||
the database from the source server. Use the ``db.stats()`` function | ||
to check the size of the database on the source :program:`mongod` | ||
instance. For more information on ``db.stats()`` see the | ||
:doc:`database statistics </reference/database-statistics>` section. | ||
|
||
Process | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Procedures. |
||
------- | ||
|
||
Copy a Database to Another Server | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Use the :dbcommand:`copydb` command to transfer a database from one | ||
MongoDB instance to another, such as from a development instance to a | ||
production instance. The :func:`db.copyDatabase()` helper in the | ||
:program:`mongo` shell provides a wrapper around the | ||
:dbcommand:`copydb`. | ||
|
||
This is useful when you want to move a database from the development | ||
environment to the production environment, or create a remote-branch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not something that happens or that will seem reasonable to users. The reverse may happen, where you might seed development servers using a portion of production data. You may also migrate data into production from a staging environment which isn't the same. and also is much more likely to pass through your application rather than go directly using these commands. |
||
of the database to archive the current database on a different server. | ||
|
||
To copy the database named ``test`` on server ``db0.example.net`` to | ||
another server ``db1.example.net`` renaming it ``records`` in the process. | ||
|
||
- Verify name of database, ``test``, you want to copy on the source | ||
server, ``db0.example.net``. | ||
|
||
- Log onto the destination server, ``db1.example.net``. | ||
|
||
- Run the following operation from the :program:`mongo` shell on the | ||
destination server, ``db1.example.net``: | ||
|
||
.. code-block:: javascript | ||
|
||
db.copyDatabase( "test", "records", db0.example.net ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think i was unclear in a previous comment, but I think we need to link to both the shell helpers and the command forms. I think you can do this, right before the example as in: "run the :func: |
||
|
||
Rename a Database | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
Use the :dbcommand:`copydb` command to copy a database within the same | ||
server also renaming the database. This is useful when the contents of | ||
the database has changed from the initial naming of the database and a | ||
new name would be more appropriate. The :func:`db.copyDatabase()` | ||
helper in the :program:`mongo` shell provides a wrapper around the | ||
:dbcommand:`copydb`. | ||
|
||
To rename a database from ``test`` to ``records`` within the | ||
same server, ``db1.example.net``. | ||
|
||
- Log onto the destination server, ``db1.example.net``. | ||
|
||
- Run the following command from the :program:`mongo` shell on the | ||
destination server, ``db1.example.net``: | ||
|
||
.. code-block:: javascript | ||
|
||
db.copyDatabase( "test", "records" ) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for all of these examples I think it's important to provide links to the database command names (in case people want to use the drivers.) also to note might be good to what the output is in the shell. |
||
Copy a Database with Authentication | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
If the source server requires ``username`` and ``password``, you can | ||
include these parameters in the :dbcommand:`copydb` command. This is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this kind of sentence is incorrect/abstruse: it says "copydb supports authentication" in 17 words (and is missing an article.) It also puts the most important part of the sentence at the end. Putting the important parts of a sentence at the beginning makes documentation easier to read, and more likely to convey the right message to users who aren't reading carefully (which is a a safe assumption to make of *any" reader.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I completely agree. This is something I am embarrassed about. |
||
useful where you need to create offsite backups, a local development | ||
system which has data from the production system, or create a system | ||
to produce reports. The :func:`db.copyDatabase()` helper in the | ||
:program:`mongo` shell provides a wrapper around the | ||
:dbcommand:`copydb`. | ||
|
||
To copy ``test`` to ``records`` from the source server | ||
``db0.example.net``, which requires ``username`` and ``password`` | ||
authentication, to ``db1.example.net`` use the following procedure. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs a colon. |
||
|
||
- Log onto the destination server, ``db1.example.net``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you'll see the change in my diff, but "Log onto" isn't what you mean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I remember this now. I think I wrote this before we talked about the difference between Logon and Login... |
||
|
||
- Run the following command from the :program:`mongo` shell on the | ||
destination server, ``db1.example.net``. | ||
|
||
.. code-block:: javascript | ||
|
||
db.copyDatabase( "test", "records", db0.example.net, "username", "password") | ||
|
||
Clone a Database | ||
~~~~~~~~~~~~~~~~ | ||
|
||
The :dbcommand:`clone` command copies a database between | ||
:program:`mongod` instances; however, :dbcommand:`clone` preserves the | ||
database name on the destination server. For many operations, | ||
:dbcommand:`clone` has identical functionality and a simpler syntax | ||
than :dbcommand:`copydb`. The :func:`db.cloneDatabase()` helper in the | ||
:program:`mongo` shell provides a wrapper around :dbcommand:`clone`. | ||
|
||
To clone a database from ``db0.example.net`` to ``db1.example.net``, on | ||
``db1.example.net`` follow these procedures. | ||
|
||
- Log onto the destination server, ``db1.example.net``. | ||
|
||
- Run the following command from the :program:`mongo` shell on the | ||
destination server, ``db1.example.net``: | ||
|
||
.. code-block:: javascript | ||
|
||
db.cloneDatabase( "db0.example.net" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.