mysql中xtrabackup全量備份/增量備份及恢復
一、測試前準備

mysql數(shù)據(jù)庫
| 端口 | 3306 |
| 數(shù)據(jù)文件目錄 | /data/mysql/3306/data |
| 安裝目錄 | /usr/lcoal/mysql |
| 配置文件 | /etc/my.cnf |
創(chuàng)建數(shù)據(jù)庫
testXtra
創(chuàng)建備份目錄
| 備份目錄 | /data/backup/ |
| 備份恢復數(shù)據(jù)文件目錄 | /data/mysql/3307/data |
| 備份恢復配置文件 | /etc/my_3307.cnf |
二、開始測試
1、全量備份數(shù)據(jù)庫
命令:
xtrabackup --user=root --password=mysql --backup --parallel=10 --target-dir=/data/backup/full

2、全量備份恢復(先準備,再恢復)
(1)準備
xtrabackup --prepare --use-memory=2G --target-dir=/data/backup/full


(2)恢復
恢復的機器必須有my.cnf配置文件,再配置文件中配置好datadir目錄即數(shù)據(jù)問目錄,數(shù)據(jù)目錄也必須為空,若不為空則會報錯。
測試在本機恢復
vi my_3307.cnf
[client]
socket=/data/mysql/3307/data/mysql.sock[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/3307/data
user=mysql
port=3307
socket=/data/mysql/3307/data/mysql.sock
log_error=/data/mysql/3307/data/mysqld.err
log_timestamps=system
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]
log-error=/data/mysql/3307/data/mysqld.err
pid-file=/data/mysql/3307/data/mysqld.pid#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
恢復命令
xtrabackup --defaults-file=/etc/my_3307.cnf --copy-back --parallel=10 --target-dir=/data/backup/full



(3)授權(quán)
chown -R mysql.mysql /data/mysql/3307/data
(4)啟動數(shù)據(jù)庫實例
mysqld_safe --defaults-file=/etc/my_3307.cnf &

(5)grep mysql

(6)查看備份文件

三、增量備份
1、先全量備份
xtrabackup --user=root --password=mysql --backup --target-dir=/data/backup/base

2、全量備份之后增加些數(shù)據(jù)

3、第一次增量備份
增量備份需要獲取全量備份的to_lsn。
(1)查看全量備份的to_lsn
cd /data/backup/base
cat xtrabackup_checkpoints

如上圖to_lsn=18374406
(2)第一次增量備份的命令
xtrabackup --user=root --password=mysql --backup --target-dir=/data/backup/inc4 --incremental-lsn=18374406


可以看到inc4是第一次增量備份生成的文件
(3)檢查下備份文件是否有新增的數(shù)據(jù)文件

可以看到test2表空間
4、第二次增量備份
(1)添加些數(shù)據(jù)

(2)查看第一次增量備份文件的to_lsn

(3)第二次增量備份的命令
xtrabackup --user=root --password=mysql --backup --target-dir=/data/backup/inc5 --incremental-lsn=18411278

5、增量備份恢復步驟
(1) 全量備份準備
xtrabackup --prepare --apply-log-only --target-dir=/data/backup/base

(2)第一次增量備份準備
xtrabackup --prepare --apply-log-only --target-dir=/data/backup/base --incremental-dir=/data/backup/inc4

(3)第二次增量備份準備
xtrabackup --prepare --target-dir=/data/backup/base --incremental-dir=/data/backup/inc5

(4)修改配置文件
vi /etc/my_3307.cnf
[client]
socket=/data/mysql/3307/data/mysql.sock[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/3307/data
user=mysql
port=3307
socket=/data/mysql/3307/data/mysql.sock
log_error=/data/mysql/3307/data/mysqld.err
log_timestamps=system
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]
log-error=/data/mysql/3307/data/mysqld.err
pid-file=/data/mysql/3307/data/mysqld.pid#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
(5)恢復命令
xtrabackup --defaults-file=/etc/my_3307.cnf --copy-back --target-dir=/data/backup/base
(6)檢查備份的數(shù)據(jù)文件

可以看到第一次增量備份后新增的表空間被恢復了。
(7)啟動備份的數(shù)據(jù)庫實例

(8)grep mysql

(9)登錄數(shù)據(jù)庫實例

到此這篇關(guān)于mysql中xtrabackup全量備份/增量備份及恢復的文章就介紹到這了,更多相關(guān)mysql xtrabackup全量備份/增量備份內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MYSQL必知必會讀書筆記第七章之數(shù)據(jù)過濾
這篇文章主要介紹了MYSQL必知必會讀書筆記第七章之數(shù)據(jù)過濾的相關(guān)資料,需要的朋友可以參考下2016-05-05
MySQL skip-character-set-client-handshake導致的一個字符集問題
這篇文章主要介紹了MySQL skip-character-set-client-handshake導致的一個字符集問題,需要的朋友可以參考下2014-07-07
MySQL數(shù)據(jù)庫創(chuàng)建新用戶及授予權(quán)限的完整流程
這篇文章主要給大家介紹了MySQL數(shù)據(jù)庫創(chuàng)建新用戶及授予權(quán)限的完整流程,通過這些步驟,管理員可以有效管理數(shù)據(jù)庫用戶,確保數(shù)據(jù)庫的安全性和高效運行,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-11-11
MySQL日期格式化yyyy-mm-dd詳解(DATE_FORMAT()函數(shù))
MySQL提供了很多功能強大、方便易用的函數(shù),在進行數(shù)據(jù)庫管理以及數(shù)據(jù)的查詢和操作時,幫助我們提高對數(shù)據(jù)庫的管理效率,下面這篇文章主要給大家介紹了關(guān)于MySQL日期格式化yyyy-mm-dd(DATE_FORMAT()函數(shù))的相關(guān)資料,需要的朋友可以參考下2023-01-01
解決mysql插入數(shù)據(jù)鎖等待超時報錯:Lock?wait?timeout?exceeded;try?restar
這篇文章主要介紹了解決mysql插入數(shù)據(jù)鎖等待超時報錯:Lock?wait?timeout?exceeded;try?restarting?transaction問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-05-05
MySQL連接器提升應(yīng)用功能與數(shù)據(jù)存儲能力
這篇文章主要為大家介紹了MySQL連接器提升應(yīng)用功能與數(shù)據(jù)存儲能力,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10

