部署percona-xtrabackup备份

本文介绍如何在Linux环境下安装Percona XtraBackup,并通过示例展示如何设置MySQL增量备份脚本,包括解决安装过程中遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[root@sf1 ~]# mv percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm  /usr/local/
[root@sf1 ~]# cd /usr/local/
[root@sf1 local]# ll
total 173404
drwxr-xr-x  2 root root      4096 Oct  8 15:32 bin
drwxr-xr-x  5 root root      4096 Oct  8 15:32 etc
drwxr-xr-x  2 root root      4096 May 11  2011 games
drwxr-xr-x  2 root root      4096 May 11  2011 include
drwxr-xr-x  2 root root      4096 May 11  2011 lib
drwxr-xr-x  2 root root      4096 May 11  2011 lib64
drwxr-xr-x  2 root root      4096 May 11  2011 libexec
lrwxrwxrwx  1 root root        28 Oct  8 12:48 mysql -> mysql-5.5.11-linux2.6-x86_64
drwxr-xr-x 13 root root      4096 Oct  8 11:32 mysql-5.5.11-linux2.6-x86_64
-rw-r--r--  1 root root 168685879 Aug  8 15:12 mysql-5.5.11-linux2.6-x86_64.tar.gz
-rw-r--r--  1 root root   8598247 Sep 25 17:28 percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm
drwxr-xr-x  2 root root      4096 Oct  8 15:32 sbin
drwxr-xr-x  4 root root      4096 Sep 21 15:06 share
drwxr-xr-x  2 root root      4096 May 11  2011 src
[root@sf1 local]# rpm -ivh percona-xtrabackup-2.1.4-656.rhel5.x86_64.rpm
报错
[root@sf1 local]#yum install perl-DBD-MySQL
[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 [按Tab键补齐]
innobackupex        innobackupex-1.5.1  innochecksum   说明已经安装ok       
 
[root@sf1 studyfun]# pwd
/database/studyfun
[root@sf1 studyfun]# mkdir backup
touch  xtrabackup.sh 
chmod +x trabackup.sh 
[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
 
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'backupuser'@'localhost' identified by '123456';
FLUSH PRIVILEGES;


附脚本

# cat 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/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/redundency" ];
 then 
mkdir -p /database/studyfun/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


加入定时计划,每天凌晨2点10分执行备份

[root@sf1 ~]# crontab -l
10 02 * * * /database/studyfun/xtrabackup.sh



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值