forked from pingcap/br
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
62 lines (54 loc) · 1.27 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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/pingcap/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
"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)
log.Warn("received signal to exit", zap.Stringer("signal", sig))
cancel()
fmt.Fprintln(os.Stderr, "gracefully shuting down, press ^C again to force exit")
<-sc
// Even user use SIGTERM to exit, there isn't any checkpoint for resuming,
// hence returning fail exit code.
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.NewDebugCommand(),
cmd.NewBackupCommand(),
cmd.NewRestoreCommand(),
)
// Ouputs cmd.Print to stdout.
rootCmd.SetOut(os.Stdout)
rootCmd.SetArgs(os.Args[1:])
if err := rootCmd.Execute(); err != nil {
log.Error("br failed", zap.Error(err))
os.Exit(1)
}
}