7
votes

I'm new to MongoDB and I'm testing some basic backup and restore operations in a single MongoDB instance.

All tests worked fine except for restoring users.

I first created a backup of a test database (db_test) using the following command:

$ mongodump -u adm_dump --authenticationDatabase admin -d db_test --dumpDbUsersAndRoles -o /opt/backup/mongodump_db_test

adm_dump is a user I created with "restore" and "backup" roles.

2 users are present in db_test database with "readWrite" and "read" roles respectively. So I was expecting these both users to be restored.

Then I restored the database into database db_test_2 (not existing):

$ mongorestore -u adm_dump --authenticationDatabase admin -d db_test_2 --restoreDbUsersAndRoles /opt/backup/mongodump_db_test/db_test

The new database db_test_2 is successfully created (all collections are restored) but users are not restored in db_test2.

Below the log tail:

...
2016-06-29T18:28:26.429+0200    restoring users from /opt/backup/mongodump_db_test/db_test/$admin.system.users.bson
2016-06-29T18:28:26.464+0200    roles file '/opt/backup/mongodump_db_test/db_test/$admin.system.roles.bson' is empty; skipping roles restoration
2016-06-29T18:28:26.464+0200    restoring roles from /opt/backup/mongodump_db_test/db_test/$admin.system.roles.bson
2016-06-29T18:28:26.468+0200    done

I also granted the "userAdmin" role to adm_dump and did operations several times with no success. Should I give another specific role to adm_dump user ?

I read the doc and googled on dumpDbUsersAndRoles / restoreDbUsersAndRoles options but found nothing relevant.

What did I miss to restore users from a dump backup ?

MongoDB version 3.2.1 on CentOS 6.6

1
The users are actually stored in the admin database; when you mongorestore the db_test data into a new db_test_2 database, it might be going wrong by recreating the users in the admin database with their privileges on db_test, instead of db_test_2 as you wished. If you log in at the console and execute user admin; then db.system.users.find();, that will help show you what user accounts do exist.Vince Bowdren

1 Answers

0
votes

In case someone else is trying to do this...

  1. Don't specify a db or a collection in mongo dump.
  2. Log in as a user that has admin privileges (maybe adm_dump has those privileges?)
  3. Don't use --dumpDbUsersAndRoles, this only applies when you specify a db. See the docs.

Example:

$ mongodump -u adm_dump --authenticationDatabase admin --dumpDbUsersAndRoles -o /opt/backup/mongodump_db_test