mongodb – remote copy of database

MongoDB
There are different way of copying of data from one server to another or from one cluster to another cluster.

by using mongodump utility tool you can view another article : How to move data from staging server to production server of mongodb

By using db.copyDatabase() on terminal

run the following after logged-in into mongodb server.

file: mongoDB_sync.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
 
## fileName: mongoDB_sync.sh ####
 
#Sync mongodb database from remote to local where you run this.
#NOTE: be careful this overwrites the local copy (from where run) of the database if you have.
## here local means where you run this script, and remote means from where you want to get data .
 
remoteHost='mongodb.mysoftkey.com'
remoteUserDB='mysoftkeyUser'
remoteDBPasswd='password123'
remoteMongoDB='orderdb'
localMongoDB='orderdb'
 
mongo $localDb --eval "use '$localMongoDB'; db.dropDatabase(); db.copyDatabase('$remoteMongoDB', '$localMongoDB', '$remoteHost', '$remoteUserDB', '$remoteDBPasswd')"

By using db.copyDatabase() on mongos terminal

Syntax to copy database as:

1
>db.copyDatabase(fromdb, todb, fromhost, username, password, mechanism);

example of copyDatabase()

1
>db.copyDatabase('orderdb', 'orderdb', '10.72.17.16:27017')

By using db.cloneCollection() on mongos terminal

1
2
 
>db.cloneCollection('10.72.17.16:27017', 'orderdb.orderColl');

Write your comment to improve this post. Happy Learning :)

Please follow and like us:
RSS
Follow by Email
Facebook
LinkedIn
Google+

Leave a Reply

Your email address will not be published. Required fields are marked *