安装percona-xtrabackup
http://990487026.blog.51cto.com/10133282/1759237
root@uat:/backup# cat xtrabackup.sh
#!/bin/bash
backdir=/backup/mysql
web_page_backdir=/backup/
user=r**t
pass=a**********t
logfile=innobackupex.log
#备份网页文件
mytime=`date +"%F_%H-%M-%S"`
cd /var/www/
tar -zcf ${mytime}_html.tar.gz html/
mv ${mytime}_html.tar.gz $web_page_backdir
week=`date +%u`
mkdir $backdir >> /dev/null 2>&1
if [ ! -f /globalback ]
then
cat /dev/null > $logfile
innobackupex --user=$user --password=$pass $backdir
stat=`echo $?`
ls $backdir | tail -n 1 > /globalback
basedir=`cat /globalback`
last=`ls $backdir | tail -n 1`
date "+%F %H:%M" >> $logfile
if [ $stat -ne 0 ]
then
echo "备份失败!" >> $logfile
exit
fi
echo " 检测到之前没有做过全局备份,完全备份一次!" >> $logfile
basedir=`cat /globalback`
echo "基 本库是 $backdir/$basedir " >> $logfile
exit
fi
if [ $week -eq 7 ]
then
innobackupex --user=$user --password=$pass $backdir
stat=`echo $?`
incre=`ls $backdir | tail -n 1`
if [ $stat -ne 0 ]
then
date "+%F %H:%M" >> $logfile
echo "备份失败!" >> $logfile
exit
fi
ls $backdir | tail -n 1 > /globalback
basedir=`cat /globalback`
echo "↓↓↓↓↓↓↓↓↓↓↓ 每周全局备份分割线 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓" >> $logfile
date "+%F %H:%M" >> $logfile
echo "全局备份" >> $logfile
echo "数据备份的位置 $backdir/$basedir " >> $logfile
basedir=`cat /globalback`
echo "基 本库是 $backdir/$basedir " >> $logfile
else
basedir=`cat /globalback`
last=`ls $backdir | tail -n 1`
innobackupex --user=$user --password=$pass --incremental $backdir --incremental-basedir=$backdir/$last
stat=`echo $?`
incre=`ls $backdir | tail -n 1`
echo "" >> $logfile
date "+%F %H:%M" >> $logfile
if [ $stat -ne 0 ]
then
echo "备份失败!" >> $logfile
exit
fi
echo "增量备份 " >> $logfile
echo "基 本库是 $backdir/$basedir " >> $logfile
echo "本次备份是 $backdir/$incre " >> $logfile
echo "MySQL二进制日志文件路径" >> $logfile
grep "^log.bin" /etc/mysql/my.cnf >> $logfile
fi