?
mydumper安裝:
mydumper原理:
myloader原理:
?
一、mydumper備份
?
1、開啟16個(gè)備份進(jìn)程,備份出所有的庫以及二進(jìn)制日志文件,到指定目錄/docker/mydumper/all_backup下
mydumper -u root -p root123?–threads=16 -o /docker/mydumper/all_backup
這里的–threads=16指定開啟16個(gè)備份線程數(shù),這個(gè)可以在MySQL里面show processlist看出來。
備份完成后,每個(gè)表都會(huì)有兩個(gè)文件:
一個(gè)是表結(jié)構(gòu)文件database.table-schema.sql;
一個(gè)是表數(shù)據(jù)文件database.table.sql。
此外還有一次二進(jìn)制日志文件metadata。
$ cat metadata
Started dump at: 2017-06-15 10:57:24
SHOW MASTER STATUS:
? ? Log: mysql-bin.000025
? ? Pos: 681395159
? ? GTID:6fbc72af-348e-11e7-865c-fa163e5807c3:1-22,
ad9b2529-348d-11e7-bef0-fa163e9e3c14:1-2663607
?
SHOW SLAVE STATUS:
? ? Host: 10.157.24.87
? ? Log: mysql-bin.000047
? ? Pos: 144635857
? ? GTID:6fbc72af-348e-11e7-865c-fa163e5807c3:1-22,
ad9b2529-348d-11e7-bef0-fa163e9e3c14:1-2663607
?
Finished dump at: 2017-06-15 10:58:50
?
注:如果沒有指定輸出的目錄:mydumper -u root -p root123
則默認(rèn)自動(dòng)生成export-20170615-105920目錄(export-年月日-時(shí)分秒)
?
2、備份出所有的庫到指定文件夾下并壓縮備份文件(這個(gè)備份壓縮過程會(huì)消耗過多的時(shí)間)
mydumper -u root -p root123 -c -o /docker/mydumper/all_backup_compress
會(huì)將表結(jié)構(gòu)文件和表數(shù)據(jù)文件都?jí)嚎s,二進(jìn)制日志文件不變,如下,文件大小從17G壓縮到了7.7G。
?????root@dpsvstadbs05 11:20:02:mydumper$ du -sh *
?????17G? ? all_backup
?????7.7G ? all_backup_compress
?
3、備份出sampson庫所有表的表結(jié)構(gòu),不備份數(shù)據(jù),到指定輸出的目錄/docker/mydumper/sampson-d下
mydumper -u root -p root123 -B sampson -d -o /docker/mydumper/sampson-d
則/docker/mydumper/sampson-d目錄下只有metadata和sampson.table-schema.sql文件。
?
4、備份出sampson庫所有表的數(shù)據(jù),不備份表結(jié)構(gòu),到指定輸出的目錄/docker/mydumper/sampson-m下
mydumper -u root -p root123 -B sampson -m -o /docker/mydumper/sampson-m
則/docker/mydumper/sampson-m目錄下只有metadata和sampson.table.sql文件。
?
5、備份出sampson庫所有dsns和t1表到指定輸出的目錄/docker/mydumper/sampson-T下
mydumper -u root -p root123 -B sampson -T dsns,t1 ?-o /docker/mydumper/sampson-T
則/docker/mydumper/sampson-T目錄下有metadata和sampson建庫文件以及dsns和t1表的備份文件。
?
注:如果備份需要后臺(tái)運(yùn)行,可以加–daemon實(shí)現(xiàn)后臺(tái)執(zhí)行導(dǎo)出命令。
?
二、myloader恢復(fù)
?
1、從全備的目錄中恢復(fù)sampson庫:
myloader -u root -p root123?–threads=16 –database=sampson -d /docker/mydumper/all_backup
?
2、從只備份了表結(jié)構(gòu)的目錄中恢復(fù)sampson庫表結(jié)構(gòu)到sampson-d庫中去:
myloader -u root -p root123 –database=sampson-d -d /docker/mydumper/sampson-d
?
3、從全備的文件夾中恢復(fù)sampson庫到samp庫中去:
myloader -u root -p root123 ?–database=samp –source-db=sampson? -d /docker/mydumper/all_backup
?
注意:建議備份恢復(fù)的時(shí)候加參數(shù)-v 3,顯示詳細(xì)的日志。
root@dpsvstadbs05 12:13:35:mydumper$ myloader -u root -p root123? -d /docker/mydumper/all_backup –database=huihui –source-db=lizhi -v 3
** Message: 4 threads created
** Message: Creating database `huihui`
** Message: Creating table `huihui`.`my1`
** Message: Creating table `huihui`.`my2`
** Message: Creating table `huihui`.`my3`
** Message: Creating table `huihui`.`my4`
** Message: Creating table `huihui`.`my5`
** Message: Creating table `huihui`.`my6`
** Message: Creating table `huihui`.`my7`
** Message: Creating table `huihui`.`t1`
** Message: Thread 1 restoring `lizhi`.`my1` part 0
** Message: Thread 3 restoring `lizhi`.`my2` part 0
** Message: Thread 2 restoring `lizhi`.`my3` part 0
** Message: Thread 4 restoring `lizhi`.`my4` part 0
** Message: Thread 3 restoring `lizhi`.`my5` part 0
** Message: Thread 1 restoring `lizhi`.`my6` part 0
** Message: Thread 4 restoring `lizhi`.`my7` part 0
** Message: Thread 2 restoring `lizhi`.`t1` part 0
** Message: Thread 2 shutting down
** Message: Thread 1 shutting down
** Message: Thread 4 shutting down
** Message: Thread 3 shutting down
?
附:
?
mydumper參數(shù)詳解
?
$ mydumper --helpUsage: mydumper [OPTION...] multi-threaded MySQL dumping Help Options: -?, --help Show help optionsApplication Options: -B, --database 要備份的數(shù)據(jù)庫,不指定則備份所有庫 -T, --tables-list 需要備份的表,名字用逗號(hào)隔開 -o, --outputdir 備份文件輸出的目錄 -s, --statement-size 生成的insert語句的字節(jié)數(shù),默認(rèn)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 如果表數(shù)據(jù)是空,還是產(chǎn)生一個(gè)空文件(默認(rèn)無數(shù)據(jù)則只有表結(jié)構(gòu)文件) -x, --regex Regular expression for 'db.table' matching 使用正則表達(dá)式匹配'db.table' -i, --ignore-engines Comma delimited list of storage engines to ignore忽略的存儲(chǔ)引擎,用逗號(hào)分割 -m, --no-schemas Do not dump table schemas with the data不備份表結(jié)構(gòu),只備份數(shù)據(jù) -d, --no-data Do not dump table data備份表結(jié)構(gòu),不備份數(shù)據(jù) -G, --triggers Dump triggers備份觸發(fā)器 -E, --events Dump events -R, --routines Dump stored procedures and functions備份存儲(chǔ)過程和函數(shù) -k, --no-locks 不使用臨時(shí)共享只讀鎖,使用這個(gè)選項(xiàng)會(huì)造成數(shù)據(jù)不一致 --less-locking Minimize locking time on InnoDB tables.減少對(duì)InnoDB表的鎖施加時(shí)間 -l, --long-query-guard 設(shè)定阻塞備份的長查詢超時(shí)時(shí)間,單位是秒,默認(rèn)是60秒(超時(shí)后默認(rèn)mydumper將會(huì)退出) -K, --kill-long-queries Kill long running queries (instead of aborting)殺掉長查詢 (不退出) -D, --daemon Enable daemon mode啟用守護(hù)進(jìn)程模式,守護(hù)進(jìn)程模式以某個(gè)間隔不間斷對(duì)數(shù)據(jù)庫進(jìn)行備 -I, --snapshot-interval dump快照間隔時(shí)間,默認(rèn)60s,需要在daemon模式下 -L, --logfile 使用的日志文件名(mydumper所產(chǎn)生的日志), 默認(rèn)使用標(biāo)準(zhǔn)輸出 --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 使用savepoints來減少采集metadata所造成的鎖時(shí)間,需要 SUPER 權(quán)限 --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 -h, --host 連接的主機(jī)名 -u, --user 用來備份的用戶名 -p, --password 用戶密碼 -P, --port 連接端口 -S, --socket 使用socket通信時(shí)的socket文件 -t, --threads 開啟的備份線程數(shù),默認(rèn)是4 -C, --compress-protocol 壓縮與mysql通信的數(shù)據(jù) -V, --version 顯示版本號(hào) -v, --verbose 輸出信息模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默認(rèn)為2
?
myloader參數(shù)詳解
?
$ myloader --helpUsage: myloader [OPTION...] multi-threaded MySQL loader Help Options: -?, --help Show help optionsApplication Options: -d, --directory Directory of the dump to import之前備份好的現(xiàn)在需要導(dǎo)入的文件夾 -q, --queries-per-transaction Number of queries per transaction, default 1000每次事物執(zhí)行的查詢數(shù)量,默認(rèn)是1000 -o, --overwrite-tables Drop tables if they already exist如果要恢復(fù)的表存在,則先drop掉該表,使用該參數(shù),需要備份時(shí)候要備份表結(jié)構(gòu) -B, --database An alternative database to restore into還原到指定的數(shù)據(jù)庫 -s, --source-db Database to restore選擇被還原的數(shù)據(jù)庫,將這個(gè)數(shù)據(jù)庫數(shù)據(jù)還原到--database指定的數(shù)據(jù)庫里 -e, --enable-binlog Enable binary logging of the restore data啟用還原數(shù)據(jù)的二進(jìn)制日志 -h, --host 連接的主機(jī)名 -u, --user 用來備份的用戶名 -p, --password 用戶密碼 -P, --port 連接端口 -S, --socket 使用socket通信時(shí)的socket文件 -t, --threads 開啟的備份線程數(shù),默認(rèn)是4 -C, --compress-protocol 壓縮與mysql通信的數(shù)據(jù) -V, --version 顯示版本號(hào) -v, --verbose 輸出信息模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默認(rèn)為2
?
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END