2/28/2018 MongoDB Create Backup
MongoDB - Create Backup
Advertisements
Previous Page Next Page
In this chapter, we will see how to create a backup in MongoDB.
Dump MongoDB Data
To create backup of database in MongoDB, you should use mongodump command. This
command will dump the entire data of your server into the dump directory. There are
many options available by which you can limit the amount of data or create backup of your
remote server.
Syntax
The basic syntax of mongodump command is as follows −
>mongodump
Example
Start your mongod server. Assuming that your mongod server is running on the localhost
and port 27017, open a command prompt and go to the bin directory of your mongodb
instance and type the command mongodump
Consider the mycol collection has the following data.
>mongodump
The command will connect to the server running at 127.0.0.1 and port 27017 and back
all data of the server to directory /bin/dump/. Following is the output of the command −
https://www.tutorialspoint.com/mongodb/mongodb_create_backup.htm 1/3
2/28/2018 MongoDB Create Backup
Following is a list of available options that can be used with the mongodump command.
Syntax Description Example
mongodump --host HOST_NAME -- This commmand will mongodump --host
port PORT_NUMBER backup all databases of tutorialspoint.com --port
specified mongod instance. 27017
mongodump --dbpath DB_PATH -- This command will backup mongodump --dbpath
out BACKUP_DIRECTORY only specified database at /data/db/ --out
specified path. /data/backup/
mongodump --collection This command will backup mongodump --collection
COLLECTION --db DB_NAME only specified collection of mycol --db test
specified database.
Restore data
To restore backup data MongoDB's mongorestore command is used. This command
restores all of the data from the backup directory.
Syntax
The basic syntax of mongorestore command is −
>mongorestore
Following is the output of the command −
https://www.tutorialspoint.com/mongodb/mongodb_create_backup.htm 2/3
2/28/2018 MongoDB Create Backup
Previous Page Next Page
Advertisements
Tutorials Point (India) Pvt. Ltd.
YouTube 52K
Write for us FAQ's Helping Contact
© Copyright 2018. All Rights Reserved.
Enter email for newsletter go
https://www.tutorialspoint.com/mongodb/mongodb_create_backup.htm 3/3