MySQL备份之xtrabackup
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL备份之xtrabackup相关的知识,希望对你有一定的参考价值。
目录
1.xtrabackup安装
2.xtrabackup原理
3.xtrabackup命令详解
1)xtrabackup安装
wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.12/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.12-1.el7.x86_64.rpm
yum -y localinstall percona-xtrabackup-24-2.4.12-1.el7.x86_64.rpm
2)xtrabackup原理
2.1)xtrabackup备份流程
start xtrabackup_log 启动innobackupex;
开启xtrabackup线程
copy redo log 开启os_thread_create 线程 拷贝 redo log文件
copy ibd;ibdata1 开启os_thread_create 拷贝idb data文件
等待拷贝完idb data文件后下发一个flush tables with read lock锁
flush tables with read lock
copy .FRM;MYD;MYI;misc files 拷贝文件frm;myd,myi,misc文件
show master status show master status输出get binary log position and so on;
stop copy redo log 停止拷贝redo log后 unlock table;
unlock table
stop and copy xtrabackup_log
2.2)观察方法
3)xtrabackup命令详解
3.1)备份
innobackupex -S /tmp/mysql3306.sock -uroot -p666666 --no-timestamp /data/backup/db3306-`date +%F`
3.2)恢复
innobackupex --apply-log /data/backup/db3306-2019-01-28
service mysqld stop
cd /data/mysql/mysql3306/
mv data data_`date +%F`
mkdir data
提示:(innodb_log_group_home_dir =./ 需要删掉)
innobackupex --copy-back /data/backup/db3306-2019-01-28/
chown -R mysql:mysql /data/mysql/mysql3306/data
3.3)加密备份
openssl rand -base64 24
innobackupex --encrypt=AES256 --encrypt-key=1CaXAN1nI+MMhSgpVLuENBM9rq3OLKpO -S /tmp/mysql3306.sock -uroot -p666666 --no-timestamp /data/backup/db3306-`date +%F_%T`
3.4)恢复
innobacupex --encrypt=AES256 --encrypt-key=1CaXAN1nI+MMhSgpVLuENBM9rq3OLKpO /data/backup/db3306-2019-01-25_09:46:52
service mysqld stop
cd /data/mysql/mysql3306/
mv data data_`date +%F`
mkdir data
提示:(innodb_log_group_home_dir =./ 需要删掉)
innobackupex --copy-back /data/backup/db3306-2019-01-28/
chown -R mysql:mysql /data/mysql/mysql3306/data
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
innobackupex -uroot -p666666 --no-timestamp -S /tmp/mysql3306.sock --stream=tar ./ |ssh -p 22 192.168.20.212 "gzip - >/data/backup/db3306_`date +%F_%T`.tat.gz"(测试:无法解压可能跟版本有关)
以上是关于MySQL备份之xtrabackup的主要内容,如果未能解决你的问题,请参考以下文章
Mysql增量备份之Mysqldump & Mylvmbackup