简介:
数据库运行过程中难免会发生误操作,特别是在测试环境 开发人员或测试人员有时会误删或者更新错误某些数据。这时可以用binlog闪回DML操作。
条件:
- 1.mysql binlog必须存在且是row格式的
- 2.反向生成的表必须有主键
- 3.表结构不能有更改
1.shell脚本闪回:
# 脚本 del_time_recovery.sh(根据起止 time恢复)用于回滚delete操作:
#!/bin/bash
# File Name : del_time_recovery.sh
# Author : wang
# Description : delete recover according to starttime and endtime.
Usage() {
cat << EOF
mysql_delete_recovery
OPTIONS:
-b binlog name
-s starttime
-e endtime
-d database name
-t table name
For secrity: This scripts check the full need arguments
EOF
}
while getopts ":b:s:e:d:t:" opt; do
case $opt in
b)
logname=${OPTARG}
;;
s)
starttime=${OPTARG}
;;
e)
endtime=${OPTARG}
;;
d)
db=${OPTARG}
;;
t)
table=${OPTARG}
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." &g