本文共 1427 字,大约阅读时间需要 4 分钟。
#!/bin/bash
#scripts sh batch_databasename.shbakfile=/data/dbbackup
logfile=/data/bak.logdbuser=xxx
dbpasswd=xxxip=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.sqlif (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.sqlecho xmxy${pf}${zoneid} backup success >> $logfileelseecho xmxy${pf}${zoneid} backup fail >>$logfileexit 1fi}while read noteline
doif [ -z "echo $noteline | grep -v ^$
" ]; thencontinuefi commentflag=${noteline:0:1}if [ "${commentflag}"x == "#"x ]; then continuefipf=`echo $noteline | awk '{print $1}'`zoneid=`printf "$noteline" | awk '{print $2}' ` echo $zoneidecho $pfrecovery_databases
done<$serverlist
转载于:https://blog.51cto.com/yzg784534398/2085893