Last active
March 8, 2016 17:54
-
-
Save hamxiaoz/0a7e2d8ad9e809c9d5f9 to your computer and use it in GitHub Desktop.
Use git to backup MongoDB for Meteor
This file contains hidden or 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
# run every day at 12am | |
00 00 * * * /home/x/run_backup.sh |
This file contains hidden or 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 | |
MONGO_DATABASE="X" | |
APP_NAME="X" | |
MONGO_HOST="127.0.0.1" | |
MONGO_PORT="27017" | |
TIMESTAMP=`date +%F-%H%M` | |
MONGODUMP_PATH="/usr/bin/mongodump" | |
BACKUPS_DIR="/home/X/backups/$APP_NAME" | |
BACKUP_NAME="$APP_NAME-$TIMESTAMP" | |
GIT_PATH="/usr/bin/git" | |
# mongo admin --eval "printjson(db.fsyncLock())" | |
# $MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE | |
$MONGODUMP_PATH -d $MONGO_DATABASE | |
# mongo admin --eval "printjson(db.fsyncUnlock())" | |
# dump the database and zip it (remove the dump folder afterwards) | |
mkdir -p $BACKUPS_DIR | |
mv dump $BACKUP_NAME | |
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME | |
rm -rf $BACKUP_NAME | |
# commit the new backup | |
cd $BACKUPS_DIR | |
$GIT_PATH add . | |
$GIT_PATH commit -m "backup from `date +'%Y-%m-%d'`" | |
$GIT_PATH push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment