Last Updated: February 25, 2016
·
2.046K
· saadshamim

Backup and Restore MongoDb

Backup using mongodump

1) lets make a directory to dump our mongo db into

mkdir mongdump

2) lets backup into the mongdump folder

mongodump -h localhost:27017 -d dbname -o location/to/mongdump

replace "dbname" with the name of the database

3) go into the mongdump folder to verify the backup is there, the back file will have the .bson extension

Restore using mongorestore

mongorestore --drop -d dbname /location/to/mongdump/dbname

dbname should be replace by the name of your database. Also when you did a mongodump into the folder mongdump most likely a subfolder with the db name was created, hence the /location/to/mongdump/dbname. you always want to point to the folder that contains the .BSON files