从整库逻辑备份单独抽出一张表

前言:有时候因应用端有高权限的人员误操作,影响到的表只有一张,那么我们只要在前一天的备份里面一张表的数据,如果一个库表很多很大,异地恢复整个库,撇开机器性能不说,时间就浪费了。接下来说一下怎么抽取单张表内容。
 
原理:简单的说指定库名导出,mysqldump是按show tables顺序导出,你要抽取哪个表,就是要知道你下一个表名,把这段内容全部抽取出来就对了
1.确认你要导出的表名并查找出下一个表的表名字 cat xxxx.sql | grep "^-- Table structure for table" | grep -A 1 "aaa_opp" 
 
[root@web10 247_2015-09-03]# cat xxxx.sql | grep "^-- Table structure for table" | grep -A 1 "aaa_opp"
-- Table structure for table `aaa_opp`
-- Table structure for table `aaa_opp_copy`
-- Table structure for table `aaa_opp_update_history`
-- Table structure for table `aaa_org_region`
2.将你要抽出的表(aaa_ppp),(aaa_opp_copy)之间内容打印出来 sed -n "/^-- Table structure for table \`aaa_opp\`/,/^-- Table structure for table \`aaa_opp_copy\`/p"  xxxx.sql > temp.sql
3.然后在一个测试机导入,跟业务,研发人员处理并确认无误后,再导入生产库
posted @ 2015-09-11 15:39  文采飞扬  阅读(337)  评论(0编辑  收藏  举报