- 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
copydbon the destination server with the following syntax:copydbaccepts the following options:Field Type Description fromhoststring Optional. Hostname of the source mongodinstance. If omitted,copydbcopies one database to another within a single MongoDB instance.fromdbstring Name of the source database. todbstring Name of the target namespace. slaveOkboolean Optional. Set slaveOKtotrueto allowcopydbto copy data from secondary members as well as the primary.fromhostmust also be set.usernamestring Optional. The username credentials on the fromhostMongoDB deployment.noncestring Optional. A single use shared secret generated on the remote server using the copydbgetnoncecommand.keystring Optional. A hash of the password used for authentication.
Behavior¶
Be aware of the following properties of copydb:
copydbruns on the destinationmongodinstance, i.e. the host receiving the copied data.copydbrequires 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 sourcemongodinstance.copydbandclonedo 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.copydbdoes not lock the destination server during its operation, so the copy will occasionally yield to allow other operations to complete.
Authentication¶
Do not use
copydbon amongodinstance that usesauthin combination with users who have privileges specified using the role-based user documents introduced in 2.4.To use
copydbwith 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. Thenonceis a one-time password that you request from the remote server using thecopydbgetnoncecommand. Thekeyis 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.