Script for daily backup of a mongodb database
#!/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
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