forked from signal18/replication-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision.go
109 lines (101 loc) · 4.45 KB
/
provision.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL
// Authors: Guillaume Lefranc <[email protected]>
// Stephane Varoqui <[email protected]>
// This source code is licensed under the GNU General Public License, version 3.
// Redistribution/Reuse of this code is permitted under the GNU v3 license, as
// an additional term, ALL code must carry the original Author(s) credit in comment form.
// See LICENSE in this directory for the integral text.
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/tanji/replication-manager/cluster"
)
var (
source string
destination string
cleanall = false
)
func init() {
rootCmd.AddCommand(bootstrapCmd)
rootCmd.AddCommand(provisionCmd)
provisionCmd.Flags().StringVar(&source, "source", "", "Source server")
provisionCmd.Flags().StringVar(&destination, "destination", "", "Source server")
bootstrapCmd.Flags().BoolVar(&cleanall, "clean-all", false, "Reset all slaves and binary logs before bootstrapping")
bootstrapCmd.Flags().StringVar(&conf.PrefMaster, "prefmaster", "", "Preferred server for master initialization")
bootstrapCmd.Flags().StringVar(&conf.MasterConn, "master-connection", "", "Connection name to use for multisource replication")
bootstrapCmd.Flags().StringVar(&conf.Topology, "topology", "master-slave", "master-slave|master-slave-no-gtid|maxscale-binlog|multi-master|multi-tier-slave|multi-master-ring")
bootstrapCmd.Flags().IntVar(&conf.MasterConnectRetry, "master-connect-retry", 10, "Specifies how many seconds to wait between slave connect retries to master")
}
var bootstrapCmd = &cobra.Command{
Use: "bootstrap",
Short: "Bootstrap a replication environment",
Long: `The bootstrap command is used to create a new replication environment from scratch`,
Run: func(cmd *cobra.Command, args []string) {
currentCluster = new(cluster.Cluster)
currentCluster.Init(confs[cfgGroup], cfgGroup, &tlog, termlength, runUUID, Version, repmgrHostname, nil)
currentCluster.CleanAll = cleanall
switch conf.Topology {
case "master-slave":
currentCluster.SetMultiTierSlave(false)
currentCluster.SetForceSlaveNoGtid(false)
currentCluster.SetMultiMaster(false)
currentCluster.SetBinlogServer(false)
case "master-slave-no-gtid":
currentCluster.SetMultiTierSlave(false)
currentCluster.SetForceSlaveNoGtid(true)
currentCluster.SetMultiMaster(false)
currentCluster.SetBinlogServer(false)
case "multi-master":
currentCluster.SetMultiTierSlave(false)
currentCluster.SetForceSlaveNoGtid(false)
currentCluster.SetMultiMaster(true)
currentCluster.SetBinlogServer(false)
case "multi-tier-slave":
currentCluster.SetMultiTierSlave(true)
currentCluster.SetForceSlaveNoGtid(false)
currentCluster.SetMultiMaster(false)
currentCluster.SetBinlogServer(false)
case "maxscale-binlog":
currentCluster.SetMultiTierSlave(false)
currentCluster.SetForceSlaveNoGtid(false)
currentCluster.SetMultiMaster(false)
currentCluster.SetBinlogServer(true)
case "multi-master-ring":
}
err := currentCluster.Bootstrap()
if err != nil {
log.WithError(err).Error("Error bootstrapping replication")
}
},
}
var provisionCmd = &cobra.Command{
Use: "provision",
Short: "Provision a replica server",
Long: `The provision command is used to create a new replication server
using mysqldump or xtrabackup`,
Run: func(cmd *cobra.Command, args []string) {
/* dbHost, dbPort := misc.SplitHostPort(source)
destHost, destPort := misc.SplitHostPort(destination)
dbUser, dbPass = misc.SplitPair(confs[cfgGroupIndex].User)
hostArg := fmt.Sprintf("--host=%s", dbHost)
portArg := fmt.Sprintf("--port=%s", dbPort)
userArg := fmt.Sprintf("--user=%s", dbUser)
passArg := fmt.Sprintf("--password=%s", dbPass)
desthostArg := fmt.Sprintf("--host=%s", destHost)
destportArg := fmt.Sprintf("--port=%s", destPort)
dumpCmd := exec.Command("/usr/bin/mysqldump", "--opt", "--single-transaction", "--all-databases", hostArg, portArg, userArg, passArg)
clientCmd := exec.Command("/usr/bin/mysql", desthostArg, destportArg, userArg, passArg)
var err error
clientCmd.Stdin, err = dumpCmd.StdoutPipe()
if err != nil {
log.Fatal("Error opening pipe:", err)
}
if err := dumpCmd.Start(); err != nil {
log.Fatal("Error starting dump:", err, dumpCmd.Path, dumpCmd.Args)
}
if err := clientCmd.Run(); err != nil {
log.Fatal("Error starting client:", err, clientCmd.Path, clientCmd.Args)
}*/
},
}