#!/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 "Enter the time of the data that needs to be recovered: (Number of hours to back up):" Times; Echo $time
Recovery_databases ()
{
#库删除或重建
MYSQL-U$DBUSER-P$DBPASSWD-E "DROP database if exists xmxyshxy${zoneid}"
echo "Bulk Delete xmxyshxy${zoneid} complete"
MYSQL-U$DBUSER-P$DBPASSWD-E "CREATE database if not exists xmxyshxy${zoneid}"
echo "Bulk Create Xmxyshxy${zoneid} complete"
#数据还原
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
done< $serverlist
MySQL Restore all libraries