Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

MongoDB shell export entire database

MongoDB shell export entire database

Problem

In MongoDB I'm attempting to set up an automated backup of all of the databases that Mongo is holding, my current script base is something along the lines of

mongodump -u username -p password -o backup/(date)

Where i have (date) I'm looking to have it be dumped into a folder with the date of the backup e.g. 2013-02-06

I'm wanting this to happen either through a chron job or a .sh script.

Problem courtesy of: PhazingAzrael

Solution

If this is a *nix shell script you could write:

mongodump -u _username_ -p _password_ -o backup/$(date +%Y-%m-%d) 

or alternately:

#!/bin/bash
DT=$(/bin/date +%Y-%m-%d)
mongodump -u _username_ -p _password_ -o backup/$DT

this will create a directory YYYY-MM-DD under backup. You'd then likely want to tar the directory up using something like:

tar -czf mongod-backup-$DT.tar backup/$DT
Solution courtesy of: epc

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

MongoDB shell export entire database

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×