Skip to content

Instantly share code, notes, and snippets.

@robbyrussell
Created February 14, 2012 22:42
Show Gist options
  • Save robbyrussell/1831231 to your computer and use it in GitHub Desktop.
Save robbyrussell/1831231 to your computer and use it in GitHub Desktop.
#!/bin/sh
# config options
CURRENT_DATE=`date +%Y%m%d`;
BACKUP_DIRECTORY="/Users/robbyrussell/Backups/Databases/Contiki"
DATABASE_NAME="contiki_live_$CURRENT_DATE"
echo $DATABASE_NAME;
DATABASE_USER="root"
MYSQL_PATH="mysql"
MYSQL_IMPORT_PATH="mysqlimport"
REMOTE_SERVER="db-backup-sfo.contiki.com"
REMOTE_PATH="/tmp/latest.sql.bz2"
function shout { echo $1; }
#
# # fetch from backup serve
scp robbyrussell@$REMOTE_SERVER:$REMOTE_PATH $BACKUP_DIRECTORY/contiki-$CURRENT_DATE.sql.bz2
# scp robbyrussell@$REMOTE_SERVER:/tmp/db_dumps/2010032500_db-backup-sfo.sql.bz2 $BACKUP_DIRECTORY/contiki-$CURRENT_DATE.sql.bz2
#
# # drop/create development db
shout "Weeeeeeeeeeeee.. just finished fetching the latest database backup from Contiki."
echo "DROP DATABASE $DATABASE_NAME" | $MYSQL_PATH -u $DATABASE_USER
echo "CREATE DATABASE $DATABASE_NAME CHARACTER SET utf8 COLLATE utf8_general_ci;" | $MYSQL_PATH -u $DATABASE_USER
shout "Just dropped the old local database. New one has been created."
#
# unarchive
shout "... decompressing backup file "
bunzip2 -k $BACKUP_DIRECTORY/contiki-$CURRENT_DATE.sql.bz2
shout "... done. "
# import db backup
shout "Getting ready to start importing the database backup."
$MYSQL_PATH --user=$DATABASE_USER $DATABASE_NAME < $BACKUP_DIRECTORY/contiki-$CURRENT_DATE.sql;
shout "Awesome... the Contiki database has been imported. Let's kick some muthafucking ass\!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment