Article Directory
xTraBackup introduction
MySQL cold standby, mysqldump, and MySQL hot copy cannot implement incremental backups of the database. In the actual production environment, incremental backup is very practical. If the data is larger than 50G or 100G and the storage space is sufficient, a full backup can be performed every day. If the amount of data generated every day is large, a data backup strategy needs to be customized. For example, a practical full backup every week, and a practical incremental backup from Monday to Saturday. Percona-Xtrabackup is a mainstream backup tool for incremental backup. Xtrabakackup has two tools, namely xtrabakup and innobakupe. This solution uses innobackup for database backup.
xTraBackup deployment
Precondition
- Make sure that the binlog log is enabled for the database. If it is not enabled, you need to enable it. Note that enabling this parameter requires restarting the database.
Check the command:
show variables like'%log_bin%';
- Additional backup storage space.
Deployment and installation
# 下载安装包
wget https://downloads.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.21/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.21-1.el7.x86_64.rpm
# 部署安装包
yum install -y percona-xtrabackup-24-2.4.21-1.el7.x86_64.rpm
# 检查安装状态
innobackupex -v
Backup path configuration
mkdir -p /data/backup/mysql_backup/
mkdir /data/backup/logs/
Backup script configuration
vi /data/backup/mysql_backup.sh
#!/bin/bash
. /etc/profile
. ~/.bash_profile
bakdir="/data/backup/mysql_backup/"
logfile="/data/backup/logs/full_mysql_`date '+%Y%m%d'`.log"
echo "=============================== "`date +"%Y-%m-%d %H:%M:%S"`" begin to backup ===============================" >> $logfile
innobackupex \
--defaults-file=/etc/my.cnf \
--user=root \
--password="" \
--socket=/home/mysql/mysql.sock \
--port=3306 \
--safe-slave-backup \
--safe-slave-backup-timeout=7200 \
--slave-info \
--backup $bakdir \
2>> $logfile
echo "=============================== "`date +"%Y-%m-%d %H:%M:%S"`" finished backup ===============================" >> $logfile
find $bakdir -mtime +30 -exec rm -rf {} \;
Scheduled task configuration
0 2 * * * /data/backup/mysql_backup.sh
It is recommended that the backup time select the time point that has the least impact on the business as much as possible to avoid slow business exceptions caused by the backup lock table.
Backup data check
File check
Backup files include database files, configuration files, and xtrabackup_checkpoints files required for consistency.