码迷,mamicode.com
首页 > 数据库 > 详细

使用innobackupex 备份MYSQL

时间:2015-08-26 14:06:17      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

#!/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

标签:

原文地址:http://my.oschina.net/longquan/blog/497257

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!