状况:
因人为失误造成一重要数据表table_a整个被删
现有备份情况:
Master:binlog
Slave:cron.daily->mysqldump(3点钟)
回档操作:
Slave:
awk 'BEGIN{temp_str = ""; find = "false"; end = "false";}{temp_str=temp_str""$0 ; if(match($0,"INSERT INTO `table_a`") >0 ) find="true"; if(match($0,";") >0 ) end = "true"; if(end=="true" && find=="false"){ temp_str=""; end="false"}; if(end=="true" && find=="true") {print temp_str; end="false"; find="false"}}' dump.sql > dump_awk.sql |
mysql -h Master -u dbroot -p rootpassword db_name < dump_awk.sql Master: /usr/local/mysql/bin/mysqlbinlog --start-datetime="2008-11-18 03:00:00" --stop-datetime="2008-11-18 09:00:00" mysql-bin.000123 > 123.sql
awk 'BEGIN{temp_str = ""; find = "false"; end = "false";}{temp_str=temp_str""$0 ; if(match($0,"table_a") >0 ) find="true"; if(match($0,";") >0 ) end = "true"; if(end=="true" && find=="false"){ temp_str=""; end="false"}; if(end=="true" && find=="true") {print temp_str; end="false"; find="false"}}' 123.sql > 123_awk.sql |
mysql -h Master -u dbroot -p rootpassword db_name < 123.sql