#!/bin/bash
#主机地址
host="localhost"
#mysql用户名
id="root"
#mysql秘密
pwd="sanyue"
dbs=$(echo "show databases;" | mysql -u$id -p$pwd -h$host)
#不需要还原的数据库
nodeldb="Database information_schema performance_schema test mysql"
#存放还原文件的位置
backupdata-path="/root/mysqlbackup"
#要还原的压缩包
filename="mysql_2013-11-24.tar.gz"
#解压后的sql文件存放的目录
inputpath=$backuppath"/input"
echo "+==================+"
#file isn't There
if [ ! -f $backuppath/$filename ]
then
exit 0
fi
echo $backuppath/$filename
#Catalog isn't there
if [ ! -d $inputpath ]
then
mkdir -p
fi
#Decompression tar file
echo "+=======Decompression start ===========+"
tar zxf $backuppath/$filename -C $inputpath
echo "+=======Decompression end ===========+"
echo "+=======input start ===========+"
for db in $dbs;
do
isbool="0"
for nodb in $nodeldb;
do
if [ "$db" == "$nodb" ]
then
isbool="1"
fi
done
if [ ! -f $inputpath/$db.sql ]
then
continue
fi
if [ "$isbool" == "1" ]
then
continue
fi
mysql -u$id -p$pwd -h$host $db
echo $db"-- input success"
if [ "$?" == "0" ]
then
echo $(date +%Y-%m-%d)" $db input sucess">>mysqlInput.log
else
echo $(date +%Y-%m-%d)" $db input failed">>mysqlInput.log
fi
done
echo "+=======input end ===========+"
#rm -rf $inputpath/*.*