mysql还原linux_shell脚本实现mysql自动还原(linux)

#!/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/*.*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值