码迷,mamicode.com
首页 > 数据库 > 详细

mysql还原所有库

时间:2018-03-13 11:04:02      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:mysql   recovery   

#!/bin/bash
#scripts sh batch_databasename.sh

bakfile=/data/dbbackup
logfile=/data/bak.log

dbuser=xxx
dbpasswd=xxx
ip=ifconfig | grep "inet addr"| grep Bcast| awk ‘{print $2}‘| awk -F":" ‘{print $2}‘

NowTime=$(date +%Y%m%d)

#ser_port=cat /usr/jyinit/serverlist | awk ‘{print $3}‘ | tr "\n" " "

serverlist=/usr/jyinit/serverlist

#time=13

read -p "请输入需要恢复的数据的时间:(备份的小时数):" time ;echo $time

recovery_databases()
{

#库删除或重建
mysql -u$dbuser -p$dbpasswd -e "drop database if exists xmxyshxy${zoneid}"
echo "批量删除xmxyshxy${zoneid} 完成"
mysql -u$dbuser -p$dbpasswd -e "create database if not exists xmxyshxy${zoneid}"
echo "批量创建xmxyshxy${zoneid} 完成"

#数据还原
cd $bakfile
#解压备份文件
gzip -cdv ${NowTime}xmxy${pf}${zoneid}${time}.FullyBak.tar.gz > ${NowTime}xmxy${pf}${zoneid}${time}.FullyBak.sql
if (test -e ${NowTime}xmxy${pf}${zoneid}${time}.FullyBak.sql)
then
#解压的sql导入到库
mysql -u$dbuser -p$dbpasswd xmxy${pf}${zoneid} < ${NowTime}xmxy${pf}${zoneid}${time}.FullyBak.sql
echo xmxy${pf}${zoneid} backup success >> $logfile
else
echo xmxy${pf}${zoneid} backup fail >>$logfile
exit 1
fi
}

while read noteline
do
if [ -z "echo $noteline | grep -v ^$" ]; then
continue
fi

commentflag=${noteline:0:1}
if [ "${commentflag}"x == "#"x ]; then
            continue
fi

pf=`echo $noteline | awk ‘{print $1}‘`
zoneid=`printf "$noteline" | awk ‘{print $2}‘ ` 
echo $zoneid
echo $pf

recovery_databases 

done<$serverlist

mysql还原所有库

标签:mysql   recovery   

原文地址:http://blog.51cto.com/yzg784534398/2085893

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!