Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use backup and restore all databases from mongodb?

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?
like image 344
alvas Avatar asked Jan 30 '13 04:01

alvas


People also ask

What is the command to create backup and restore the MongoDB?

The Mongodump command dumps a backup of the database into the “. bson” format, and this can be restored by providing the logical statements found in the dump file to the databases. The Mongorestore command is used to restore the dump files created by Mongodump.

How do I import an entire database into MongoDB?

To import data to a MongoDB database, you can use mongoimport to import specific collections data, or you can use mongorestore to import a binary (BSON) full database backup. The exported database file must be stored locally on the same machine as your client.


1 Answers

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

like image 186
attish Avatar answered Oct 19 '22 01:10

attish