【備份工具】XtraBackup 壓縮備份恢復(fù)

環(huán)境

  • xtrabackup 2.4.21
  • 數(shù)據(jù)庫版本:MySQL 5.7.27

壓縮備份

xtrabackup --defaults-file=/etc/my.cnf --user=databak  -S /tmp/mysql.sock --parallel=2 --backup --compress --target-dir=/app/xtra_full_`date +%Y%m%d%H%M%S`

可以使用并行壓縮參數(shù)--compress --compress-threads=2
xtrabackup --defaults-file=/etc/my.cnf --user=databak -S /tmp/mysql.sock --parallel=2 --backup --compress --compress-threads=2 --target-dir=/app/xtra_full_`date +%Y%m%d%H%M%S`

恢復(fù)

準(zhǔn)備備份

解壓縮

解壓縮需要安裝qpress

wget "http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/183466/cn_zh/1608011575185/qpress-11-linux-x64.tar"
tar xvf qpress-11-linux-x64.tar
chmod 775 qpress
cp qpress /usr/bin

解壓

xtrabackup --defaults-file=/etc/my.cnf --decompress --target-dir=/app/xtra_full_20210127001702

準(zhǔn)備數(shù)據(jù)

# 應(yīng)用日志
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/app/xtra_full_20210127001702/

恢復(fù)文件

  • 恢復(fù)前需要停止 MySQL
  • 恢復(fù)前保證MySQL數(shù)據(jù)目錄為空
xtrabackup --defaults-file=/etc/my.cnf --copy-back --target-dir=/app/xtra_full_20210126234309/

#備份文件不需要保留的也能直接move,會快很多
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ù)實際的datadir設(shè)置

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

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

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