How to backup MongoDB database

Backing up any kind of data store is essential for business continuity point of view. Use of MongoDB does not exclude any application from not having to back up the database and collections on regular basis. In this post, I will show how to use mongodump command line utility to backup on-premises deployment of MongoDB.


mongodump is a command line utility. It is not shipped and install with MongoDB server. You will need to download and install it separately. You can use following link to get the command line Tools that you can install.

MongoDB Tools

Backup Command

You will use following command to backup a database.

mongodump /uri:mongodb://my-blockchain 
  • /uri: You will specify your server's URL, IP, Server name etc.
  • /out: This is the output path where backup files will be created
  • /db: This option is used to specify name of the database you want to backup
  • /username: If your database requires authentication, specify user name that you used to login
  • /password: Use this option to specify password for the user that you will use to authenticate
  • /authenticationDatabase: Use this option to specify database that contains authentication information
  • /gzip: If you want to compress backup files, use this option. If you do not intend to compress, you can omit this option

There are more option to have finer control on backup process. The above command and options are minimum you will need to perform the operation. If there is any issue with options, you could run into errors when running the command line. Following are some of the errors that are commonly observed.

Failed: can't create session: could not connect to server: connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

The above error is thrown when you have not specified correct authentication credentials.

Failed: error creating intents to dump: error getting collections for database `xxxx`: (Unauthorized) not authorized on xxxxx to execute command { listCollections: 1, filter: {}, cursor: {}, lsid: { id: UUID("bd7290d9-e552-46cc-8c28-5052e0c94697") }, $db: "xxxxxx" }

The above error means that the user you are using does not have rights to perform backup operations. To fix this issue, you will need to grant backup role to the user.

This is all you will need to create backup of your MongoDB databases.




15.6 °C / 60.0 °F

weather conditions Clouds

Monthly Posts

Blog Tags