一个mysql备份脚本

checkname=mysqlbak
now=`date +"%Y%m%d"`
StatFile="./slave_status.$now"
SERVERTIME=$DAY%20$TIME
dbuser=mysqlbak
dbpwd=t119000
SERVERNAME=
HOSTNAME=`hostname`
IPADDR=`awk -F '=' '/IPADDR/ {print $2}' /etc/sysconfig/network-scripts/ifcfg-eth0`
tip=10.0.0.19
echo $IPADDR
bakpath=/bak/mysql/$IPADDR.$now
tarpath=/bak/mysql
mysqldumppath=/data/app/mysql/bin
mountpath=/site/mysqlbak/mysql_bak/
mkdir -p $bakpath
echo "show databases;" | /data/app/mysql/bin/mysql -u$dbuser -p$dbpwd > $StatFile
linesum=$(wc -l $StatFile)
linesum1=$linesum-1
echo $linesum
linecount=`echo $linesum | awk '{print $1}' `
echo $linecount
for ((i=2;i<=$linecount;i++));do
dbname=`sed -n ''$i' p' $StatFile`
echo $dbname
$mysqldumppath/mysqldump -u$dbuser -p$dbpwd  $dbname > $bakpath/$dbname.sql
done
tar czvf  $tarpath/$IPADDR.$now.tar.gz  $bakpath
ssize=`du -sh $tarpath/$IPADDR.$now.tar.gz`
ssize1=`echo $ssize | awk '{print $1}'`
ssizemd5=`md5sum $tarpath/$IPADDR.$now.tar.gz | awk '{print $1}'`   验证备份文件MD5
echo $ssizemd5
mount -t cifs -o usernamed=bak,password=bob1206 //10.0.0.19/mysql $mountpath
cp $tarpath/$IPADDR.$now.tar.gz $mountpath
echo $state
tsize=`du -sh  $mountpath/$IPADDR.$now.tar.gz`
tsize1=`echo $tsize | awk '{print $1}'`
tsizemd5=`md5sum $mountpath/$IPADDR.$now.tar.gz | awk '{print $1}'` 验证传到备份服务器上的MD5
if [ $ssizemd5 = $tsizemd5 ] ; then
state=0
note=$IPADDR.$checkname"sucess_bak_db_Amount"$linesum1
else
statr=1
note=transmission unsuccess
fi
echo $tsizemd5
echo $checkname
echo $IPADDR
echo $ssize1.ssize1
echo $tsize1
echo
umount $mountpath
rm -rf $tarpath/$IPADDR.$now.tar.gz
rm -rf $tarpath/$IPADDR.$now

你可能感兴趣的:(sql,mysql,F#,脚本)