From f35d965f630799d540ca5c1ba532188b6f1ccb86 Mon Sep 17 00:00:00 2001 From: smilingleo Date: Fri, 3 Jul 2015 10:02:10 +0800 Subject: [PATCH 1/4] test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45ffa683..b64ae7ee 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,4 @@ See the wiki page for : wiki文
  • 新浪微博: agapple0002
  • 报告issue:issues
  • +t From 87c14f0b5149ef556068b7713236549fb670c772 Mon Sep 17 00:00:00 2001 From: smilingleo Date: Fri, 3 Jul 2015 10:08:03 +0800 Subject: [PATCH 2/4] Revert "test" This reverts commit f35d965f630799d540ca5c1ba532188b6f1ccb86. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b64ae7ee..45ffa683 100644 --- a/README.md +++ b/README.md @@ -75,4 +75,3 @@ See the wiki page for : wiki文
  • 新浪微博: agapple0002
  • 报告issue:issues
  • -t From 199f30de87c9bb0a1008cd1cf9311b55c6bc2bfa Mon Sep 17 00:00:00 2001 From: smilingleo Date: Fri, 3 Jul 2015 10:29:58 +0800 Subject: [PATCH 3/4] add a script to fetch mysql master binlog file and sync position automatically --- example/src/main/bin/init.sh | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 example/src/main/bin/init.sh diff --git a/example/src/main/bin/init.sh b/example/src/main/bin/init.sh new file mode 100755 index 00000000..499f0a96 --- /dev/null +++ b/example/src/main/bin/init.sh @@ -0,0 +1,89 @@ +#! /bin/bash +current_path=`pwd` +case "`uname`" in + Linux) + bin_abs_path=$(readlink -f $(dirname $0)) + ;; + *) + bin_abs_path=`cd $(dirname $0); pwd` + ;; +esac +base=${bin_abs_path}/.. + +# default values +PORT=3306 +MYSQL_IP="0" + +# parse arguments +while getopts "h:p:" opt; do + case $opt in + p) + if [[ $OPTARG -gt 0 ]]; then + PORT=$OPTARG + else + echo "Invalid -p option: -$OPTARG, should be positive integer >&2" + exit 1 + fi + ;; + h) + MYSQL_IP=$OPTARG + ;; + \?) + printUsage + exit 1 + ;; + esac +done + +function printUsage +{ + cat << __Usage + +Initialise the instance config property file automatically. This tool will connect to Mysql master server and get the binlog file and position then update the instance config property file for you. + +Usage: $0 -p [port] -h [hostname] +Options: + -p: mysql port, default to 3306 + -h: mysql host ip. + For example: + $0 -p 3306 -h 172.17.0.2 + +Enjoy!!! + +__Usage +} + +if [[ $PORT -lt 0 ]]; then + echo "invalid port argument $PORT" + printUsage + exit 1 +fi + +# check if mysql ip is specified +if [[ $MYSQL_IP = "0" ]]; then + echo '-h mysql host ip argument is required.' + printUsage + exit 1 +fi + +MYSQL_ADDR="$MYSQL_IP:$PORT" + +MASTER_STATUS=`mysql -ucanal -pcanal -h192.168.22.89 -e 'show master status' 2>/dev/null | head -n 2 | tail -n 1` + +LOG_FILE=`echo "$MASTER_STATUS" | cut -f 1` +LOG_POS=`echo "$MASTER_STATUS" | cut -f 2` + +INSTANCE_CONF_FILE=$base/conf/example/instance.properties + +if [ ! -f $INSTANCE_CONF_FILE ]; then + echo "Can not find instance config file: $INSTANCE_CONF_FILE" + exit 1 +fi + +# replace the binlog file and position +sed -i.bak -e "s/canal\.instance\.master\.address = .*/canal\.instance\.master\.address = $MYSQL_ADDR/" -e "s/canal\.instance\.master\.journal\.name = .*/canal\.instance\.master\.journal\.name = $LOG_FILE/" -e "s/canal\.instance\.master\.position = .*/canal\.instance\.master\.position = $LOG_POS/" $INSTANCE_CONF_FILE + +cat $INSTANCE_CONF_FILE + +echo '\n==========================================' +echo 'Above is your instance config file, check if the settings are correct' From 169baafb8b0347204ea6a1c3e5a6efe2a4388013 Mon Sep 17 00:00:00 2001 From: smilingleo Date: Fri, 3 Jul 2015 10:32:40 +0800 Subject: [PATCH 4/4] correct format --- example/src/main/bin/init.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example/src/main/bin/init.sh b/example/src/main/bin/init.sh index 499f0a96..cca6825a 100755 --- a/example/src/main/bin/init.sh +++ b/example/src/main/bin/init.sh @@ -85,5 +85,6 @@ sed -i.bak -e "s/canal\.instance\.master\.address = .*/canal\.instance\.master\. cat $INSTANCE_CONF_FILE -echo '\n==========================================' +echo echo 'Above is your instance config file, check if the settings are correct' +echo