代码拉取完成,页面将自动刷新
同步操作将从 wj596/go-mysql-transfer 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* Copyright 2020-2021 the original author(https://github.com/wj596)
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"regexp"
"syscall"
"github.com/juju/errors"
"github.com/siddontang/go-mysql/mysql"
"go-mysql-transfer/global"
"go-mysql-transfer/metrics"
"go-mysql-transfer/service"
"go-mysql-transfer/storage"
"go-mysql-transfer/util/stringutil"
"go-mysql-transfer/web"
)
var (
helpFlag bool
cfgPath string
stockFlag bool
positionFlag bool
statusFlag bool
)
func init() {
flag.BoolVar(&helpFlag, "help", false, "this help")
flag.StringVar(&cfgPath, "config", "app.yml", "application config file")
flag.BoolVar(&stockFlag, "stock", false, "stock data import")
flag.BoolVar(&positionFlag, "position", false, "set dump position")
flag.BoolVar(&statusFlag, "status", false, "display application status")
flag.Usage = usage
}
func main() {
//stockFlag = true
//cfgPath = "D:\\transfer\\app.yml"
//cfgPath = "D:\\transfer\\release_test_luascript.yml"
//cfgPath = "D:\\transfer\\rabbitmq_release_test_lua.yml"
//cfgPath = "D:\\transfer\\rabbitmq_release_test_rule.yml"
// cfgPath = "D:\\transfer\\kafka_release_test_lua.yml"
// cfgPath = "D:\\transfer\\kafka_release_test_rule.yml"
//cfgPath = "D:\\transfer\\rocketmq_release_test_lua.yml"
//cfgPath = "D:\\transfer\\rocketmq_release_test_rule.yml"
//cfgPath = "D:\\transfer\\es7_release_test_lua.yml"
//cfgPath = "D:\\transfer\\es7_release_test_rule.yml"
//cfgPath = "D:\\transfer\\es6_release_test_lua.yml"
//cfgPath = "D:\\transfer\\es6_release_test_rule.yml"
//cfgPath = "D:\\transfer\\redis_release_test_lua.yml"
//cfgPath = "D:\\transfer\\redis_release_test_rule.yml"
//cfgPath = "D:\\transfer\\mongo_release_test_rule.yml"
//cfgPath = "D:\\transfer\\mongo_release_test_lua.yml"
flag.Parse()
if helpFlag {
flag.Usage()
return
}
// 初始化global
err := global.Initialize(cfgPath)
if err != nil {
println(errors.ErrorStack(err))
return
}
if stockFlag {
doStock()
return
}
// 初始化Storage
err = storage.Initialize()
if err != nil {
println(errors.ErrorStack(err))
return
}
if statusFlag {
doStatus()
return
}
if positionFlag {
doPosition()
return
}
err = service.Initialize()
if err != nil {
println(errors.ErrorStack(err))
return
}
if err := metrics.Initialize(); err != nil {
println(errors.ErrorStack(err))
return
}
if err := web.Start(); err != nil {
println(errors.ErrorStack(err))
return
}
service.StartUp() // start application
s := make(chan os.Signal, 1)
signal.Notify(s, os.Kill, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
sin := <-s
log.Printf("application stoped,signal: %s \n", sin.String())
web.Close()
service.Close()
storage.Close()
}
func doStock() {
stock := service.NewStockService()
if err := stock.Run(); err != nil {
println(errors.ErrorStack(err))
}
stock.Close()
}
func doStatus() {
ps := storage.NewPositionStorage()
pos, _ := ps.Get()
fmt.Printf("The current dump position is : %s %d \n", pos.Name, pos.Pos)
}
func doPosition() {
others := flag.Args()
if len(others) != 2 {
println("error: please input the binlog's File and Position")
return
}
f := others[0]
p := others[1]
matched, _ := regexp.MatchString(".+\\.\\d+$", f)
if !matched {
println("error: The parameter File must be like: mysql-bin.000001")
return
}
pp, err := stringutil.ToUint32(p)
if nil != err {
println("error: The parameter Position must be number")
return
}
ps := storage.NewPositionStorage()
pos := mysql.Position{
Name: f,
Pos: pp,
}
ps.Save(pos)
fmt.Printf("The current dump position is : %s %d \n", f, pp)
}
func usage() {
fmt.Fprintf(os.Stderr, `version: 1.0.0
Usage: transfer [-c filename] [-s stock]
Options:
`)
flag.PrintDefaults()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。