Posted On April 2, 2019

MongoDB: Backup and Restore

kimconnect 0 comments
blog.KimConnect.com >> Database >> MongoDB: Backup and Restore
Manual Methods:

Using mongodump and mongorestore

Making a backup using mongodump
- Permissions required: grant find action, backup role
- Outputs BSON file formats
- Connects to mongod or mongos instance (on port 27017 if default)
- Creates ./dump in current directory
- mongodump 2.2+ will not work with older mongod
- Command: mongodump [--host mongodb01.kimconnect.com] [--port 27017] [--collection --myCollection --db kimconnect] [--username kimconnect --password "PASSWORD"] [--oplog (point-in-time snapshot)] [--out /opt/backup/kimconnect-YYYY-MM-DD]

Restoring a backup using mongorestore
- Permissions required:
-- MongoDB 3.2.10 and earlier, requires anyAction on anyResource grants
-- MongoDB 3.2.11 and newer, restore role with --oplogReplay
- By default, ./dump is in the environmental paths
- Command: mongorestore [--host mongodb01.kimconnect.com] [--port 27017] [--username kimconnect --password 'PASSWORD'] [/opt/backup/kimconnect-YYYY-MM-DD/] [--oplogReplay (restore snapshot)] [--objcheck (checks integrity prior to commit)]

Using mongoexport & mongoimport

Using mongoexport
- Permissions required: read role
- Commands:
-- mongoexport [--db contacts --collection crm --out /opt/backups/contacts.json] [--username kimconnect --password 'PASSWORD'] [--host mongodb01.kimconnect.com --port 27017]

Using mongoimport
- Permissions required: readWrite role
- Commands:
-- mongoimport [--file /opt/backups/contacts.json] [--db contacts --collection crm] [--username kimconnect --password 'PASSWORD'] [--host mongodb01.kimconnect.com --port 27017]

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

SQL: Exists Condition

The EXISTS condition is considered "to be met" if the subquery returns at least one…

Microsoft SQL Database Stuck in Restoring Mode

These are the possible resolutions from highest to lowest recommendations -- Normal method of restoring…

DB2 AS400 to Microsoft SQL Conversion

SQL Ways Wizard: Enter ODBC data source, username, and password >> press Next Set Target…
Other project: DragonCoin.com