1. 程式人生 > >MySQL備份之xtrabackup

MySQL備份之xtrabackup

2.x 拷貝文件 xtra 線程 apply-log 遠程備份 ont reat 3.5

目錄

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)觀察方法

innobackupex -S /tmp/mysql3306.sock -uroot -p666666 /data/backup/ 2>&1 |tee 1.log

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

innobackupex --apply-log /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

3.5)遠程備份

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