Skip to content

Instantly share code, notes, and snippets.

@icleversoft
Last active August 29, 2015 14:04
Show Gist options
  • Save icleversoft/68abf5905cad5a5ec247 to your computer and use it in GitHub Desktop.
Save icleversoft/68abf5905cad5a5ec247 to your computer and use it in GitHub Desktop.
Script for daily backup of a mongodb database
1. Set appropriate permissions to the file
$ chmod 755 mongobackup
Then add the following entry to your crontab list
-------------------------------
@daily /home/user/mongobackup
-------------------------------
@daily means everyday at midnight
#!/bin/bash
DUMPPATH=/home/user/dumps
MONGODBNAME=my_db
DAY=`/bin/date +%Y%m%d`
mongodump -d $MONGODBNAME -o $DUMPPATH/mongo_$DAY
cd $DUMPPATH/mongo_$DAY
tar -cvzf "$DUMPPATH/mongo_$DAY.tar" $MONGODBNAME
cd $DUMPPATH
rm -rf $DUMPPATH/mongo_$DAY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment