发布于 2015-09-14 14:58:49 | 166 次阅读 | 评论: 0 | 来源: 网络整理
The copydb command copies a database from a remote host to the current host. The command has the following syntax:
{ copydb: 1:
fromhost: <hostname>,
fromdb: <db>,
todb: <db>,
slaveOk: <bool>,
username: <username>,
password: <password>,
nonce: <nonce>,
key: <key> }
All of the following arguments are optional:
You can omit the fromhost argument, to copy one database to another database within a single MongoDB instance.
You must run this command on the destination, or the todb server.
Be aware of the following behaviors:
copydb can run against a slave or a non-primary member of a replica set. In this case, you must set the slaveOk option to true.
copydb does not snapshot the database. If the state of the database changes at any point during the operation, the resulting database may be inconsistent.
You must run copydb on the destination server.
The destination server is not locked for the duration of the copydb operation. This means that copydb will occasionally yield to allow other operations to complete.
If the remote server has authentication enabled, then you must include a username and password. You must also include a nonce and a key. The nonce is a one-time password that you request from the remote server using the copydbgetnonce command. The key is a hash generated as follows:
hex_md5(nonce + username + hex_md5(username + ":mongo:" + pass))
If you need to copy a database and authenticate, it’s easiest to use the shell helper:
db.copyDatabase(<remote_db_name>, <local_db_name>, <from_host_name>, <username>, <password>)