-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathskip1062.sh
More file actions
32 lines (30 loc) · 1.13 KB
/
skip1062.sh
File metadata and controls
32 lines (30 loc) · 1.13 KB
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
#!/bin/sh
MYSQL="mysql -h 127.0.0.1 -P 3307 -e"
lastPos=0
while [ 1 ]; do
$MYSQL "show slave status\G" > /tmp/.skip
lastError=`cat /tmp/.skip|grep "Last_SQL_Errno"|awk '{print $2}'`
nowPos=`cat /tmp/.skip|grep "Exec_Master_Log_Pos"|awk '{print $2}'`
if [ $lastError -eq 1062 ]; then
if [ $lastPos -ne $nowPos ]; then
echo "blocked, skip one"
$MYSQL "stop slave; SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; start slave;"
lastPos=$nowPos
else
echo "sleep one second"
sleep 1
fi
elif [ $lastError -eq 0 ]; then
secondsBehind=`cat /tmp/.skip|grep "Seconds_Behind_Master"|awk '{print $2}'`
if [ $secondsBehind -eq 0 ]; then
echo "done"
break
else
echo "$secondsBehind seconds behind server"
sleep 3
fi
else
echo "error $lastError found"
break
fi
done