您好,登錄后才能下訂單哦!
上一篇簡(jiǎn)單介紹了一下mysqldump進(jìn)行數(shù)據(jù)庫(kù)的備份和恢復(fù),這一篇說(shuō)一下另一種備份工具xtrabackup,在InnoDB事務(wù)引擎泛濫的時(shí)代,xtrabackup可以很好的支持?jǐn)?shù)據(jù)庫(kù)的熱備份,這就很討人喜,
Xtrabackup在epel源中有,所以直接用yum安裝即可;
完全備份就是直接連接MySQL服務(wù),給定一個(gè)目標(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!
然后我們就可以在備份的目錄中看到幾個(gè)文件
[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ù)庫(kù)之外,還有幾個(gè)特殊的文件:
xtrabackup_binlog_info:記錄了整個(gè)備份過(guò)程中的一些屬性信息;
[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存儲(chǔ)引擎相關(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:記錄了此次的類(lèi)型及起始和終止的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ù)的過(guò)程只需要添加一個(gè)--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兩個(gè)選項(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!
通過(guò)查看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ù)過(guò)程同上,也是一個(gè)--copy-back即可;
xtrabackup是一個(gè)相當(dāng)好的備份工具,在如今事務(wù)引擎遍地的時(shí)代,良好的熱備份機(jī)制和簡(jiǎn)單化的操作,對(duì)我們來(lái)說(shuō)很友好,所以,我很推薦這個(gè)工具,而mysqldump大多用來(lái)做測(cè)試用,因?yàn)閙ysqldump需要鎖表,所以溫備份機(jī)制在這方便不如xtrabackup的熱備份機(jī)制。但是,在我們實(shí)驗(yàn)環(huán)境做測(cè)試的情況下,這個(gè)直接打包成數(shù)據(jù)庫(kù),copy到其他主機(jī)就可以釋放,還是很不錯(cuò)的。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。