【備份工具】Xtraback 全量備份恢復(fù)

環(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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容