您好,登錄后才能下訂單哦!
mydumper
簡介:
由percona公司的Max Bubenick與facebook公司的Domas Mituzas共同維護開發(fā),也是個10年歷史的工具了,
與同為邏輯備份的mysqldump工具而言,其特性在于多線程并行備份,與官方同類型的mysqlpump相比,其優(yōu)點
在于一張表可以分到好幾個線程上進行備份。
安裝:
很多博客都推薦使用編譯的方式進行安裝 ,在這里點一下坑,由于mydumper依賴了 glib2-devel
mysql-devel zlib-devel pcre-devel openssl-devel等第三方庫,而這些庫之前并沒有按系統(tǒng)默認方式安裝
到各個默認位置,那么將會產(chǎn)生編譯安裝的連鎖指定編譯位置的問題。我在Cent7系統(tǒng)上安裝時,就遇到
很多編譯不通過或者編譯后使用報錯的問題,檢查環(huán)境后發(fā)現(xiàn)系統(tǒng)運維的同事使用編譯安裝的方式安裝了
MySQL 5.6與pcre庫。后面我嘗試使用yum安裝庫后,還是無法排除問題。
在這里我推薦使用開發(fā)者編譯好的rpm包進行安裝,配合yum可以自動補齊依賴,避免很多坑。
地址:https://github.com/maxbube/mydumper/releases,請根據(jù)自己的系統(tǒng)類型選擇下載版本。
`yum -y install https://github.com/maxbube/mydumper/releases/download/v0.9.3/mydumper-0.9.3-41.el7.x86_64.rpm`
使用:
$mydumper --help
Usage:
mydumper [OPTION...] multi-threaded MySQL dumping
Help Options:
-?, --help Show help options
Application Options:
-B, --database Database to dump
-T, --tables-list Comma delimited table list to dump (does not exclude regex option)
-o, --outputdir Directory to output files to
-s, --statement-size Attempted size of INSERT statement in bytes, default 1000000
-r, --rows Try to split tables into chunks of this many rows. This option turns off --chunk-filesize
-F, --chunk-filesize Split tables into chunks of this output file size. This value is in MB
-c, --compress Compress output files
-e, --build-empty-files Build dump files even if no data available from table
-x, --regex Regular expression for 'db.table' matching
-i, --ignore-engines Comma delimited list of storage engines to ignore
-m, --no-schemas Do not dump table schemas with the data
-d, --no-data Do not dump table data
-G, --triggers Dump triggers
-E, --events Dump events
-R, --routines Dump stored procedures and functions
-W, --no-views Do not dump VIEWs
-k, --no-locks Do not execute the temporary shared read lock. WARNING: This will cause inconsistent backups
--no-backup-locks Do not use Percona backup locks
--less-locking Minimize locking time on InnoDB tables.
-l, --long-query-guard Set long query timer in seconds, default 60
-K, --kill-long-queries Kill long running queries (instead of aborting)
-D, --daemon Enable daemon mode
-I, --snapshot-interval Interval between each dump snapshot (in minutes), requires --daemon, default 60
-L, --logfile Log file name to use, by default stdout is used
--tz-utc SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones, defaults to on use --skip-tz-utc to disable.
--skip-tz-utc
--use-savepoints Use savepoints to reduce metadata locking issues, needs SUPER privilege
--success-on-1146 Not increment error count and Warning instead of Critical in case of table doesn't exist
--lock-all-tables Use LOCK TABLE for all, instead of FTWRL
-U, --updated-since Use Update_time to dump only tables updated in the last U days
--trx-consistency-only Transactional consistency only
--complete-insert Use complete INSERT statements that include column names
-h, --host The host to connect to
-u, --user Username with the necessary privileges
-p, --password User password
-P, --port TCP/IP port to connect to
-S, --socket UNIX domain socket file to use for connection
-t, --threads Number of threads to use, default 4
-C, --compress-protocol Use compression on the MySQL connection
-V, --version Show the program version and exit
-v, --verbose Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
--defaults-file Use a specific defaults file
這里給出我最常用的備份方式:
mydumper -h 192.168.1.109 -P 3109 -u root -p 123456 -G -E -R -t 4 -c -o /data/bak/mysql/3109
說明:-h 指定地址
-P 指定備份端口
-u 指定備份用戶
-p 密碼
-G 備份觸發(fā)器
-E 備份定時事件
-R 備份存儲過程和函數(shù)
-t 備份時并發(fā)的線程數(shù)(不包含備份主線程)
-c 對備份文件進行壓縮(gz方式)
-o 指定備份存儲位置
原理與過程:
與mysqldump工具類似,先FTWRL(flush table with read lock),查詢自己本身的事務執(zhí)行位置(show
master status),然后開啟一個一致性快照事務,再啟動若干個子線程分別開啟一致性可重復讀快照事務,
使用子線程開啟事務并讀取數(shù)據(jù)和視圖,函數(shù),存儲過程,定時事件等。由于實例中可能有非事務型表的
存在,為保持一致性,待各個子線程全部備份完非事務型的表后才會釋放FTWRL。
這里重點說明下`--trx-consistency-only`參數(shù),很多博客都是粗粗點過甚至不翻譯。上一步中我們說到
mydumper為了獲取整個實例級別的一致性備份,會在開始備份時加上FTWRL,待各個線程都備份完非事務
表后,才會釋放FTWRL。這是考慮到5.7及之前的版本中mysql庫的部分表是MyISAM引擎,不具備事務特
性,或者業(yè)務上還存在非事務表。但8.0之后的版本中mysql庫全部改成了InnoDB引擎,或者用戶選擇不備
份mysql庫,或者實例中一張非事務表都沒有,這時mydumper會在創(chuàng)建完所有子線程并分別開啟一致性可
重復讀快照事務后就釋放FTWRL.因為這個時候根據(jù)事務特性已經(jīng)可以保證備份一致了。
若你確定沒有備份非事務型表,或者沒有備份mysql庫,或者實例中非事務表的一致性無關緊要,在你非常
介意備份時加的讀鎖對業(yè)務造成的影響的話,可以考慮加上`--trx-consistency-only`參數(shù)強制在創(chuàng)建完備的
子線程后就釋放鎖,減小備份對業(yè)務造成的寫堵塞
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。