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
| 1. 解压备份文件 unzip mysql_backup-202407060330.zip # 由于文件解压后250G,会报:sed: regex input buffer length larger than INT_MAX # 分隔成member_aa,member_ab,member_ac,member_ad,member_ae split -b 50G mysql_backup-202407060330.sql member_
2. 从全备备份文件中,挖出表名cm_t、bb_t的表结构,并输出到文件cm_t-create.sql、bb_t-create.sql sed -e'/./{H;$!d;}' -e 'x;/CREATE TABLE `cm_t`/!d;q' mysql_backup-202407060330.sql > cm_t-create.sql sed -e'/./{H;$!d;}' -e 'x;/CREATE TABLE `bb_t`/!d;q' mysql_backup-202407060330.sql > bb_t-create.sql
3.1 第2步找出来很慢,可以手动创建表结构
4. 从全备备份文件中,挖出表名cm_t、bb_t所有insert语句,并输出到文件cm_t-data.sql、bb_t-data.sql grep -i 'INSERT INTO `cm_t`' mysql_backup-202407060330.sq > cm_t-data.sql grep -i 'INSERT INTO `bb_t`' mysql_backup-202407060330.sql > bb_t-data.sql
4.1 从分隔后的文件找到对应的insert语句 grep -i -n 'INSERT INTO `cm_t`' member_ad |more # 26073:INSERT INTO `cm_t` # 54507 grep -i 'INSERT INTO `cm_t`' member_ad >> cm_t-data.sql
grep -n 'INSERT INTO `bb_t`' member_aa |more # 17383:INSERT INTO `bb_t` wc -l < member_aa # 55735 grep -i 'INSERT INTO `bb_t`' member_aa > bb_t-data.sql
5. 新建临时库repl,将新表恢复到临时库中 # 恢复表结构 mysql -h 192.168.64.33 -P 3306 -u root -p repl < cm_t-create.sql mysql -h 192.168.64.33 -P 3306 -u root -p repl < bb_t-create.sql # 恢复表数据 mysql -h 192.168.64.33 -P 3306 -u root -p repl < cm_t-data.sql mysql -h 192.168.64.33 -P 3306 -u root -p repl < bb_t-data.sql
|