#!/bin/bash

MYSQL_HOST="192.168.251.155"
MYSQL_PORT="30001"
MYSQL_USER="root"
MYSQL_PASSWORD="1qaz2WSX"
BACKUP_FILE=

DATABASES=$(echo "show databases"| /usr/bin/mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h ${MYSQL_HOST} -P ${MYSQL_PORT} 2> /dev/nurl |egrep -v '(Database|schema|mysql)')

if [ $? != 0 ];then
    echo "$(date '+%Y-%m-%d %H:%M:%S') mysql server can't connect." 
    exit 1
fi

/usr/bin/mysql  --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT}  < ${BACKUP_FILE}

if [ "$?" == 0 ];then
    echo "$(date '+%Y-%m-%d %H:%M:%S') mysql restore success." 
else
    echo "$(date '+%Y-%m-%d %H:%M:%S') mysql restore faile." 
fi


