欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mysql中xtrabackup全量備份/增量備份及恢復

 更新時間:2024年09月15日 10:52:32   作者:zyjzyjjyzjyz  
本文詳細介紹了使用XtraBackup工具進行MySQL數(shù)據(jù)庫的全量備份、增量備份以及恢復的詳細步驟,文章詳細列出了所需目錄結構、配置文件和命令,為數(shù)據(jù)庫管理員提供了一套完整的備份恢復解決方案

一、測試前準備

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的四種連接-左外連接、右外連接、內連接、全連接

    本篇文章是對SQL中的四種連接-左外連接、右外連接、內連接、全連接進行了詳細的分析介紹,需要的朋友參考下
    2013-07-07
  • 批量 kill mysql 中運行時間長的sql

    批量 kill mysql 中運行時間長的sql

    這篇文章主要介紹了批量 kill mysql 中運行時間長的sql,需要的朋友可以參考下
    2016-01-01
  • MySQL如何實現(xiàn)兩張表取差集

    MySQL如何實現(xiàn)兩張表取差集

    這篇文章主要介紹了MySQL如何實現(xiàn)兩張表取差集問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • 尋找sql注入的網(wǎng)站的方法(必看)

    尋找sql注入的網(wǎng)站的方法(必看)

    下面小編就為大家?guī)硪黄獙ふ襰ql注入的網(wǎng)站的方法(必看)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • 詳解mysql不等于null和等于null的寫法

    詳解mysql不等于null和等于null的寫法

    這篇文章主要介紹了詳解mysql不等于null和等于null的寫法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-09-09
  • MySql 5.6.35 winx64 安裝詳細教程

    MySql 5.6.35 winx64 安裝詳細教程

    這篇文章主要介紹了MySql 5.6.35 winx64 安裝詳細教程,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-02-02
  • MySQL Hash索引和B-Tree索引的區(qū)別

    MySQL Hash索引和B-Tree索引的區(qū)別

    MySQL Hash索引和B-Tree索引的區(qū)別究竟在哪里呢?相信很多人都有這樣的疑問,下文對兩者的區(qū)別進行了詳細的分析,需要的朋友可以參考下
    2014-03-03
  • MySQL索引失效之隱式轉換的問題

    MySQL索引失效之隱式轉換的問題

    本文主要介紹了MySQL索引失效之隱式轉換的問題,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • MySQL如何匹配字符串函數(shù)

    MySQL如何匹配字符串函數(shù)

    MySQL提供多個字符串匹配函數(shù),如like、locate、position、instr和find_in_set,其中l(wèi)ocate、position、instr和find_in_set均返回字符在字段中的索引(如果包含),否則返回0,特別地,find_in_set適用于字段為數(shù)組的情況
    2024-11-11
  • MySQL數(shù)據(jù)庫中CAST與CONVERT函數(shù)實現(xiàn)類型轉換的講解

    MySQL數(shù)據(jù)庫中CAST與CONVERT函數(shù)實現(xiàn)類型轉換的講解

    今天小編就為大家分享一篇關于MySQL數(shù)據(jù)庫中CAST與CONVERT函數(shù)實現(xiàn)類型轉換的講解,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03

最新評論