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

PowerShell: Automating Microsoft Failover Cluster Maintenance – FileServer, SQL AlwaysOn, Hyper-V Guest VMs, Disks Operations

##################################################################################################### # MsClusterMaintenance_v0.0.2.ps1 # Author: KimConnect.com # License: GPLv3 # Description: this program automates the…

PowerShell: Backup, Archive, and Remove a Microsoft SQL Database

$sqlServer='sqlsherver007' $databaseName="someDatabaseName" $saCredential=get-credential $backupDestination="\\Archive03\MSSQL_Backups" function triggerSqlBackup($sqlServer,$databaseName){ # Ensure the the Jump Box has SQL PowerShell…

PowerShell: Optimize SQL Server Memory & CPU Resources

# optimizeSqlServer.ps1 # Version 0.0.2 # This version deals with Memory, CPU # Future versions…