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 Language (Condensed)

SELECT [DISTINCT | MIN | MAX] column1 [AS alias]FROM table_nameWHERE condition [IS NULL|IS NOT NULL]…

T-SQL Msg 3101 Exclusive access could not be obtained because the database is in use

Symptom: Msg 3101, Level 16, State 1, Line 2Exclusive access could not be obtained because…

PowerShell: Obtaining SQL Database Default Paths

# This function returns an array of 3 string values reflecting default Data, Log, and…