mongo db backup

Posted January 9, 2017 8.4k views
MongoDBUbuntuUbuntu 16.04

I tried to set up Backups with mongodump command.
I used this Tutorial:

But when i execute folowing command:
sudo mongodump –db newdb –out /var/backups/mongobackups/date +"%m-%d-%y"
I get this error:

Failed: error getting collections for database ibyc_db: error running listCollections. Database: ibyc_db Err: not authorized on ibyc_db to execute command { listCollections: 1, cursor: {} }

I am running a node.js application and it works fine. The application is able to write and read to the database.

Could someone help with the mongodump command?

Thx a lot

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

You may need to provide a username and password to the mongodump command and also ensure that the user that you are using has the “backup” role on it which will provide the needed permissions.

From the official documentation for mongodump:

To run mongodump against a MongoDB deployment that has access control enabled, you must have privileges that grant find action for each database to back up. The built-in backup role provides the required privileges to perform backup of any and all databases.

Changed in version 3.2.1: The backup role provides additional privileges to back up the system.profile collections that exist when running with database profiling. Previously, users required an additional read access on this collection.
  • thanks for your quick answer.
    I tried with the user/password that we use for our application, dont work.
    Did i understand you right: I have to create another user with backup role and use it in the mongodump command?


  • could you provide a snipped how to grant the “backup” role to a user?

    • This section of the official documentation covers how to grant a role to a user.

      • This section does not explain it clear.

        Role “backup” exists only in “admin” database. To create user for backup purposes you need in Mongo shell

        use db1
        db.createUser({user: 'backup_user', pwd: '*********', roles: [{ role: 'backup',db:'admin'}]})

        Where “db1” is your database. Statement is reading as “create user backup_user in db1 database with role backup which exists in admin database”.