環(huán)境
- xtrabackup 2.4.21
- 數(shù)據(jù)庫版本:MySQL 5.7.27
全量備份
創(chuàng)建備份用戶
mysql> create user 'databak'@'localhost' identified by '1122333';
# 最小權(quán)限需要給 reload,lock tables,super這三個(gè),其余的看著給一般不需要了
mysql> grant reload,lock tables,super,replication client,show view,event,process on *.* to 'databak'@localhost;
mysql> plush privileges;
全備
備份數(shù)據(jù)會(huì)在備份目錄下創(chuàng)建一個(gè)以當(dāng)前日期時(shí)間為名字的目錄存放備份文件
xtrabackup --defaults-file=/etc/my.cnf --user=databak -S /tmp/mysql.sock --parallel=2 --backup --target-dir=/data/backup/xtra_full_`date +%Y%m%d%H%M%S`
恢復(fù)
準(zhǔn)備操作
應(yīng)用日志
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/app/xtra_full_20210126234309/
/**
...
InnoDB: Shutdown completed; log sequence number 10524266024
210126 23:59:55 completed OK!
*/
停止mysql
- 恢復(fù)前需要停止 MySQL
- 恢復(fù)前保證MySQL數(shù)據(jù)目錄為空
恢復(fù)文件
xtrabackup --defaults-file=/etc/my.cnf --copy-back --target-dir=/app/xtra_full_20210126234309/
#備份文件不需要保留的也能直接move,會(huì)快很多
xtrabackup --defaults-file=/etc/my.cnf --move-back --target-dir=/app/xtra_full_20210126234309/
授權(quán)
修改MySQL數(shù)據(jù)文件權(quán)限,'/var/lib/mysql'是數(shù)據(jù)文件路徑,根據(jù)實(shí)際的datadir設(shè)置
chown -R mysql:mysql /var/lib/mysql