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

MySQL: update with Join Tables

Let's say for example you have a product table which stores information about products and…

Microsoft SQL Server Storage Capacity Planning

This would be a recommended mounted volumes for most environment: 80GB RAID10 C:\ Operating System…

How to Migrate a Database to a Newer Version of Microsoft SQL Server

Get Version of new SQL server Create a sql-dump script on the old SQL server:…