For a one-time full copy in 2.6, using mongodump/mongorestore works well. If the source database is being written to as the dump is created, make sure to use --oplog and --oplogReplay in mongodump and mongorestore, respectively. If you can shut off the source mongod for a time, just copying the actual database files is very efficient. db.copyDatabase essentially reads all the data from the source and inserts it into the target (running on the target), but if the source or target database are being written to during the copy then the final source and target datasets can diverge.
For a specific example of the db.copyDatabase function:
and remember that the "<to_hostname>" is implicit in the fact that db.copyDatabase runs on the target server. In this case, the hostname of the target server would be something like "
myserver.mydomain.com". The user guest/password is a user on the source machine with sufficient privileges.
Why do you need to frequently copy a database from one server to another? Would using a replica set to keep the data in sync not work?
-Will