Mongo Backup and Restore

While working on Sitecore at times one can come across a simple task for backing up and restoring mongo databases. Did that made you think? Why me? It should have been done by a DBA. Let’s ignore Mr. Anger from your Inside Out and learn how to do that.


Mad at Mongo


To me the task seemed simple and my initial thoughts were let’s get connected to RoboMongo or Mongo Management Studio, visit any one menu or right click on any one of the mongo database and I will find an option to backup my databases. Well reality is always bitter and I did not have those easy options. At this point of time I was Sad from Inside Out.

Do not know Mongo Backup & Restore

I learned some commands from “Back Up and Restore with MongoDB Tools” and would like to share.

Run the command prompt as administrator and navigate to Mongo/Bin folder in my case the path was C:\Databases\Mongo26\bin. From the command prompt issue below commands,

Backup

1) Backup all databases on the Mongo Instance

[code language=”SQL”]
mongodump
[/code]

mongodump

This command will be backup all the databases available on the mongo instance. The backup files will be created under \bin\dump folder

Explorer

2) Specific Database

[code language=”SQL”]
mongodump –db speakplay_analytics –out c:/Backup/dump/speakplay_analytics
[/code]

Parameter Description
–db Path of the database for which you want to create a backup
–out Destination path of the backup



Mongo specific database


3) Specific Database behind authentication

[code language=”SQL”]
mongodump.exe –db sc8prod_analytics –authenticationDatabase admin –username xxxx –password xxxx –out F:\MongoBackup\sc8prod_analytics
[/code]

In case if authentication is enabled extra parameters needs to be passed on to mongodump command,

Parameter Description
–authenticationDatabase DB in which the user is defined, mostly it would be “admin” database
–username Self explanatory
–password Self explanatory



Authentication

4) Specific Collection

[code language=”SQL”]
mongodump  –db speakplay_analytics –collection Interactions
[/code]

If you want to restore specific collection (table) from a mongo db use –collection parameter to do so.

Restore

1) Restore a database

[code language=”SQL”]
mongorestore –db speakplay_analytics dump/speakplay_analytics/Interactions.bson
[/code]

2) Restore a collection

[code language=”SQL”]
mongorestore –collection Interactions –db speakplay_analytics dump/speakplay_analytics/Interactions.bson
[/code]

This now makes me Joy from Inside Out as I now know Mongo basics.

Happy now

Leave a Reply

Powered by WordPress.com.

Up ↑

%d bloggers like this: