mysql數(shù)據(jù)備份之xtrabackup

上一篇簡單介紹了一下MySQLdump進(jìn)行數(shù)據(jù)庫的備份和恢復(fù),這一篇說一下另一種備份工具xtrabackup,在InnoDB事務(wù)引擎泛濫的時(shí)代,xtrabackup可以很好的支持?jǐn)?shù)據(jù)庫的熱備份,這就很討人喜,

從網(wǎng)站建設(shè)到定制行業(yè)解決方案,為提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作服務(wù)體系,各種行業(yè)企業(yè)客戶提供網(wǎng)站建設(shè)解決方案,助力業(yè)務(wù)快速發(fā)展。成都創(chuàng)新互聯(lián)將不斷加快創(chuàng)新步伐,提供優(yōu)質(zhì)的建站服務(wù)。

 

Xtrabackup在epel源中有,所以直接用yum安裝即可;

完全備份就是直接連接MySQL服務(wù),給定一個目標(biāo)目錄即可;

 

[root@www ~]# innobackupex  --user=root --host=localhost --port=3306 --password='123456'  /data/mydata
181105 20:31:30 innobackupex: Starting the backup operation
 
IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".
…
181105 20:31:39 Executing UNLOCK TABLES
181105 20:31:39 All tables unlocked
181105 20:31:39 Backup created in directory '/data/mydata/2018-11-05_20-31-30'
181105 20:31:39 [00] Writing backup-my.cnf
181105 20:31:39 [00]        ...done
181105 20:31:39 [00] Writing xtrabackup_info
181105 20:31:39 [00]        ...done
xtrabackup: Transaction log of lsn (9424992) to (9424992) was copied.
181105 20:31:39 completed OK!

 

 

然后我們就可以在備份的目錄中看到幾個文件

[root@www ~]# ls /data/mydata/2018-11-05_20-31-30/
backup-my.cnf  ibdata1  performance_schema  xtrabackup_checkpoints  xtrabackup_logfile
hellodb        mysql    wpsdb               xtrabackup_info         zabbix

 

除了數(shù)據(jù)庫之外,還有幾個特殊的文件:

xtrabackup_binlog_info:記錄了整個備份過程中的一些屬性信息;

[root@www ~]# cd /data/mydata/2018-11-05_20-31-30/
[root@www 2018-11-05_20-31-30]# cat xtrabackup_info
uuid = 725248b0-da18-11e8-9fcc-000c29ceaa48
name =
tool_name = innobackupex
tool_command = --user=root --host=localhost --port=3306 --password=... /data/mydata
tool_version = 2.3.6
ibbackup_version = 2.3.6
server_version = 5.5.60-MariaDB
start_time = 2018-11-05 20:31:31
end_time = 2018-11-05 20:31:39
lock_time = 0
binlog_pos =
innodb_from_lsn = 0
innodb_to_lsn = 9424992
partial = N
incremental = N
format = file
compact = N
compressed = N
encrypted = N

 

backup-my.cnf:記錄與InnoDB存儲引擎相關(guān)的重要配置參數(shù);

[root@www 2018-11-05_20-31-30]# cat backup-my.cnf
# This MySQL options file was generated by innobackupex.
 
# The MySQL server
[mysqld]
innodb_checksum_algorithm=innodb
innodb_log_checksum_algorithm=innodb
innodb_data_file_path=ibdata1:10M:autoextend
innodb_log_files_in_group=2
innodb_log_file_size=5242880
innodb_fast_checksum=false
innodb_page_size=16384
innodb_log_block_size=512
innodb_undo_directory=.
innodb_undo_tablespaces=0

 

xtrabackup_checkpoints:記錄了此次的類型及起始和終止的LSN;

[root@www 2018-11-05_20-31-30]# cat xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 9424992
last_lsn = 9424992
compact = 0
recover_binlog_info = 0
 
xtrabackup_binlog_info:記錄當(dāng)前使用的二進(jìn)制日志的一致性坐標(biāo);
[root@www 2018-11-05_20-55-04]# cat xtrabackup_binlog_info
binlog.000001       245

 

 

完全備份的恢復(fù)(mysql的數(shù)據(jù)目錄為空):

       恢復(fù)數(shù)據(jù)的過程只需要添加一個--copy-back即可完成;

[root@www 2018-11-05_20-55-04]# innobackupex --copy-back ./
181105 20:59:30 innobackupex: Starting the copy-back operation
 
IMPORTANT: Please check that the copy-back run completes successfully.
           At the end of a successful copy-back run innobackupex
           prints "completed OK!".

 

增量備份:

       相比于之前的完全備份,需要--incremental和--incremental-basedir兩個選項(xiàng)即可;

[root@www ~]# innobackupex --incremental /data/mydata --incremental-basedir=/data/mydata/2018-11-05_20-31-30
181105 20:54:41 innobackupex: Starting the backup operation
 
IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".
…
181105 20:55:14 Executing UNLOCK TABLES
181105 20:55:14 All tables unlocked
181105 20:55:14 Backup created in directory '/data/mydata/2018-11-05_20-55-04'
MySQL binlog position: filename 'binlog.000001', position '245'
181105 20:55:14 [00] Writing backup-my.cnf
181105 20:55:14 [00]        ...done
181105 20:55:14 [00] Writing xtrabackup_info
181105 20:55:14 [00]        ...done
xtrabackup: Transaction log of lsn (9424992) to (9424992) was copied.
181105 20:55:14 completed OK!

 

通過查看xtrabackup-checkpoints文件內(nèi)容即可;

[root@www 2018-11-05_20-55-04]# cat xtrabackup_checkpoints
backup_type = incremental
from_lsn = 9424992
to_lsn = 9424992
last_lsn = 9424992
compact = 0
recover_binlog_info = 0

 

增量備份的恢復(fù)過程同上,也是一個--copy-back即可;

xtrabackup是一個相當(dāng)好的備份工具,在如今事務(wù)引擎遍地的時(shí)代,良好的熱備份機(jī)制和簡單化的操作,對我們來說很友好,所以,我很推薦這個工具,而mysqldump大多用來做測試用,因?yàn)閙ysqldump需要鎖表,所以溫備份機(jī)制在這方便不如xtrabackup的熱備份機(jī)制。但是,在我們實(shí)驗(yàn)環(huán)境做測試的情況下,這個直接打包成數(shù)據(jù)庫,copy到其他主機(jī)就可以釋放,還是很不錯的。

分享標(biāo)題:mysql數(shù)據(jù)備份之xtrabackup
本文URL:http://bm7419.com/article34/gijspe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、移動網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司定制開發(fā)、外貿(mào)建站關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站