/
main.go
46 lines (38 loc) · 1.06 KB
/
main.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"flag"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/sjmudd/mysql_defaults_file"
"os"
"github.com/takaidohigasi/gtid-errant-fixer/src/replica"
)
func exitWithError(err error) {
fmt.Print(err)
os.Exit(1)
}
func main() {
var conf, monitorUser, monitorPass string
var forceOption bool
flag.StringVar(&conf, "c", ".my.cnf", "mysql client config(need SUPER priv to operate stop / slave)")
flag.StringVar(&monitorUser, "u", "root", "mysql client config ()")
flag.StringVar(&monitorPass, "p", "", "mysql client config ()")
flag.BoolVar(&forceOption, "f", false, "force execution (skip prompt to confirm Y/N")
flag.Parse()
if _, err := os.Stat(conf); err != nil {
exitWithError(err)
}
db, err := mysql_defaults_file.OpenUsingDefaultsFile("mysql", conf, "")
if err != nil {
exitWithError(err)
}
defer db.Close()
mysqlDB, err := replica.NewMySQLDB(db, monitorUser, monitorPass)
if err != nil {
exitWithError(err)
}
if err := mysqlDB.FixErrantGTID(forceOption); err != nil {
exitWithError(err)
}
fmt.Println("completed.")
}