Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 1 addition & 75 deletions br/cmd/br/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/session"
"github.com/spf13/cobra"
"github.com/tikv/migration/br/pkg/gluetikv"
"github.com/tikv/migration/br/pkg/summary"
Expand All @@ -18,31 +17,6 @@ import (
"sourcegraph.com/sourcegraph/appdash"
)

func runBackupCommand(command *cobra.Command, cmdName string) error {
cfg := task.BackupConfig{Config: task.Config{LogProgress: HasLogFile()}}
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
command.SilenceUsage = false
return errors.Trace(err)
}

ctx := GetDefaultContext()
if cfg.EnableOpenTracing {
var store *appdash.MemoryStore
ctx, store = trace.TracerStartSpan(ctx)
defer trace.TracerFinishSpan(ctx, store)
}
if cfg.IgnoreStats {
// Do not run stat worker in BR.
session.DisableStats4Test()
}

if err := task.RunBackup(ctx, tidbGlue, cmdName, &cfg); err != nil {
log.Error("failed to backup", zap.Error(err))
return errors.Trace(err)
}
return nil
}

func runBackupRawCommand(command *cobra.Command, cmdName string) error {
cfg := task.RawKvConfig{Config: task.Config{LogProgress: HasLogFile()}}
if err := cfg.ParseBackupConfigFromFlags(command.Flags()); err != nil {
Expand All @@ -67,7 +41,7 @@ func runBackupRawCommand(command *cobra.Command, cmdName string) error {
func NewBackupCommand() *cobra.Command {
command := &cobra.Command{
Use: "backup",
Short: "backup a TiDB/TiKV cluster",
Short: "backup a TiKV cluster",
SilenceUsage: true,
PersistentPreRunE: func(c *cobra.Command, args []string) error {
if err := Init(c); err != nil {
Expand All @@ -85,61 +59,13 @@ func NewBackupCommand() *cobra.Command {
},
}
command.AddCommand(
newFullBackupCommand(),
newDBBackupCommand(),
newTableBackupCommand(),
newRawBackupCommand(),
)

task.DefineBackupFlags(command.PersistentFlags())
return command
}

// newFullBackupCommand return a full backup subcommand.
func newFullBackupCommand() *cobra.Command {
command := &cobra.Command{
Use: "full",
Short: "backup all database",
// prevents incorrect usage like `--checksum false` instead of `--checksum=false`.
// the former, according to pflag parsing rules, means `--checksum=true false`.
Args: cobra.NoArgs,
RunE: func(command *cobra.Command, _ []string) error {
// empty db/table means full backup.
return runBackupCommand(command, "Full backup")
},
}
task.DefineFilterFlags(command, acceptAllTables)
return command
}

// newDBBackupCommand return a db backup subcommand.
func newDBBackupCommand() *cobra.Command {
command := &cobra.Command{
Use: "db",
Short: "backup a database",
Args: cobra.NoArgs,
RunE: func(command *cobra.Command, _ []string) error {
return runBackupCommand(command, "Database backup")
},
}
task.DefineDatabaseFlags(command)
return command
}

// newTableBackupCommand return a table backup subcommand.
func newTableBackupCommand() *cobra.Command {
command := &cobra.Command{
Use: "table",
Short: "backup a table",
Args: cobra.NoArgs,
RunE: func(command *cobra.Command, _ []string) error {
return runBackupCommand(command, "Table backup")
},
}
task.DefineTableFlags(command)
return command
}

// newRawBackupCommand return a raw kv range backup subcommand.
func newRawBackupCommand() *cobra.Command {
// TODO: remove experimental tag if it's stable
Expand Down
14 changes: 0 additions & 14 deletions br/cmd/br/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ var (
hasLogFile uint64
tidbGlue = gluetidb.New()
envLogToTermKey = "BR_LOG_TO_TERM"

filterOutSysAndMemTables = []string{
"*.*",
fmt.Sprintf("!%s.*", utils.TemporaryDBName("*")),
"!mysql.*",
"!sys.*",
"!INFORMATION_SCHEMA.*",
"!PERFORMANCE_SCHEMA.*",
"!METRICS_SCHEMA.*",
"!INSPECTION_SCHEMA.*",
}
acceptAllTables = []string{
"*.*",
}
)

const (
Expand Down
62 changes: 0 additions & 62 deletions br/cmd/br/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@ import (
"sourcegraph.com/sourcegraph/appdash"
)

func runRestoreCommand(command *cobra.Command, cmdName string) error {
cfg := task.RestoreConfig{Config: task.Config{LogProgress: HasLogFile()}}
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
command.SilenceUsage = false
return errors.Trace(err)
}

ctx := GetDefaultContext()
if cfg.EnableOpenTracing {
var store *appdash.MemoryStore
ctx, store = trace.TracerStartSpan(ctx)
defer trace.TracerFinishSpan(ctx, store)
}
if err := task.RunRestore(GetDefaultContext(), tidbGlue, cmdName, &cfg); err != nil {
log.Error("failed to restore", zap.Error(err))
return errors.Trace(err)
}
return nil
}

func runRestoreRawCommand(command *cobra.Command, cmdName string) error {
cfg := task.RestoreRawConfig{
RawKvConfig: task.RawKvConfig{Config: task.Config{LogProgress: HasLogFile()}},
Expand Down Expand Up @@ -79,55 +59,13 @@ func NewRestoreCommand() *cobra.Command {
},
}
command.AddCommand(
newFullRestoreCommand(),
newDBRestoreCommand(),
newTableRestoreCommand(),
newRawRestoreCommand(),
)
task.DefineRestoreFlags(command.PersistentFlags())

return command
}

func newFullRestoreCommand() *cobra.Command {
command := &cobra.Command{
Use: "full",
Short: "restore all tables",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runRestoreCommand(cmd, "Full restore")
},
}
task.DefineFilterFlags(command, filterOutSysAndMemTables)
return command
}

func newDBRestoreCommand() *cobra.Command {
command := &cobra.Command{
Use: "db",
Short: "restore tables in a database from the backup data",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runRestoreCommand(cmd, "Database restore")
},
}
task.DefineDatabaseFlags(command)
return command
}

func newTableRestoreCommand() *cobra.Command {
command := &cobra.Command{
Use: "table",
Short: "restore a table from the backup data",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runRestoreCommand(cmd, "Table restore")
},
}
task.DefineTableFlags(command)
return command
}

func newRawRestoreCommand() *cobra.Command {
command := &cobra.Command{
Use: "raw",
Expand Down
Loading