#!/bin/bash
# Name:MYSQL全备份 # mysql qk scripts#定义数据库用户名及密码
user=root userPWD=123456 #定义数据库 database1=a database2=b database3=c database4=d #定义全备份位置 dbDir=/data/mysqlbk/#定义变量DATE格式为20150127
DATE=`date +%Y%m%d`/usr/local/mysql/bin/mysqldump -u$user -p$userPWD --quick $database1 > $dbDir$database1$DATE.sql
/usr/local/mysql/bin/mysqldump -u$user -p$userPWD --quick $database2 > $dbDir$database2$DATE.sql /usr/local/mysql/bin/mysqldump -u$user -p$userPWD --quick $database3 > $dbDir$database3$DATE.sql /usr/local/mysql/bin/mysqldump -u$user -p$userPWD --quick $database4 > $dbDir$database4$DATE.sql#查找mysql-index索引里的bin 2进制文件,并将倒二的日志文件赋值给filename
filename=`tac /data/database/mysql-bin.index |sed -n 2p | awk -F "/" '{print $2}'`#rsync同步mysql-bin.00000X文件到备份服务器上
rsync -avH --port=873 --progress /data/database/$filename mslog@192.168.0.X::mslog --password-file=/home/mysql/mslog.passwd#rsync同步全备数据库
rsync -avH --port=873 --progress $dbDir msqb@192.168.0.X::msqb --password-file=/home/mysql/msqb.passwd