-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (48 loc) · 1.31 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
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
)
var username = flag.String("username", "root", "MySQL username.")
var password = flag.String("password", "", "MySQL password.")
var host = flag.String("host", "127.0.0.1", "MySQL host.")
var port = flag.Int("port", 3306, "MySQL port.")
var socket = flag.String("socket", "", "MySQL socket file.")
var database = flag.String("database", "", "MySQL database which will be dumped.")
var verbose = flag.Bool("verbose", false, "Show detail log")
var exportDir = flag.String("export-dir", "/tmp/", "Export directory which will hold exported file.")
var mysqldump = flag.Bool("use-mysqldump", false, "Use mysqldump command to export tables.")
func checkParameter() {
if *database == "" {
fmt.Fprintf(os.Stderr, "Usage: %s [options]\n", os.Args[0])
fmt.Fprint(os.Stderr, "Options:\n")
flag.PrintDefaults()
os.Exit(1)
}
}
func init() {
flag.Parse()
checkParameter()
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
fmt.Println("Go MySQL Dumpper")
dbReader := &DatabaseReader{
host: *host,
port: *port,
socket: *socket,
database: *database,
username: *username,
password: *password}
dbReader.init()
dbReader.getTables()
dbReader.db.Close()
}
func handleError(err error, msg string) {
if err != nil {
log.Fatalf(msg+": %v", err)
}
}