Skip to content

Commit 6f2ee44

Browse files
author
Andrew Leung
committed
updating copyDB tutorial
1 parent 8450a69 commit 6f2ee44

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

draft/tutorial/copy-database.txt

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,69 @@
1-
=============================
2-
How to Copy or Clone Database
3-
=============================
1+
===========================================
2+
Copy Databases Between ``mongod`` Instances
3+
===========================================
44

55
.. default-domain:: mongodb
66

77
Sypnosis
88
--------
99

10-
One may need to copy a :term:`database` from one server to another,
11-
rename a database, move a database within the same server, seed a
12-
development server from a production server, or create a test
13-
environment with production data. The :dbcommand:`copydb` and
14-
:dbcommand:`clone` function in MongoDB can help one in these
15-
situations.
10+
In some situations, you may need to copy a :term:`database` from one
11+
MongoDB instance to another. For example, you may use these commands
12+
to support migrations and data warehousing, seeding test environments,
13+
or to help perform backups. The :dbcommand:`copydb` and
14+
:dbcommand:`clone` function in MongoDB can help in these situations.
1615

1716
This document oulines the procedure to copy MongoDB databases using
1817
the :dbcommand:`copydb` and :dbcommand:`clone` command.
1918

2019
The :dbcommand:`copydb` and :dbcommand:`clone` are faster than
21-
:program:`mongodump` and :program:`mongorestore` because there are no
22-
intermediate files to be created in the :dbcommand:`copydb` process.
20+
:program:`mongodump` and :program:`mongorestore` because the commands
21+
do not require intermediate files.
2322

2423
.. note::
2524

2625
:dbcommand:`copydb` and :dbcommand:`clone` do not produce
2726
point-in-time snapshots of the source database. Write traffic to
28-
the source database during the copy process may result in databases
29-
with different contents.
27+
the source or destination database during the copy process may
28+
result in databases with different contents.
3029

3130
Considerations
3231
--------------
3332

34-
- :dbcommand:`copydb` or :dbcommand:`clone` must be run on the
33+
- You must run :dbcommand:`copydb` or :dbcommand:`clone` on the
3534
destination server.
3635

37-
- :dbcommand:`copydb` or :dbcommand:`clone` do not work with a sharded
38-
database, such as a database a from :term:`shard cluster`.
36+
- You can use :dbcommand:`copydb` or :dbcommand:`clone` with unsharded
37+
databases in a :term:`shard cluster` when you're connected directly
38+
to the :program:`mongod` instance.
3939

40-
- :dbcommand:`copydb` or :dbcommand:`clone` commands may be run
41-
on a :term:`secondary` member.
40+
- You can run :dbcommand:`copydb` or :dbcommand:`clone` commands on a
41+
:term:`secondary` member.
4242

4343
- There must be enough free disk storage on the destination server for the
44-
database from the source server.
44+
database from the source server. You can check for the size of the
45+
database on the source server by issuing command:
46+
47+
.. code-block::
48+
49+
db.runCommand()
4550

4651
Process
4752
-------
4853

4954
Copy a Database to Another Server
5055
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5156

52-
Use the :dbcommand:`copydb` command when you need to transfer a database from
53-
one server to another, such as from a development server a production
54-
server, changing the database name in the process.
57+
Use the :dbcommand:`copydb` command to transfer a database from
58+
one MongoDB instance to another, such as from a development instance
59+
to a production instance.
5560

5661
This is useful when you want to move a database from the development
5762
environment to the production environment, or create a remote-branch of the database
5863
to archive the current database on a different server.
5964

6065
To copy the database named ``test`` on server ``db0.example.net`` to
61-
another server ``db1.example.net`` renaming it ``records``.
66+
another server ``db1.example.net`` renaming it ``records`` in the process.
6267

6368
- Verify name of database, ``test``, you want to copy on the source
6469
server, ``db0.example.net``.
@@ -75,10 +80,10 @@ another server ``db1.example.net`` renaming it ``records``.
7580
Rename a Database
7681
~~~~~~~~~~~~~~~~~
7782

78-
Use the :dbcommand:`copydb` command to rename a database within the same
79-
server. This is useful when the contents of the database has changed
80-
from the initial naming of the database and a new name would be more
81-
appropriate.
83+
Use the :dbcommand:`copydb` command to copy a database within the same
84+
server also renaming the database. This is useful when the contents of
85+
the database has changed from the initial naming of the database and a
86+
new name would be more appropriate.
8287

8388
To rename a database from ``test`` to ``records`` within the
8489
same server, ``db1.example.net``.
@@ -95,11 +100,11 @@ same server, ``db1.example.net``.
95100
Copy a Database with Authentication
96101
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97102

98-
If the source server requires ``username`` and ``password``
99-
authentication, you can include these parameters in the
100-
:dbcommand:`copydb` command. This is useful where you need to create
101-
offsite backups, a local development system which has data from the
102-
production system, or create a system to produce reports.
103+
If the source server requires ``username`` and ``password``, you can
104+
include these parameters in the :dbcommand:`copydb` command. This is
105+
useful where you need to create offsite backups, a local development
106+
system which has data from the production system, or create a system
107+
to produce reports.
103108

104109
To copy ``test`` to ``records`` from the source server
105110
``db0.example.net``, which requires ``username`` and ``password``
@@ -112,23 +117,16 @@ authentication, to ``db1.example.net`` use the following procedure.
112117

113118
.. code-block:: javascript
114119

115-
db.copyDatabase( "test", "records", db0.example.net, username, password)
116-
117-
.. TODO verify that username & password do not have to be in quotes...?
120+
db.copyDatabase( "test", "records", db0.example.net, "username", "password")
118121

119122
Clone a Database
120123
~~~~~~~~~~~~~~~~
121124

122125
The :dbcommand:`clone` command copies a database between :program:`mongod`
123126
instances; however, :dbcommand:`clone` preserves the database
124-
name. For many operations :dbcommand:`clone` has a more
125-
straightforward syntax than :dbcommand:`copydb` but are functionally
126-
the same.
127-
128-
You can use :dbcommand:`clone` to quickly create a :term:`secondary`
129-
member from the :term:`primary` dataset, to seed a development system
130-
with production data, or to create a system to run reports on instead
131-
of the main production system.
127+
name on the destination server. For many operations,
128+
:dbcommand:`clone` has identical functionality and a simpler syntax
129+
than :dbcommand:`copydb`.
132130

133131
To clone a database from ``db0.example.net`` to ``db1.example.net``, on
134132
``db1.example.net`` follow these procedures.

0 commit comments

Comments
 (0)