Skip to content

Instantly share code, notes, and snippets.

@jhyland87
Created March 2, 2018 15:45
Show Gist options
  • Save jhyland87/9db7ca5fb3495a99aa6ec91a6dfcb15f to your computer and use it in GitHub Desktop.
Save jhyland87/9db7ca5fb3495a99aa6ec91a6dfcb15f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Load nightly mysqldump
# aaa B / bbb G / ccc B
# 10/17/2014
BACKUP_DIR=/mnt/CHD_DB_BACKUP
DATE=`date +%Y.%m.%d-%H.%M.%S`
BACKUP_FILE=`ls -1r $BACKUP_DIR/*.* | head -1`
if [ ! -z $BACKUP_FILE ]
then
BZIP_CHECK=`echo $BACKUP_FILE | grep -c bz2`
if [ "$BZIP_CHECK" = "0" ]
then
echo "------ Starting Restore at $DATE! ------"
echo "Restoring database from '$BACKUP_FILE'..."
# Clean out the sullied debris
for i in `mysql -s -e 'show databases' | egrep -v '(mysql|information_schema|Database)'`; do
mysql -e "drop database $i"
done
# turn off bin logging (if it happens to be on)
mysql -e "SET SQL_LOG_BIN=0;"
mysql -e "SET GLOBAL slow_query_log=0"
mysql < $BACKUP_FILE
if [[ "$?" -ne "0" ]]
then
echo "LS DB Refresh to Stage Failed." | mail -s "LibSweet Stage DB Refresh Oops" [email protected]
fi
END_DATE=`date +%Y.%m.%d-%H.%M.%S`
echo "------ Completed Restore at $END_DATE! ------"
echo "------ All done now ------"
else
echo "Error: Backup file, $BACKUP_FILE, is compressed! - $DATE"
fi
else
echo "Error: Backup file not found! - $DATE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment