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.
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.
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,
1) Backup all databases on the Mongo Instance
This command will be backup all the databases available on the mongo instance. The backup files will be created under \bin\dump folder
2) Specific Database
mongodump –db speakplay_analytics –out c:/Backup/dump/speakplay_analytics
|–db||Path of the database for which you want to create a backup|
|–out||Destination path of the backup|
mongodump.exe –db sc8prod_analytics –authenticationDatabase admin –username xxxx –password xxxx –out F:\MongoBackup\sc8prod_analytics
In case if authentication is enabled extra parameters needs to be passed on to mongodump command,
|–authenticationDatabase||DB in which the user is defined, mostly it would be “admin” database|
mongodump –db speakplay_analytics –collection Interactions
If you want to restore specific collection (table) from a mongo db use –collection parameter to do so.
1) Restore a database
mongorestore –db speakplay_analytics dump/speakplay_analytics/Interactions.bson
2) Restore a collection
mongorestore –collection Interactions –db speakplay_analytics dump/speakplay_analytics/Interactions.bson
This now makes me Joy from Inside Out as I now know Mongo basics.