#!/bin/bash #connect to app01 #ssh app01.flipkey.net #TODAY=`date +%Y-%m-%d` TODAY='2009-11-09' #this user should have public key access to app01 or you will be prompted for a password for each download SCPUSER='brent' #change this list if you don't want all dbs DBS="pm_scraping" #if you wanted to use this to a remote server, change the MYSQLHOST, but you need to ensure that the MYSQLUSER has access MYSQLHOST='localhost' MYSQLUSER='flipkey' MYSQLPASS='fl1p3gg5' #none below here this should have to change BACKUPLOCATION="/home/flipkey/proddata" BACKUPSERVER='backup.flipkey.net' #if your programs are in odd areas and can't be found, set their full path here #if you're using windows, this will only work via cygwin SCP=`which scp` GUNZIP=`which gunzip` GZIP=`which gzip` MYSQL=`which mysql` AWK=`which awk` SED=`which sed` ECHO=`which echo` TODAYSZIPS='' for db in $DBS; do TODAYSZIPS="${TODAYSZIPS} ${TODAY}-${db}-backup.dump.gz" done for zip in ${TODAYSZIPS}; do ${ECHO} "Fetching ${zip}" ${SCP} ${SCPUSER}@${BACKUPSERVER}:${BACKUPLOCATION}/${zip} . if [ -f $zip ]; then ${ECHO} "Downloaded ${zip}, extracting" ${GUNZIP} ${zip} db=`${ECHO} ${zip} | ${AWK} -F- ' { print $4 } '` nonzip=`${ECHO} ${zip} | ${SED} -e s/.gz//` ${ECHO} "Loading ${nonzip} to ${MYSQLHOST} " $MYSQL -u ${MYSQLUSER} -p${MYSQLPASS} -h ${MYSQLHOST} ${db} < ${nonzip} ${ECHO} "Zipping ${nonzip}" ${GZIP} ${nonzip} else ${ECHO} "Can't find file ${zip}, skipping..." fi done exit 0