-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
66 lines (57 loc) · 1.54 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
58
59
60
61
62
63
64
65
66
/*
TODO:
* Fix races with a read write lock.
* Check S3 first if backup pre-exists. If it does and was not complete,
auto-resume by reading a "metadata.json" file. Which contains:
- the tidb-snapshot
- min/max/primary key/rows-per-file of tables included in backup.
* Add MySQL compatibility with FTWRL, followed by START TRANSACTION WITH CONSISTENT SNAPSHOT.
* Backup TiDB views (last)
* Keep trx's open for dump (for mysql compat, optimization)
LIMITATIONS:
* Does not backup users. Waiting on TIDB #7733.
* Not efficient at finding Primary Key. Waiting on TiDB #7714.
* Files may not be equal in size (may be fixed in TIDB #7714)
* Server does not expose version in easily parsable format (TIDB #7736)
*/
package main
import (
"flag"
"os"
"time"
"github.com/pingcap/errors"
"go.uber.org/zap"
)
var startTime = time.Now()
func panicError(err error) {
if err != nil {
panic(err)
}
}
func main() {
logCfg := zap.NewDevelopmentConfig()
logInit, err := logCfg.Build()
panicError(err)
log := logInit.Sugar()
cfg := NewConfig()
err = cfg.Parse(os.Args[1:])
switch errors.Cause(err) {
case nil:
case flag.ErrHelp:
os.Exit(0)
default:
log.Error("parse cmd flags err %s\n", err)
os.Exit(2)
}
level := zap.AtomicLevel{}
err = level.UnmarshalText([]byte(cfg.LogLevel))
panicError(err)
logCfg.Level = level
logLeveled, err := logCfg.Build()
zap.ReplaceGlobals(logLeveled)
if d, err := NewDumper(cfg); err == nil {
d.Dump() // start main loop.
}
t := time.Now()
zap.S().Infof("Completed in %s seconds.", t.Sub(startTime))
}