部署xtrabckup备份_附带shell增量脚本

需要的安装包:
percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm
注意,该安装包不适合rhel4或CentOS4的操作系统,安装升级perl系统lib库会引起OS崩溃

操作系统环境介绍:
[root@im-web local]# lsb_release -a
LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: CentOS
Description:    CentOS release 5.2 (Final)
Release:        5.2
Codename:       Final

[root@sf1 ~]# mv percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm  /usr/local/
[root@sf1 ~]# cd /usr/local/

安装
[root@sf1 local]# rpm -ivh percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm 
warning: percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID cd2efd2a
Preparing...                ########################################### [100%]
   1:percona-xtrabackup     ########################################### [100%]
[root@sf1 local]# inno
innobackupex        innobackupex-1.5.1  innochecksum        
表示安装正确

#cd /database/studyfun
# mkdir backup 
创建脚本
#touch xtrabackup.sh  
需要根据数据库具体配置修改如下
backdir=/database/xmobile/backup
redun=/database/xmobile/redundency
file_cnf=/etc/my_xmobile.cnf
user_name=backupuser
password="123456"
socket="/tmp/mysql_xmobile.sock"

if [ ! -d "/database/xmobile/redundency" ];
 then
mkdir -p /database/xmobile/redundency
fi

[root@sf1 studyfun]#  ll
total 20
drwxr-xr-x 2 root  root  4096 Oct  8 16:44 backup
drwxr-xr-x 2 mysql mysql 4096 Oct  8 15:53 binlog
drwxr-xr-x 5 mysql mysql 4096 Oct  8 15:53 data
drwxr-xr-x 2 mysql mysql 4096 Oct  8 15:53 relaylog
-rwxr-xr-x 1 root  root  3528 Oct  8 16:45 xtrabackup.sh
给脚本赋执行权限
# chmod +x xtrabackup.sh 

创建备份用户
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'backupuser'@'localhost' identified by '123456';
FLUSH PRIVILEGES;

加入crontab定时任务
# crontab -l
10 02 * * * /database/studyfun/xtrabackup.sh

xtrbackup.sh脚本

[root@sf1 data]# cat /database/studyfun/xtrabackup.sh
#!/bin/bash
BEGINTIME=`date +"%Y-%m-%d %H:%M:%S"`
format_time=`date +"%Y-%m-%d_%H:%M:%S"`
week=`date +%Y-%m-%d`
backupbin=/usr/bin
backdir=/database/studyfun/backup
redun=/database/studyfun/backup/redundency
file_cnf=/etc/my_studyfun.cnf
user_name=backupuser
password="123456"
socket="/tmp/mysql_studyfun.sock"
out_log=$backdir/xtrabackup_log_$format_time
time_cost=$backdir/xtrabackup_time.txt


if [ ! -d "/database/studyfun/backup/redundency" ];
 then 
mkdir -p /database/studyfun/backup/redundency
fi


if [ -d "$backdir/incr5" ];then
tar -czvf ${redun}\/redundency_${week}.gz $backdir >/dev/null 2>&1
        rm -rf $backdir
        mkdir $backdir
# del backup
DEL_UNTIL_DATE=`date --date='14 day ago' +%Y-%m-%d`


/bin/rm -f /${redun}/*${DEL_UNTIL_DATE}.gz >/dev/null 2>&1
fi 
#full
if [ ! -d "$backdir/full" ];then
        echo "#####start full backup at $BEGINTIME to directory full" >>$time_cost
        $backupbin/innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info  $backdir/full 1> $out_log 2>&1
        break;
elif [ ! -d "$backdir/incr0" ];then
        echo "#####start 0 incremental backup at $BEGINTIME to directory incr0" >>$time_cost
        $backupbin/innobackupex --defaults-file=$file_cnf  --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info  --incremental --incremental-basedir=$backdir/full $backdir/incr0 1> $out_log 2>&1
        break;
elif [ ! -d "$backdir/incr1" ];then
        echo "#####start 1 incremental backup at $BEGINTIME to directory incr1" >>$time_cost
        $backupbin/innobackupex --defaults-file=$file_cnf  --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info  --incremental --incremental-basedir=$backdir/incr0 $backdir/incr1 1> $out_log 2>&1
        break;
elif [ ! -d "$backdir/incr2" ];then
        echo "#####start 2 incremental backup at $BEGINTIME to directory incr2" >>$time_cost
        $backupbin/innobackupex --defaults-file=$file_cnf  --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info  --incremental --incremental-basedir=$backdir/incr1 $backdir/incr2 1> $out_log 2>&1
        break;
elif [ ! -d "$backdir/incr3" ];then
        echo "#####start 3 incremental backup at $BEGINTIME to directory incr3" >>$time_cost
        $backupbin/innobackupex --defaults-file=$file_cnf  --no-timestamp --user=$user_name --password=$password --socket=$socket --
slave-info  --incremental --incremental-basedir$backdir/incr2 $backdir/incr3 1> $out_log 2>&1
        break;
elif [ ! -d "$backdir/incr4" ];then
        echo "#####start 4 incremental backup at $BEGINTIME to directory incr4" >>$time_cost
        $backupbin/innobackupex --defaults-file=$file_cnf  --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info  --incremental --incremental-basedir=$backdir/incr3 $backdir/incr4 1> $out_log 2>&1
        break;
elif [ ! -d "$backdir/incr5" ];then
        echo "#####start 5 incremental backup at $BEGINTIME to directory incr5" >>$time_cost
        $backupbin/innobackupex --defaults-file=$file_cnf  --no-timestamp --user=$user_name --password=$password --socket=$socket --slave-info  --incremental --incremental-basedir=$backdir/incr4 $backdir/incr5 1> $out_log 2>&1
        break;
 fi
 ENDTIME=`date +"%Y-%m-%d %H:%M:%S"`
 begin_data=`date -d "$BEGINTIME" +%s`
 end_data=`date -d "$ENDTIME" +%s`
 spendtime=`expr $end_data - $begin_data`
 echo "it takes $spendtime sec for packing the data directory" >>$time_cost
------------遇到的问题----
报错1安装报错
[root@439607-db1-crov local]# rpm -ivh percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm 
warning: percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID cd2efd2a
error: Failed dependencies:
        perl(DBD::mysql) is needed by percona-xtrabackup-2.1.4-656.rhel5.x86_64
出现上述报错,需要执行“yum install perl-DBD-MySQL”
 
报错2
日志报错Can't connect to local MySQL server through socket '/tmp/mysql.sock'
#cat  xtrabackup_log_2014-11-03_02:10:01
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Ireland Ltd 2009-2012.  All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
141103 02:10:02  innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/etc/my_umc.cnf;mysql_read_default_group=xtrabackup' as 'backupuser'  (using password: YES).
ERROR: Failed to connect to MySQL server: DBI connect(';mysql_read_default_file=/etc/my_umc.cnf;mysql_read_default_group=xtrabackup','backupuser',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at /usr/bin/innobackupex line 1384
解决:
备份脚本xtrabackup.sh添加socket="/tmp/mysql_umc.sock",如果还报错,是因为脚本拷贝过程中产生了问题,从正确部署的机器上拷贝即可

报错3, 执行备份脚本报错line 35: break: only meaningful in a `for', `while', or `until' loop

原因:脚本错误,请重新粘贴上述提供的脚本,并注意排版,避免乱行



  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值