This post discusses how to backup and restore mongodb database(s) quickly using mongodump and mongorestore.

Backup all Databases

mongodump dump all database(s) from your mongodb. The default location is <presentWorkingDirectory>/dump.


~ hpatel$ mongodump
  	

Backup specific Databases to specific directory

We can explicity specify database using -d option. Location can be specified explicity using -o option.


~ hpatel$ mongodump -d demo -o /Users/hpatel/dump
  	

Restore all Databases

Go to the default location where dump directory is present. mongorestore will restore all database under dump directory.


~ hpatel$ mongorestore
  	

Restore specific Databases from directory

Use -d to specify a database to restore. “demo” is the name of database in below command.


~ hpatel$ mongorestore -d demo /Users/hpatel/dump/demo
  	

Help


Hirals-MacBook-Air:~ hpatel$ mongodump --help
Hirals-MacBook-Air:~ hpatel$ mongorestore --help
	  	

Conclusion

mongodump and mongorestore is very helpful in backup and restore of mongodb databases.

References

Mongodump documentation
Mongorestore documentation