Created
June 1, 2014 11:26
-
-
Save yoku0825/bdc34d3bb30ed05c4701 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PATH=/bin:/usr/bin:/usr/local/mysql/bin | |
which mysqlbinlog > /dev/null || exit 1 | |
which mysql > /dev/null || exit 1 | |
while getopts h:u:p: OPT; do | |
case "$OPT" in | |
"h") host="$OPTARG";; | |
"u") user="--user=$OPTARG";; | |
"p") password="--password=$OPTARG";; | |
"P") port="--port=$OPTARG";; | |
esac | |
done | |
test -z $host && host="localhost" | |
while true; do | |
last_log_file=`ls ${host}_* 2> /dev/null | tail -1` | |
last_log_file=${last_log_file#${host}_} | |
if [ -z "$last_log_file" ]; then | |
last_log_file=`mysql --host=$host $user $password $port -ss --execute="SHOW MASTER LOGS" | awk '{print $1; exit}'` | |
if [ -z "$last_log_file" ]; then | |
echo "can't autodetect master binary log." | |
exit 1 | |
fi | |
fi | |
cmd="mysqlbinlog --host=$host $user $password $port --read-from-remote-server --stop-never --raw --result-file=${host}_ $last_log_file" | |
$cmd | |
sleep 10 | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment