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)授權
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ù)庫實例
到此這篇關于mysql中xtrabackup全量備份/增量備份及恢復的文章就介紹到這了,更多相關mysql xtrabackup全量備份/增量備份內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
深入理解SQL的四種連接-左外連接、右外連接、內連接、全連接
本篇文章是對SQL中的四種連接-左外連接、右外連接、內連接、全連接進行了詳細的分析介紹,需要的朋友參考下2013-07-07MySQL數(shù)據(jù)庫中CAST與CONVERT函數(shù)實現(xiàn)類型轉換的講解
今天小編就為大家分享一篇關于MySQL數(shù)據(jù)庫中CAST與CONVERT函數(shù)實現(xiàn)類型轉換的講解,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03