Last active
August 29, 2015 14:04
-
-
Save icleversoft/68abf5905cad5a5ec247 to your computer and use it in GitHub Desktop.
Script for daily backup of a mongodb database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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