- Reference >
- Database Commands >
- Administration Commands >
- copydb
copydb¶
On this page
Definition¶
-
copydb
¶ Copies a database from a remote host to the current host, or from one name to another on the current host. See also
db.copyDatabase()
,clone
, anddb.cloneDatabase()
. Also see MongoDB Backup Methods and Import and Export MongoDB Data documentation for more information.Call
copydb
on the destination server with the following syntax:copydb
accepts the following options:Field Type Description fromhost
string Optional. Hostname of the source mongod
instance. If omitted,copydb
copies one database to another within a single MongoDB instance.fromdb
string Name of the source database. todb
string Name of the target namespace. slaveOk
boolean Optional. Set slaveOK
totrue
to allowcopydb
to copy data from secondary members as well as the primary.fromhost
must also be set.username
string Optional. The username credentials on the fromhost
MongoDB deployment.nonce
string Optional. A single use shared secret generated on the remote server using the copydbgetnonce
command.key
string Optional. A hash of the password used for authentication.
Behavior¶
Be aware of the following properties of copydb
:
copydb
runs on the destinationmongod
instance, i.e. the host receiving the copied data.copydb
requires enough free disk space on the host instance for the copied database. Use the:method:db.stats() operation to check the size of the database on the sourcemongod
instance.copydb
andclone
do not produce point-in-time snapshots of the source database. Write traffic to the source or destination database during the copy process will result divergent data sets.copydb
does not lock the destination server during its operation, so the copy will occasionally yield to allow other operations to complete.
Authentication¶
Do not use
copydb
on amongod
instance that usesauth
in combination with users who have privileges specified using the role-based user documents introduced in 2.4.To use
copydb
with access control enabled you must use the legacy user privilege documents from v2.2 and prior.If the remote server has authentication enabled, then you must include a
username
,nonce
, andkey
. Thenonce
is a one-time password that you request from the remote server using thecopydbgetnonce
command. Thekey
is a hash generated as follows:
Replica Sets¶
With read preference configured to set the slaveOk
option
to true
, you may run copydb
on a secondary
member of a replica set.