How to use backup and restore all databases from mongodb?

alvas picture alvas · Jan 30, 2013 · Viewed 8k times · Source

If i want to do a generic backup for all databases in mongodb, is it that all i have to do is:

$ mongodump

And if i want to restore the latest dump i've created, all i need to do is:

$ mongorestore
  • Where are the backups from the mongodump stored?
  • How to i specify a specific dump for all databases to be restored?

Answer

attish picture attish · Jan 30, 2013

The backups are stored in the directory that you have specified with the --out option in command line. If you do not specify any output dir the backup will be placed to ./dump directory. With the mongorestore you have to specify the directory where you have dumped before as a command line argument.

On sharded environment the backup will be flattened if you use mongodump through a mongos. After restore you will have to re-shard the collections. so restoring not always effortless. See documentation: http://docs.mongodb.org/manual/tutorial/backup-small-sharded-cluster-with-mongodump/

You can dump directly the db folders too, check the cli options.

For sharded clusters you can check the possibilities here: http://docs.mongodb.org/manual/administration/backups/#sharded-cluster-backups