Backing up and restoring a MongoDB database
This recipe teaches you how to back up a MongoDB database using the mongodump
utility and restore it using mongorestore
.
Getting ready
This recipe requires a running MongoDB server and access to a user account with membership in the userAdmin
role.
How to do it...
Follow these steps to back up a MongoDB database:
- Connect to MongoDB as a user with membership in the
userAdmin
role:mongo --username admin --password "" admin
- Create an account with membership in the
backup
andrestore
roles to be used for creating and restoring backups:db.createUser({ user: "backupusr", pwd: "B@CK&4th", roles: [ { role: "backup", db: "admin" }, { role: "restore", db: "admin" } ] })
- Use
mongodump
on the command-line to ...
Get CentOS 7 Server Deployment Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.