Mongodump output

142 views
Skip to first unread message

Martinus Martinus

unread,
Oct 22, 2012, 10:28:59 PM10/22/12
to mongod...@googlegroups.com
Hi,

Is there any way to make my mongodump output to be send directly into remote machine folder? For example I have two machines A and B, I want to put my mongodump from machine A directly to machine B "/backup" folder what should I put after --out parameter?

mongodump --host machine_A --port 10001 --out ?

Thanks.

Andre de Frere

unread,
Oct 23, 2012, 1:26:38 AM10/23/12
to mongod...@googlegroups.com
Hi,

Could you just run mongodump from machine_b?  As long as you can connect to machine_a from machine_b (which I assume you can, if you are trying to drop files there) you could just run the command you have given from machine_b and give the --out as the "/backup" directory.

Regards,
André

Martinus Martinus

unread,
Oct 23, 2012, 2:47:17 AM10/23/12
to mongod...@googlegroups.com
Hi Andre,

Thanks for your answer. Yeah, that could also be a solution. And if I have 2 shards where each shard has 3 replicaSets, can I do this to make mongodump for my shard 1 and shard 2 (without lock, because mongodump can't be used when the database is locked) :

mongodump --host shard1 --port 10001 --out /backup/mongodump1 --oplog

mongodump --host shard2 --port 10004 --out /backup/mongodump2 --oplog
 
where 10001 and 10004 are each the master node for each replicaSets. And for config server, will it be better if I do :

mongodump --host config1 --port 20001 --db config --out /backup

or

mongodump --dbpath /data/config1 --out /backup

Thanks.

Best regards,

Martinus

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Andre de Frere

unread,
Oct 25, 2012, 12:15:03 AM10/25/12
to mongod...@googlegroups.com
Hi Martinus,

You are able to take a mongodump from the primaries while they are running if you wish, but you should be aware of the load that this process will put on your node.  It might be better to take the backups from a secondary node, or a secondary hidden node.  If you back up from secondaries, not only will there be less pressure on your primary but you will also be able to lock the secondaries if needed.  If necessary you could even stop the process on the secondary entirely.

You should also be aware that you must stop the balancer (and wait for chunk migrations to finish) before doing any of the backups.  If you skip this step, then you might find duplicate or spurious data.

Either of your techniques for backing up the config DB should be okay, as long as the balancer is off at the time.

Regards,
André

Martinus Martinus

unread,
Oct 25, 2012, 3:23:10 AM10/25/12
to mongod...@googlegroups.com
Hi Andre,

Thanks for your answer. I remember if I put a lock on the secondary node and shut it down, I can't use mongodump to make a backup out of it. Can you explain more about secondary hidden node? and after I stop the balancer from mongos, how do I know if the chunk migrations is already finish or not before I do the backup process on shard servers? Because currently I just followed the steps explained  in mongodb website : 1. stop the balancer and 2. mongodump the config db.

Thanks.

--

Andre de Frere

unread,
Oct 26, 2012, 12:39:19 AM10/26/12
to mongod...@googlegroups.com
Hi Martinus,

You can still use mongodump to dump databases even if the secondary is down.  This is done through the --dbpath option which allows mongodump to connect directly to the db files without the mongod process.  You can find more information at the documentation: http://docs.mongodb.org/manual/reference/mongodump/

A hidden node is one that has a priority of 0 (so it cannot be elected primary) and also cannot have client read requests directed to it.  It will still take part in elections, even if it cannot become primary.  You can find more information in the documentation here:  http://docs.mongodb.org/manual/administration/replica-sets/#replica-set-hidden-members

You can check the locks collection in the config database to see if the balancer is currently doing a migration.  In 2.2 this is taken care of with the "sh.stopBalancer()" shell function, but in prior versions you can do something similar with:

while (db.locks.findOne({_id: "balancer", state: {$ne: 0}}) != null) { sleep(1000); }

Regards,
André

Martinus Martinus

unread,
Oct 26, 2012, 2:55:26 AM10/26/12
to mongod...@googlegroups.com
Hi Andre,

Thank you for your complete explanations. I already use mongo 2.2.0, so if I do sh.stopBalancer() will it be the same as doing :

1. sh.setBalancerState(false) or
2. use config
    db.settings.update({ _id : "balancer" }, { $set : { stopped : true }}, true);

Thanks.

Best regards,

Martinus

Andre de Frere

unread,
Oct 28, 2012, 5:40:44 PM10/28/12
to mongod...@googlegroups.com
Hi Martinus,

The two commands you have listed are functionally equivalent.  

If you have a look at the sh.stopBalancer() command you will see that it does sh.setBalancerState(false) (which is equivalent of db.getSiblingDB("config").settings.update({_id:"balancer"},{$set:{stopped:true}},true) ) and then also waits for the locks to resolve.

The waiting for the locks to resolve is the new functionality in sh.stopBalancer() from 2.2.

Regards,
André

Martinus Martinus

unread,
Oct 29, 2012, 12:13:14 AM10/29/12
to mongod...@googlegroups.com
Hi Andre,

Thanks for your helpful explanation.

Best regards,

Martinus
Reply all
Reply to author
Forward
0 new messages