基於MySQL MEB的備份恢復

来源:http://www.cnblogs.com/ivictor/archive/2016/09/27/5911919.html
-Advertisement-
Play Games

MEB(MySQL Enterprise Backup)是MySQL商業版中提供的備份工具,屬於物理備份。 同XtraBackup一樣,mysqlbackup的使用過程同樣包含如下三個步驟: 備份(--backup)=> 應用日誌(--apply-log)=> 恢復(--copy-back) 備份 ...


MEB(MySQL Enterprise Backup)是MySQL商業版中提供的備份工具,屬於物理備份。

同XtraBackup一樣,mysqlbackup的使用過程同樣包含如下三個步驟:

備份(--backup)=> 應用日誌(--apply-log)=> 恢復(--copy-back)

 

備份

# ./mysqlbackup --backup_dir=/backup --socket=/usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/data/mysql.sock backup

在備份目錄下,會生成以下文件

# ls
backup-my.cnf  datadir  meta  server-all.cnf  server-my.cnf

其中datadir和meta是目錄,其它是變數配置文件

backup-my.cnf

官方解釋如下:

Records the configuration parameters that specify the layout of the MySQL data files.

# cat backup-my.cnf 
#
# Generated backup-my.cnf file.
# Auto generated by mysqlbackup program.
#
[mysqld]
innodb_data_file_path=ibdata1:12M:autoextend
innodb_log_file_size=50331648
innodb_log_files_in_group=2
innodb_page_size=16384
innodb_checksum_algorithm=innodb

server-all.cnf

該文件記錄了備份資料庫的所有全局參數

server-my.cnf

該文件記錄了備份資料庫的非預設的全局參數

註意:在恢複數據庫時,可使用server-all.cnf和server-my.cnf中的任意一個。如果需要將資料庫恢復到非預設路徑,還要修改路徑相關的變數值。

 

再來看看meta目錄中的文件

# ls meta/
backup_content.xml  backup_create.xml  backup_gtid_executed.sql  backup_variables.txt  MEB_2016-09-27.10-49-21_backup.log

MEB_2016-09-27.10-49-21_backup.log

記錄了此次備份的詳細信息

backup_content.xml

記錄了備份文件的元數據信息和資料庫定義信息,同時還記錄了備份資料庫的plugin信息,恢復時必須確保這些插件在目標資料庫中同樣存在。

backup_create.xml

記錄了備份操作的相關信息,包括備份命令,備份的時間,備份的目錄,資料庫的參數信息

上述兩個文件可通過--disable-manifest選項禁用。

backup_gtid_executed.sql

因為備份資料庫啟動了GTID複製,故會生成該文件記錄GTID的信息

# cat backup_gtid_executed.sql 
# On a new slave, issue the following command if GTIDs are enabled:
  SET @@GLOBAL.GTID_PURGED='844e8202-8391-11e6-accb-000c29c64704:1-328944';

# Use the following command if you want to use the GTID handshake protocol:
# CHANGE MASTER TO MASTER_AUTO_POSITION=1; 

backup_variables.txt

記錄了備份的相關信息,該文件由mysqlbackup來控制的,譬如apply_log_done指示是否進行了apply-log操作

# cat backup_variables.txt 
#
# This file is auto generated by mysqlbackup.
#
[backup_variables]
start_lsn=98224128
end_lsn=98227650
apply_log_done=0
is_incremental=0
is_incremental_with_redo_log_only=0
is_partial=0
is_compressed=0
is_skip_unused_pages=0
binlog_position=mysql-bin.000005:65395090
gtid_executed=844e8202-8391-11e6-accb-000c29c64704:1-328944
is_onlyinnodb=0

關於各文件的說明,可參考官方文檔的解釋

https://dev.mysql.com/doc/mysql-enterprise-backup/3.12/en/meb-files-overview.html

 

應用日誌

./mysqlbackup --backup-dir=/backup/ apply-log

MySQL Enterprise Backup version 3.9.0 [2013/08/23] 
Copyright (c) 2003, 2013, Oracle and/or its affiliates. All Rights Reserved.

 mysqlbackup: INFO: Starting with following command line ...
 ./mysqlbackup --backup-dir=/backup/ apply-log 

IMPORTANT: Please check that mysqlbackup run completes successfully.
           At the end of a successful 'apply-log' run mysqlbackup
           prints "mysqlbackup completed OK!".

160927 11:38:43 mysqlbackup: INFO: MEB logfile created at /backup/meta/MEB_2016-09-27.11-38-43_apply_log.log

--------------------------------------------------------------------
                       Backup Config Options:
--------------------------------------------------------------------
  datadir = /backup/datadir
  innodb_data_home_dir = /backup/datadir
  innodb_data_file_path = ibdata1:12M:autoextend
  innodb_log_group_home_dir = /backup/datadir
  innodb_log_files_in_group = 2
  innodb_log_file_size = 50331648
  innodb_page_size = 16384
  innodb_checksum_algorithm = innodb

 mysqlbackup: INFO: Uses posix_fadvise() for performance optimization.
 mysqlbackup: INFO: Creating 14 buffers each of size 65536.
160927 11:38:43 mysqlbackup: INFO: Apply-log operation starts with following threads
        1 read-threads    1 process-threads
160927 11:38:43 mysqlbackup: INFO: ibbackup_logfile's creation parameters:
          start lsn 98224128, end lsn 98227650,
          start checkpoint 98224335.
InnoDB: Doing recovery: scanned up to log sequence number 98227650
 mysqlbackup: INFO: InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percent: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  mysqlbackup: INFO: InnoDB: Setting log file size to 50331648
 mysqlbackup: INFO: InnoDB: Setting log file size to 50331648
160927 11:38:48 mysqlbackup: INFO: We were able to parse ibbackup_logfile up to
          lsn 98227650.
 mysqlbackup: INFO: Last MySQL binlog file position 0 65394957, file name mysql-bin.000005
160927 11:38:48 mysqlbackup: INFO: The first data file is '/backup/datadir/ibdata1'
          and the new created log files are at '/backup/datadir'
160927 11:38:48 mysqlbackup: INFO: Apply-log operation completed successfully.
160927 11:38:48 mysqlbackup: INFO: Full backup prepared for recovery successfully.

mysqlbackup completed OK!

在應用日誌之前,

數據目錄中並沒有redo log

[root@localhost datadir]# ls
ibbackup_logfile  ibdata1  mysql  performance_schema  test

在應用完日誌之後,

數據目錄中會生成redo log

[root@localhost datadir]# ls
ibbackup_logfile  ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  test

 

恢復

./mysqlbackup --defaults-file=/backup/server-my.cnf --backup-dir=/backup/ copy-back

./mysqlbackup --defaults-file=/backup/server-my.cnf --backup-dir=/backup/ copy-back
MySQL Enterprise Backup version 3.9.0 [2013/08/23] 
Copyright (c) 2003, 2013, Oracle and/or its affiliates. All Rights Reserved.

 mysqlbackup: INFO: Starting with following command line ...
 ./mysqlbackup --defaults-file=/backup/server-my.cnf 
        --backup-dir=/backup/ copy-back 

IMPORTANT: Please check that mysqlbackup run completes successfully.
           At the end of a successful 'copy-back' run mysqlbackup
           prints "mysqlbackup completed OK!".

160927 15:26:55 mysqlbackup: INFO: MEB logfile created at /backup/meta/MEB_2016-09-27.15-26-55_copy_back.log

--------------------------------------------------------------------
                       Server Repository Options:
--------------------------------------------------------------------
  datadir = /usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/data/
  innodb_data_home_dir = /usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/data/
  innodb_data_file_path = ibdata1:12M:autoextend
  innodb_log_group_home_dir = /usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/data/
  innodb_log_files_in_group = 2
  innodb_log_file_size = 50331648
  innodb_page_size = 16384
  innodb_checksum_algorithm = innodb
  innodb_undo_directory = /usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/data/
  innodb_undo_tablespaces = 0
  innodb_undo_logs = 128

--------------------------------------------------------------------
                       Backup Config Options:
--------------------------------------------------------------------
  datadir = /backup/datadir
  innodb_data_home_dir = /backup/datadir
  innodb_data_file_path = ibdata1:12M:autoextend
  innodb_log_group_home_dir = /backup/datadir
  innodb_log_files_in_group = 2
  innodb_log_file_size = 50331648
  innodb_page_size = 16384
  innodb_checksum_algorithm = innodb

 mysqlbackup: INFO: Uses posix_fadvise() for performance optimization.
 mysqlbackup: INFO: Creating 14 buffers each of size 16777216.
160927 15:26:55 mysqlbackup: INFO: Copy-back operation starts with following threads
        1 read-threads    1 write-threads
160927 15:26:55 mysqlbackup: INFO: Copying /backup/datadir/ibdata1 (to '/usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/data')
.160927 15:26:59 mysqlbackup: INFO: Copying /backup/datadir/mysql/innodb_index_stats.ibd.
160927 15:26:59 mysqlbackup: INFO: Copying /backup/datadir/mysql/innodb_table_stats.ibd.
160927 15:26:59 mysqlbackup: INFO: Copying /backup/datadir/mysql/slave_master_info.ibd.
160927 15:26:59 mysqlbackup: INFO: Copying /backup/datadir/mysql/slave_relay_log_info.ibd.
160927 15:26:59 mysqlbackup: INFO: Copying /backup/datadir/mysql/slave_worker_info.ibd.
160927 15:27:00 mysqlbackup: INFO: Copying /backup/datadir/test/test.ibd.
160927 15:27:00 mysqlbackup: INFO: Copying the database directory 'mysql'
160927 15:27:00 mysqlbackup: INFO: Copying the database directory 'performance_schema'
160927 15:27:00 mysqlbackup: INFO: Copying the database directory 'test'
160927 15:27:00 mysqlbackup: INFO: Completing the copy of all non-innodb files.
160927 15:27:00 mysqlbackup: INFO: Copying the log file 'ib_logfile0'
160927 15:27:04 mysqlbackup: INFO: Copying the log file 'ib_logfile1'
160927 15:27:07 mysqlbackup: INFO: Creating server config files server-my.cnf and server-all.cnf in /usr/local/mysql-advanced-5.6.23-
linux-glibc2.5-x86_64/data/160927 15:27:07 mysqlbackup: INFO: Copy-back operation completed successfully.
160927 15:27:07 mysqlbackup: INFO: Finished copying backup files to '/usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/data/'

mysqlbackup completed OK!

關於恢復,有以下幾點需要註意

1. 恢復必須使用配置文件,建議備份目錄下的server-all.cnf和server-my.cnf,事實上,在恢復的過程中,mysqlbackup需要明確上述輸出中的參數,譬如,我使用了自己的配置文件進行恢復,結果報如下錯誤:

# ./mysqlbackup --defaults-file=/usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/my.cnf --backup-dir=/backup/
 copy-backMySQL Enterprise Backup version 3.9.0 [2013/08/23] 
Copyright (c) 2003, 2013, Oracle and/or its affiliates. All Rights Reserved.

 mysqlbackup: INFO: Starting with following command line ...
 ./mysqlbackup 
        --defaults-file=/usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/my.cnf 
        --backup-dir=/backup/ copy-back 

IMPORTANT: Please check that mysqlbackup run completes successfully.
           At the end of a successful 'copy-back' run mysqlbackup
           prints "mysqlbackup completed OK!".

160927 15:26:09 mysqlbackup: INFO: MEB logfile created at /backup/meta/MEB_2016-09-27.15-26-09_copy_back.log

 mysqlbackup: ERROR: Server innodb_log_files_in_group is missing or invalid
 mysqlbackup: ERROR: Server repository configuration problem found.

mysqlbackup failed with errors!

很顯然,我的配置文件中並沒有定義innodb_log_files_in_group參數。

2. 可在上述配置文件中server-all.cnf和server-my.cnf自定義數據目錄和base目錄,不然預設的都是備份資料庫的。

3. 雖然mysqlbackup --help中的解釋是:The restore operation assumes the server is offline. Use of this command when server is running is not supported.

   但事實上,在server是online的情況下,執行恢復操作並沒有報錯,甚至還顯示“mysqlbackup completed OK!”。但是,並沒有覆蓋數據目錄中的文件。

4. 在啟動資料庫的過程中,可以使用server-my.cnf或備份資料庫的配置文件,不要使用server-all.cnf。在使用server-all.cnf啟動資料庫的過程中,會報如下錯誤:

2016-09-27 15:51:37 85229 [ERROR] /usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/bin/mysqld: Table './mysql/user' is marked a
s crashed and should be repaired2016-09-27 15:51:37 85229 [ERROR] Fatal error: Can't open and lock privilege tables: Table './mysql/user' is marked as crashed and sh
ould be repaired

   這個坑定位了好久,因為server-all.cnf中定義的是所有參數的配置,懷疑跟某些參數有關,因參數較多,時間有限,並沒有一一驗證。

 

啟動資料庫

修改數據目錄的許可權

# chown -R mysql.mysql /usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/data

啟動資料庫

# /usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/bin/mysqld --defaults-file=/usr/local/mysql-advanced-5.
6.23-linux-glibc2.5-x86_64/my.cnf --user=mysql &

 

總結

以上只是mysqlbackup的一個簡單的備份恢復流程,事實上,mysqlbackup還支持壓縮備份等高級特性,後續再表。

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 成都聯通作為合併重組後的中國聯通在成都的分支機構,擁有基礎扎實的通信網路和當前最先進技術的WCDMA網路。隨著3G和4G業務的發展領先,成都聯通憑藉其出色的網路能力和服務,在用戶中贏得了口碑。 ...
  • 總結,int(M) zerofill,加上zerofill後M才表現出有點點效果,比如 int(3) zerofill,你插入到資料庫里的是10,則實際插入為010,也就是在前面補充加了一個0.如果int(3)和int(10)不加zerofill,則它們沒有什麼區別.M不是用來限制int個數的.in ...
  • 1、在安裝過程中,出現的 source /usr/local/greenplum-db/greenplum_path.sh 不要寫到profile或者./bashrc文件中 因為該句會導致python環境變數的改變,致使yum不能正常使用,出現no module named yum問題。 解決辦法: ...
  • 1.概述 從MYSQL5.6 開始,mysql開始支持GTID複製。 基於日誌點複製的缺點: 從那個二進位日誌的偏移量進行增量同步,如果指定錯誤會造成遺漏或者重覆,導致數據不一致。 基於GTID複製: 1.從伺服器會告訴主伺服器已執行的事務的GTID值。 2.主庫會告訴從哪些GTID事務沒有被執行。... ...
  • 目錄: 1.新建資料庫 2.新建數據表 3.查看表結構 4.增刪改查 建立一個資料庫students 建立一塊數據表class1 內容包括: 代碼如下: 1.建立資料庫 2.進入資料庫 3.新建表 4.查看表結構 1.插入(INSERT) 2.修改(UPDATE) 3.刪除(DELETE) 4.查詢 ...
  • Chpt 1 一、基本名詞 1.資料庫:實際上是一個信息列表 2.資料庫程式:虛擬的列表管理員 3.表:只用於存儲一類事情的信息,保持不同信息分類之間的獨立性可以讓資料庫以一種嚴密的組織方式高效地存儲信息 4.行/記錄:每一行都包含一個(且只有一個)由表名稱定義的項目信息 5.列/欄位:包含特定事物 ...
  • 【方法整理】Oracle 獲取trace跟蹤文件名的幾種常用方式 1 BLOG文檔結構圖 2 前言部分 2.1 導讀和註意事項 各位技術愛好者,看完本文後,你可以掌握如下的技能,也可以學到一些其它你所不知道的知識,~O(∩_∩)O~: ① trace跟蹤文件的獲取 Tips: ① 本文在itpub(... ...
  • 本文目錄列表: 1、sql server查看可編程對象定義的方式對比 2、整合實現所有可編程對象定義的查看功能的存儲dbo.usp_helptext2 3、dbo.helptext2的選擇性測試 4、總結語 5、參考清單列表 本文目錄列表: 1、sql server查看可編程對象定義的方式對比 2、 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...