forked from pingcap/br
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (50 loc) · 973 Bytes
/
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 (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/spf13/cobra"
"github.com/pingcap/br/cmd"
)
func main() {
gCtx := context.Background()
ctx, cancel := context.WithCancel(gCtx)
defer cancel()
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
fmt.Printf("\nGot signal [%v] to exit.\n", sig)
switch sig {
case syscall.SIGTERM:
cancel()
os.Exit(0)
default:
cancel()
os.Exit(1)
}
}()
rootCmd := &cobra.Command{
Use: "br",
Short: "br is a TiDB/TiKV cluster backup restore tool.",
TraverseChildren: true,
SilenceUsage: true,
}
cmd.AddFlags(rootCmd)
cmd.SetDefaultContext(ctx)
rootCmd.AddCommand(
cmd.NewValidateCommand(),
cmd.NewBackupCommand(),
cmd.NewRestoreCommand(),
)
rootCmd.SetArgs(os.Args[1:])
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}