Copying database from local to remote server

97 views
Skip to first unread message

Yaroslav Kyrpych

unread,
Dec 15, 2014, 12:43:36 AM12/15/14
to mongod...@googlegroups.com
Hi,

I need to copy database from local pc to remote server. What's the best practice for doing it? I saw examples with mongodump and mongorestore while there is also db.copyDatabase(). Related question - what's the best way of doing it if I need to do it often?

I saw generic example for copyDatabase as follows:
db.copyDatabase(<from_db>, <to_db>, <from_hostname>, <username>, <password>);

Is there specific example that would should in detail how it's done?

Thank you,

Yaroslav

Will Berkeley

unread,
Dec 15, 2014, 11:40:26 AM12/15/14
to mongod...@googlegroups.com
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:

db.copyDatabase("your_db", "my_db", "yourserver.yourdomain.com", "guest", "password")

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

Yaroslav Kyrpych

unread,
Dec 18, 2014, 9:29:01 PM12/18/14
to mongod...@googlegroups.com
Will,

Thank you for explanation - now I understand that replication is the better way to do it.

I read that I need at least three instances for replication. What if I have just local pc with database and remote server on VPS. I don't plan to add another server at this point. Is it possible with two machines? How would I do that with just two machines?

I am also not very clear on mechanics of replication process. In my case database on local pc will be primary and local machine is not always online. Server would host secondary. How would replication work in such a setting? Do I need to always manually set replication when I start local pc?

What would be bind_ip for my local machine?

Database on a server would be used for reads, no writes.

Thank you,

Yaroslav



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/7cc37e46-f3ca-479f-b6e2-7fd432a00b9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages