Last Updated: February 25, 2016
· icflorescu

Backup a cloud MongoDB database on your computer

If you're deploying your apps on Heroku, AppFog or other PaaS provider, you're probably keeping your MongoDB data on MongoLab or MongoHQ.

Backup a MongoLab database on your computer

Here's a short shell script to do a local, compressed and timestamped backup of a MongoLab database:


echo "\n\n\nDownloading database...\n\n\n"
mongodump -h \
          -d database_name \
          -u user_name \
          -p secret_password \
          -o ./backup/mongolab

echo "\n\n\nArchiving temporary backup folder...\n\n\n"
zip -r ./backup/mongolab-$(date +"%Y%m%d-%H%M%S").zip ./backup/mongolab

echo "\n\n\nDeleting temporary backup folder..."
rm -R ./backup/mongolab

echo "\nDone."