MySQL Restore all libraries

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.