How to create backup of MongoDB - Backup and restore - In 1 minute

You are here : Home / MongoDB Tutorial



Contents of page >

1) How to create backup of MongoDB?
Please ensure mongod (mongoDB server)  is running before executing the follow up commands.


Go to bin directory of MongoDB
And type mongodump.
C:\Program Files\MongoDB\Server\3.0\bin > mongodump


It will create backup in C:\Program Files\MongoDB\Server\3.0\bin\dump\


Screenshot >


2) How to backup only specific database in mongoDB server >


C:\Program Files\MongoDB\Server\3.0\bin > mongodump --db enterDbName --out directoryOfBackup
It will create backup of database enterDbName in directory directoryOfBackup.


Example >
C:\Program Files\MongoDB\Server\3.0\bin > mongodump --db mydb --out \dump\
It will create backup of database mydb in directory C:\Program Files\MongoDB\Server\3.0\bin\dump\mydb


Screenshot>


3) How to backup only specific collection of database in mongoDB server >
C:\Program Files\MongoDB\Server\3.0\bin > mongodump --collection enterCollectionName --db enterDbName --out directoryOfBackup
It will create backup of collection enterCollectionName of database enterDbName in directory directoryOfBackup.


Example >
C:\Program Files\MongoDB\Server\3.0\bin > mongodump --collection employee --db mydb --out \dump\
It will create backup of collection employee of database mydb in directory C:\Program Files\MongoDB\Server\3.0\bin\dump\mydb


Screenshot>


4) How to RESTORE mongoDB data >


It will restore the backed up data from the backup directory.


C:\Program Files\MongoDB\Server\3.0\bin > mongorestore


It will restore the backed up data from the default backup directory i.e. \dump (C:\Program Files\MongoDB\Server\3.0\bin\dump\).


Screenshot>


5) How to RESTORE specific database in mongoDB >


It will restore the backed up data from the backup directory.


C:\Program Files\MongoDB\Server\3.0\bin > mongorestore --db new_mydb dump\mydb


It will restore the backed up database in new database (i.e in new_mydb) from the directory i.e. C:\Program Files\MongoDB\Server\3.0\bin\dump\mydb.


Screenshot>


6) Summary -


So in this mongoDB tutorial we learned How to create backup of MongoDB. And How to restore mongoDB from that backup.


1) How to create backup of MongoDB?
Go to bin directory of MongoDB
And type mongodump.
C:\Program Files\MongoDB\Server\3.0\bin > mongodump


2) How to backup only specific database in mongoDB server >
C:\Program Files\MongoDB\Server\3.0\bin > mongodump --db enterDbName --out directoryOfBackup
It will create backup of database enterDbName in directory directoryOfBackup.


3) How to backup only specific collection of database in mongoDB server >
C:\Program Files\MongoDB\Server\3.0\bin > mongodump --collection enterCollectionName --db enterDbName --out directoryOfBackup
It will create backup of collection enterCollectionName of database enterDbName in directory directoryOfBackup.


4) How to RESTORE mongoDB data >
It will restore the backed up data from the backup directory.
C:\Program Files\MongoDB\Server\3.0\bin > mongorestore


5) How to RESTORE specific database in mongoDB >
It will restore the backed up data from the backup directory.
C:\Program Files\MongoDB\Server\3.0\bin > mongorestore --db new_mydb dump\mydb

Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter. You may join our fbGroup or linkedInGroup as well.


RELATED LINKS>

Labels: MongoDB
eEdit
Must read for you :