使用innobackupex 备份MYSQL

#!/bin/bash

# by gaolongquan 


LogF="/root/jiankong_log/rc_mysql_slave_backup.log"

mkdir -p /home/rc_mysql_backup_tmp && mkdir -p /home/rc_mysql_backup && rm -rf /home/rc_mysql_backup_tmp/*


# all backup

innobackupex --defaults-file=/etc/my3308.cnf --user=root --password=`cat /opt/sql` --host=127.0.0.1 --port=3308 --slave-info /home/rc_mysql_backup_tmp 2>$LogF

echo "============== total take $SECONDS seconds to backup ! ================"  >> $LogF

# check backup is right?

grep "innobackupex: completed OK\!" $LogF

if [ $? -ne 0 ];then

  echo "$HOSTNAME"|mail -s "mysql backup failed" gaolongquan#aaa.com

fi

rsync -aq /home/rc_mysql_backup_tmp/ /home/rc_mysql_backup/


# clean mysql old bakcup,keep 3 days

find /home/rc_mysql_backup/ -name "`date -d "3 days ago" +%Y-%m-%d`*" |xargs rm -rf


# apply-log , you can rsync to new machine , apply-log hou rongliang hui bian da

File=`ls /home/rc_mysql_backup_tmp/`

innobackupex --apply-log --use-memory=1G /home/rc_mysql_backup/"$File" 2>>$LogF

内存不够的话不要用use-memory这个参数,如果够多加一点,加快apply速度

你可能感兴趣的:(使用innobackupex 备份MYSQL)