mysql完全备份脚本

#!/bin/bash
#set -x
dbname=test  #数据库名
backupdir=/backup/mysqlbackup  #备份目录
date=`date +%y-%m-%d-%H-%M-%S`
bakupfile=${dbname}_$date.tar.gz
PW=123456 #密码
cd /usr/local/mysql/var
/usr/local/mysql/bin/mysqlhotcopy -u root -p $PW $dbname ${backupdir}/ > /dev/null   #运用mysqlhotcopy工具复制数据库文件到备份目录
if [ $? -eq 0 ];then
cd $backupdir
tar zcf $bakupfile  $dbname
if [ $? -eq 0 ];then
rm -rf ${backupdir}/$dbname
if [ $? -eq 0 ];then
rsync -uqzrt --password-file=/etc/swd/dbserver1.pass  ${backupdir}/$bakupfile  [email protected]::DBserver  #运用rsync同步到远程机器上
if [ $? -eq 0 ];then
rm -rf ${backupdir}$bakupfile
echo "$date rsync to $dbname is sucess" >> /var/log/mysqlbackup.log
else
echo "$date rsync to $dbname is error" >> /var/log/mysqlbackup.log
fi
fi
fi
fi

你可能感兴趣的:(数据库,mysql,职场,休闲)