Created
November 17, 2011 10:24
-
-
Save yalab/1372860 to your computer and use it in GitHub Desktop.
Backup scripts MongoHQ databases using heroku.
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 | |
HEROKU="/home/yalab/.rvm/gems/ruby-1.9.3-p0/bin/heroku" | |
BACKUP_DIR="$HOME/.backup/mongohq" | |
if [ ! -d $BACKUP_DIR ];then | |
mkdir -p $BACKUP_DIR | |
fi | |
for APP in `$HEROKU list`;do | |
MONGOHQ_URL=`heroku config --app $APP | grep MONGOHQ_URL | awk '{print $3}'` | |
if [ -z "$MONGOHQ_URL" ];then | |
continue | |
fi | |
URI=(`ruby -ruri -e "uri = URI.parse('$MONGOHQ_URL'); puts(uri.user, uri.password, uri.host, uri.port, uri.path.delete('/'))"`) | |
USER=${URI[0]} | |
PASS=${URI[1]} | |
HOST=${URI[2]} | |
PORT=${URI[3]} | |
NAME=${URI[4]} | |
mongodump -h ${HOST}:${PORT} -d ${NAME} -u ${USER} -p ${PASS} -o $BACKUP_DIR | |
tar -C $BACKUP_DIR -jcvf ${BACKUP_DIR}/${APP}_`date +%Y%m%d%H%M%S`.tar.bz2 $NAME | |
rm -rf ${BACKUP_DIR}/${NAME} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment