Skip to content

Commit

Permalink
Merge master to Release 4.0 (pingcap#206)
Browse files Browse the repository at this point in the history
* restore: merge tidb-tools/pkg/restore-util (pingcap#146)

* restore-util: Implement split/scatter (pingcap#274)

* implement split/scatter

Signed-off-by: 5kbpers <[email protected]>

* init test

Signed-off-by: 5kbpers <[email protected]>

* redesign output/input of the lib

Signed-off-by: 5kbpers <[email protected]>

* update dependency

Signed-off-by: 5kbpers <[email protected]>

* add commments and more tests

Signed-off-by: 5kbpers <[email protected]>

* add ScanRegions interface to Client

Signed-off-by: 5kbpers <[email protected]>

* fix potential data race

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* Apply suggestions from code review

Co-Authored-By: kennytm <[email protected]>

* Update pkg/restore-util/client.go

Co-Authored-By: kennytm <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* update dependency

Signed-off-by: 5kbpers <[email protected]>

* resolve conflicts

Signed-off-by: 5kbpers <[email protected]>

* fix prefix rewrite

Signed-off-by: 5kbpers <[email protected]>

* add RewriteRule/skip failed scatter region/retry the SplitRegion

Signed-off-by: 5kbpers <[email protected]>

* fix test

Signed-off-by: 5kbpers <[email protected]>

* check if region has peer

Signed-off-by: 5kbpers <[email protected]>

* more logs

Signed-off-by: 5kbpers <[email protected]>

* restore-util: add split retry interval (pingcap#277)

* reset dependencies to release-3.1

* add split retry interval

Signed-off-by: 5kbpers <[email protected]>

* fix go.sum

Signed-off-by: 5kbpers <[email protected]>

* restore-util: wait for scatter region sequentially  (pingcap#279)

* wait for scatter region sequentially

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* restore-util: add on split hook (pingcap#281)

* restore-util: add on split hook

Signed-off-by: Neil Shen <[email protected]>

* Nil check onSplit

Co-Authored-By: kennytm <[email protected]>

* restore-util: fix returned new region is nil (pingcap#283)

* restore-util: fix returned new region is nil

Signed-off-by: 5kbpers <[email protected]>

* more logs

Signed-off-by: 5kbpers <[email protected]>

* *: gofmt

Signed-off-by: 5kbpers <[email protected]>

* Apply suggestions from code review

Co-Authored-By: kennytm <[email protected]>

* fix log

Signed-off-by: 5kbpers <[email protected]>

* restore-util: call onSplit on splitByRewriteRules (pingcap#285)

Signed-off-by: Neil Shen <[email protected]>

* restore-util: fix overlapped error message (pingcap#293)

* restore-util: fix overlapped error message

Signed-off-by: 5kbpers <[email protected]>

* fix log message

Signed-off-by: 5kbpers <[email protected]>

* reduce error trace

Signed-off-by: 5kbpers <[email protected]>

* fix test

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* restore-util: log warning when cannot find matched rewrite rule (pingcap#299)

* restore-util: add method to set placement rules and store labels (pingcap#301)

* restore-util: add method to set placement rules and store labels

Signed-off-by: disksing <[email protected]>

* minor fix

Signed-off-by: disksing <[email protected]>

* address comment

Signed-off-by: disksing <[email protected]>

* add GetPlacementRules

Signed-off-by: disksing <[email protected]>

* fix test

Signed-off-by: disksing <[email protected]>

* restore-util: support batch split (pingcap#300)

* restore-util: support batch split

Signed-off-by: 5kbpers <[email protected]>

* go fmt

Signed-off-by: 5kbpers <[email protected]>

* Apply suggestions from code review

Co-Authored-By: kennytm <[email protected]>

* address commits

Signed-off-by: 5kbpers <[email protected]>

* Update pkg/restore-util/split.go

Co-Authored-By: kennytm <[email protected]>

* add onSplit callback

Signed-off-by: 5kbpers <[email protected]>

* fix test

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* restore-util: add upper bound time for waiting for scatter (pingcap#305)

* restore: fix scatter regions failed

Signed-off-by: 5kbpers <[email protected]>

* add log

Signed-off-by: 5kbpers <[email protected]>

* stop waiting for scatter after 3min

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* restore-util: fix wrong url (pingcap#306)

Signed-off-by: disksing <[email protected]>

* restore-util: add warning about unmatched table id (pingcap#313)

* restore-util: support table partition

Signed-off-by: 5kbpers <[email protected]>

* fix log

Signed-off-by: 5kbpers <[email protected]>

* warn table id does not match

Signed-off-by: 5kbpers <[email protected]>

* add unit tests

Signed-off-by: 5kbpers <[email protected]>

* Apply suggestions from code review

Co-Authored-By: Neil Shen <[email protected]>

* fix compile error

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* fix test

Signed-off-by: 5kbpers <[email protected]>

Co-authored-by: Ian <[email protected]>
Co-authored-by: Neil Shen <[email protected]>

* *: prune tidb-tools

Signed-off-by: Neil Shen <[email protected]>

* restore: address linters suggestions

Signed-off-by: Neil Shen <[email protected]>

* restore: merge restoreutil into restore

Signed-off-by: Neil Shen <[email protected]>

* address comment

Signed-off-by: Neil Shen <[email protected]>

Co-authored-by: 5kbpers <[email protected]>
Co-authored-by: kennytm <[email protected]>
Co-authored-by: disksing <[email protected]>
Co-authored-by: Ian <[email protected]>

* Fixed handling for a dbName that do not exist in the backup being restored (pingcap#148)

* Fixed handling for a dbName that do not exist in the backup being restored

* Fixed handling for a dbName that do not exist in the backup being restored

* validate: fix debug meta test ci (pingcap#153)

* validate: fix debug meta test ci

* *: extracts runBackup/runRestore in cmd into pkg/task (pingcap#156)

* *: extracts runBackup/runRestore in cmd into pkg/task

Defines a "Config" structure to store the parsed flags.

Use the "black-white-list" structure to define what tables/databases to
backup/restore.

* go.mod: update tidb to v4.0.0-beta

* restore: fix restore summary log (pingcap#150)

Co-authored-by: kennytm <[email protected]>

* restore: enhance error handling (pingcap#152)

* restore: enhance error handling

Signed-off-by: 5kbpers <[email protected]>

* unit test

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* fix region epoch error

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* remove `Restore*`

Signed-off-by: 5kbpers <[email protected]>

* address lint

Signed-off-by: 5kbpers <[email protected]>

* add debug log

Signed-off-by: 5kbpers <[email protected]>

* Apply suggestions from code review

Co-Authored-By: kennytm <[email protected]>

* Update pkg/restore/import.go

Co-Authored-By: kennytm <[email protected]>

* fix retry error

Signed-off-by: 5kbpers <[email protected]>

* handle RegionNotFound error

Signed-off-by: 5kbpers <[email protected]>

Co-authored-by: Neil Shen <[email protected]>
Co-authored-by: kennytm <[email protected]>

* Incremental BR: support DDL (pingcap#155)

* support backup&restore ddl

Signed-off-by: 5kbpers <[email protected]>

* integration tests

Signed-off-by: 5kbpers <[email protected]>

* update kvproto

Signed-off-by: 5kbpers <[email protected]>

* fix integration tests

Signed-off-by: 5kbpers <[email protected]>

* reduce cyclomatic complexity of `runRestore`

Signed-off-by: 5kbpers <[email protected]>

* fix test

Signed-off-by: 5kbpers <[email protected]>

* add unit test

Signed-off-by: 5kbpers <[email protected]>

* fix tests

Signed-off-by: 5kbpers <[email protected]>

* disable fast checksum in incremental br

Signed-off-by: 5kbpers <[email protected]>

* fix no valid key error

Signed-off-by: 5kbpers <[email protected]>

* address lint

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* Reduce TiDB dependencies (pingcap#158)

* utils: exclude mock_cluster outside of unit test

* utils: remove unused ResultSetToStringSlice()

* *: abstract away dependencies of tidb/session into a Glue interface

* *: fix hound lint

* util,mock: move utils.MockCluster to mock.Cluster

* restore: fix test build failure

Co-authored-by: 3pointer <[email protected]>

* go.mod: update tidb (pingcap#168)

Signed-off-by: Neil Shen <[email protected]>

* BR support TLS (pingcap#161)

* *: support tls

* move tikv.driver to glue

* fix comments

* upgrade golangci and prepare for go 1.14 (pingcap#171)

Signed-off-by: Neil Shen <[email protected]>

* backup: add raw backup command (pingcap#101)

* backup: add raw backup command

* restore: speed up retry on not leader (pingcap#179)

* tests: stable cluster start up

Signed-off-by: Neil Shen <[email protected]>

* tests: fix unbound var

Signed-off-by: Neil Shen <[email protected]>

* restore: speed retry on not leader

Signed-off-by: Neil Shen <[email protected]>

* address comments

Signed-off-by: Neil Shen <[email protected]>

* tests: add --cacert flag

Signed-off-by: Neil Shen <[email protected]>

* make codecov green

Signed-off-by: Neil Shen <[email protected]>

* address comments

Signed-off-by: Neil Shen <[email protected]>

* conn, restore: paginate scan regions (pingcap#165)

* conn, restore: paginate scan regions

Signed-off-by: Neil Shen <[email protected]>

* tests: large timeout

Signed-off-by: Neil Shen <[email protected]>

* Batch restore (pingcap#167)

* *: unify Range and RangeTree

Signed-off-by: Neil Shen <[email protected]>

* restore: split restore files into small batch

Signed-off-by: Neil Shen <[email protected]>

* task: set default restore concurrency to 128

Signed-off-by: Neil Shen <[email protected]>

* restore: unused table worker pool

Signed-off-by: Neil Shen <[email protected]>

* summary: sum up repeated duration and int

Signed-off-by: Neil Shen <[email protected]>

* rtree: move rtree from utils to pkg

Signed-off-by: Neil Shen <[email protected]>

* README, docker: add quick start (pingcap#181)

* README, docker: add quick start

Signed-off-by: Neil Shen <[email protected]>

* cmd: disable some TiDB log

Signed-off-by: Neil Shen <[email protected]>

* docker: build go-ycsb automatically

Signed-off-by: Neil Shen <[email protected]>

* cmd: add TODO about TiDB logs

Signed-off-by: Neil Shen <[email protected]>

* *: update tidb dependency build with go1.14 (pingcap#176)

* *: add license header (pingcap#182)

* rtree: move checkFile into backup

Signed-off-by: Neil Shen <[email protected]>

* *: add license header

Signed-off-by: Neil Shen <[email protected]>

* Update LICENSE.md

Co-Authored-By: kennytm <[email protected]>

Co-authored-by: kennytm <[email protected]>
Co-authored-by: 3pointer <[email protected]>

* conn: support not shutting down the storage when closing the connection (pingcap#185)

Co-authored-by: 3pointer <[email protected]>

* conn: use GetDomain to avoid some TiDB breaking changes (pingcap#186)

* conn: use GetDomain to avoid some TiDB breaking changes

Signed-off-by: Neil Shen <[email protected]>

* minor usability improvement

Signed-off-by: Neil Shen <[email protected]>

Co-authored-by: kennytm <[email protected]>

* fix check safepoint & unhide experimental features (pingcap#175)

* backup: check safepoint for last backup ts

Signed-off-by: 5kbpers <[email protected]>

* check lastbackupts > 0

Signed-off-by: 5kbpers <[email protected]>

* unhide experimental features

Signed-off-by: 5kbpers <[email protected]>

* address comment

Signed-off-by: 5kbpers <[email protected]>

* Update tests/br_z_gc_safepoint/run.sh

Co-Authored-By: kennytm <[email protected]>

Co-authored-by: kennytm <[email protected]>

* support backupts (pingcap#172)

* support backupts

* address comment

* address comment

* fix space

* *: update pd deps to v4 (pingcap#184)

Co-authored-by: 3pointer <[email protected]>

* restore: support online restore (pingcap#114)

Signed-off-by: disksing <[email protected]>

* metrics: add grafana scripts (pingcap#140)

* add grafana scripts

* fix

Co-authored-by: 3pointer <[email protected]>
Co-authored-by: glorv <[email protected]>
Co-authored-by: kennytm <[email protected]>

* filter out all TiFlash nodes when retrieving lists of stores from PD (pingcap#187)

* conn: ignore nodes with label engine=tiflash

* conn: disallow TiFlash on restore, only skip TiFlash on backup

* Create integration test for S3 storage (pingcap#174)

* Fix summary log (pingcap#191)

* *: fix restore summary log after restore logic changed to files

* fix

* fix

* fix

Co-authored-by: kennytm <[email protected]>

* Implement Raw Restore (pingcap#104)

* Update kvproto

* Implement raw restore

* fix build

* Set range for file importer

Signed-off-by: MyonKeminta <[email protected]>

* Remove unnecessary comments

Signed-off-by: MyonKeminta <[email protected]>

* check cf and support multi ranges in BackupMeta

Signed-off-by: MyonKeminta <[email protected]>

* Check files' cf; address comments

* adjust structure to keep consistent with master

* Fix build

Signed-off-by: MyonKeminta <[email protected]>

* Fix build and make check, avoid accessing TiDB in rawkv mode

* Fix test

Signed-off-by: MyonKeminta <[email protected]>

* Fix tests

Signed-off-by: MyonKeminta <[email protected]>

* Fix broken logic after merging master

* Update pkg/task/restore_raw.go

Co-Authored-By: Neil Shen <[email protected]>

* Address comments

* Address comments

* Mark raw restore as experimental

* Fix build

* Address comments

* test: Add check for deleting data and partial backup

* Fix build

* Add license header

* fix ci

* fix ci

Co-authored-by: MyonKeminta <[email protected]>
Co-authored-by: 3pointer <[email protected]>
Co-authored-by: Neil Shen <[email protected]>
Co-authored-by: pingcap-github-bot <[email protected]>

* restore: remove tiflash replica before restore (pingcap#194)

* restore: remove tiflash replica before restore

Signed-off-by: 5kbpers <[email protected]>

* rename errSplit variable

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* check replica count by region info

Signed-off-by: 5kbpers <[email protected]>

* cleanup

Signed-off-by: 5kbpers <[email protected]>

* save tiflash replica count to backupmeta

Signed-off-by: 5kbpers <[email protected]>

* fix save crcxor

Signed-off-by: 5kbpers <[email protected]>

* fix decode the key of placement rule

Signed-off-by: 5kbpers <[email protected]>

* address lint

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* close domain after restoring tiflash-replica

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* address comments

Signed-off-by: 5kbpers <[email protected]>

* Update pkg/task/restore.go

Co-Authored-By: 3pointer <[email protected]>

Co-authored-by: 3pointer <[email protected]>

* summary: put summary log at last (pingcap#197)

* summary: put summary log at last

* fix switch sql

* *: abstract the progress channel (updateCh) into the glue package (pingcap#196)

* *: abstract the progress channel (updateCh) into the glue package

* restore: fix crash in truncateTS() when the bound is unlimited

* task: fix comment

Co-authored-by: Ian <[email protected]>

* *: refline logs (pingcap#189)

* tests: disable TLS test (pingcap#204)

Signed-off-by: Neil Shen <[email protected]>

* *: add S3 quick start and few enhancement of log (pingcap#202)

* README, docker: add quick start about S3 storage

Signed-off-by: Neil Shen <[email protected]>

* pkg/summary: make sure to output correct summary

Signed-off-by: Neil Shen <[email protected]>

* cmd, tests: log to terminal if BR_LOG_TO_TERM is set

Signed-off-by: Neil Shen <[email protected]>

* Update pkg/task/common.go

Co-Authored-By: kennytm <[email protected]>

* address comments

Signed-off-by: Neil Shen <[email protected]>

* address comments

Signed-off-by: Neil Shen <[email protected]>

* tests: cat log if br fails

Signed-off-by: Neil Shen <[email protected]>

Co-authored-by: kennytm <[email protected]>

* restore: add error field to `DownloadResponse` (pingcap#195)

* restore: add error field to `DownloadResponse`

Signed-off-by: 5kbpers <[email protected]>

* restore: populate restore cancel error (pingcap#207)

Signed-off-by: Neil Shen <[email protected]>

Co-authored-by: kennytm <[email protected]>

* enhance usability of br (pingcap#208)

* silenceUsage only when parse cmd flags failed

* udpate tidb

Co-authored-by: kennytm <[email protected]>

* task: do not run checksum if restore failed (pingcap#209)

* fix incremental bug in llroad test (pingcap#199)

* restore: filter same table ddl

* *: do not return error when backup/restore data is empty

* fix create database double during incremental restore

* add tests

* fix ci

* address comment

* add skip create sqls (pingcap#211)

* Revert "tests: disable TLS test (pingcap#204)" (pingcap#218)

This reverts commit e168a60.

* doc: add `minio` to dependence list. (pingcap#221)

The README of test omitted `minio` in the dependence list, which is needed for run the integration test.

Co-authored-by: Neil Shen <[email protected]>

* move waiting reject stores in import file (pingcap#222)

* move wait rejectstores into import files

* restore: use new table id to search placementRules

* Update pkg/restore/import.go

Co-Authored-By: Neil Shen <[email protected]>

* Update pkg/restore/import.go

Co-Authored-By: kennytm <[email protected]>

* fix ci

Co-authored-by: Neil Shen <[email protected]>
Co-authored-by: kennytm <[email protected]>

* Max index length (pingcap#220)

* restore: set max-index-length to max

* restore:add max-index-length params

* address comment

* address comment

* glue: create schema/table directly with info (pingcap#216)

* glue: create schema/table directly with info

* go.mod: change to use the master version

* gluetidb: fix failure to create schema

* gluetidb: exclude non-public indices when restoring

* go.mod: removed unused replace

Co-authored-by: 3pointer <[email protected]>

Co-authored-by: Neil Shen <[email protected]>
Co-authored-by: 5kbpers <[email protected]>
Co-authored-by: kennytm <[email protected]>
Co-authored-by: disksing <[email protected]>
Co-authored-by: Ian <[email protected]>
Co-authored-by: Kolbe Kegel <[email protected]>
Co-authored-by: WangXiangUSTC <[email protected]>
Co-authored-by: glorv <[email protected]>
Co-authored-by: MyonKeminta <[email protected]>
Co-authored-by: MyonKeminta <[email protected]>
Co-authored-by: pingcap-github-bot <[email protected]>
Co-authored-by: 庄天翼 <[email protected]>
Co-authored-by: 山岚 <[email protected]>
  • Loading branch information
14 people authored Apr 2, 2020
1 parent 3239e7d commit 194a4ff
Show file tree
Hide file tree
Showing 46 changed files with 836 additions and 331 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ go-ycsb load mysql -p workload=core \
mysql -uroot -htidb -P4000 -E -e "SELECT COUNT(*) FROM test.usertable"

# Build BR and backup!
make release && \
make build && \
bin/br backup full --pd pd0:2379 --storage "local:///data/backup/full" \
--log-file "/logs/br_backup.log"

Expand All @@ -69,6 +69,20 @@ bin/br restore full --pd pd0:2379 --storage "local:///data/backup/full" \

# How many rows do we get again? Expected to be 100000 rows.
mysql -uroot -htidb -P4000 -E -e "SELECT COUNT(*) FROM test.usertable"

# Test S3 compatible storage (MinIO).
# Create a bucket to save backup by mc (a MinIO Client).
mc config host add minio $S3_ENDPOINT $MINIO_ACCESS_KEY $MINIO_SECRET_KEY && \
mc mb minio/mybucket

# Backup to S3 compatible storage.
bin/br backup full --pd pd0:2379 --storage "s3://mybucket/full" \
--s3.endpoint="$S3_ENDPOINT"

# Drop database and restore!
mysql -uroot -htidb -P4000 -E -e "DROP DATABASE test; SHOW DATABASES;" && \
bin/br restore full --pd pd0:2379 --storage "s3://mybucket/full" \
--s3.endpoint="$S3_ENDPOINT"
```

## Contributing
Expand Down
4 changes: 3 additions & 1 deletion cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
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 err
}
return task.RunBackup(GetDefaultContext(), tidbGlue, cmdName, &cfg)
Expand All @@ -24,6 +25,7 @@ func runBackupCommand(command *cobra.Command, cmdName string) error {
func runBackupRawCommand(command *cobra.Command, cmdName string) error {
cfg := task.RawKvConfig{Config: task.Config{LogProgress: HasLogFile()}}
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
command.SilenceUsage = false
return err
}
return task.RunBackupRaw(GetDefaultContext(), gluetikv.Glue{}, cmdName, &cfg)
Expand All @@ -34,7 +36,7 @@ func NewBackupCommand() *cobra.Command {
command := &cobra.Command{
Use: "backup",
Short: "backup a TiDB/TiKV cluster",
SilenceUsage: false,
SilenceUsage: true,
PersistentPreRunE: func(c *cobra.Command, args []string) error {
if err := Init(c); err != nil {
return err
Expand Down
28 changes: 22 additions & 6 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"context"
"net/http"
"net/http/pprof"
"os"
"path/filepath"
"sync"
"sync/atomic"
"time"

"github.com/pingcap/log"
"github.com/pingcap/tidb/util/logutil"
Expand All @@ -16,15 +19,17 @@ import (
"go.uber.org/zap"

"github.com/pingcap/br/pkg/gluetidb"
"github.com/pingcap/br/pkg/summary"
"github.com/pingcap/br/pkg/task"
"github.com/pingcap/br/pkg/utils"
)

var (
initOnce = sync.Once{}
defaultContext context.Context
hasLogFile uint64
tidbGlue = gluetidb.Glue{}
initOnce = sync.Once{}
defaultContext context.Context
hasLogFile uint64
tidbGlue = gluetidb.Glue{}
envLogToTermKey = "BR_LOG_TO_TERM"
)

const (
Expand All @@ -41,6 +46,10 @@ const (
flagVersionShort = "V"
)

func timestampLogFileName() string {
return filepath.Join(os.TempDir(), "br.log."+time.Now().Format(time.RFC3339))
}

// AddFlags adds flags to the given cmd.
func AddFlags(cmd *cobra.Command) {
cmd.Version = utils.BRInfo()
Expand All @@ -49,8 +58,8 @@ func AddFlags(cmd *cobra.Command) {

cmd.PersistentFlags().StringP(FlagLogLevel, "L", "info",
"Set the log level")
cmd.PersistentFlags().String(FlagLogFile, "",
"Set the log file path. If not set, logs will output to stdout")
cmd.PersistentFlags().String(FlagLogFile, timestampLogFileName(),
"Set the log file path. If not set, logs will output to temp file")
cmd.PersistentFlags().String(FlagStatusAddr, "",
"Set the HTTP listening address for the status report service. Set to empty string to disable")
task.DefineCommonFlags(cmd.PersistentFlags())
Expand All @@ -73,8 +82,15 @@ func Init(cmd *cobra.Command) (err error) {
if err != nil {
return
}
_, outputLogToTerm := os.LookupEnv(envLogToTermKey)
if outputLogToTerm {
// Log to term if env `BR_LOG_TO_TERM` is set.
conf.File.Filename = ""
}
if len(conf.File.Filename) != 0 {
atomic.StoreUint64(&hasLogFile, 1)
summary.InitCollector(true)
cmd.Printf("Detial BR log in %s\n", conf.File.Filename)
}
lg, p, e := log.InitLogger(conf)
if e != nil {
Expand Down
5 changes: 4 additions & 1 deletion cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
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 err
}
return task.RunRestore(GetDefaultContext(), tidbGlue, cmdName, &cfg)
Expand All @@ -25,6 +26,7 @@ func runRestoreRawCommand(command *cobra.Command, cmdName string) error {
RawKvConfig: task.RawKvConfig{Config: task.Config{LogProgress: HasLogFile()}},
}
if err := cfg.ParseFromFlags(command.Flags()); err != nil {
command.SilenceUsage = false
return err
}
return task.RunRestoreRaw(GetDefaultContext(), gluetikv.Glue{}, cmdName, &cfg)
Expand All @@ -33,6 +35,7 @@ func runRestoreRawCommand(command *cobra.Command, cmdName string) error {
func runRestoreTiflashReplicaCommand(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 err
}

Expand All @@ -44,7 +47,7 @@ func NewRestoreCommand() *cobra.Command {
command := &cobra.Command{
Use: "restore",
Short: "restore a TiDB/TiKV cluster",
SilenceUsage: false,
SilenceUsage: true,
PersistentPreRunE: func(c *cobra.Command, args []string) error {
if err := Init(c); err != nil {
return err
Expand Down
26 changes: 24 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Source: tidb-docker-compose/templates/docker-compose.yml
version: '2.1'
version: '3.2'

services:
control:
Expand All @@ -10,11 +10,13 @@ services:
dockerfile: ./docker/Dockerfile
volumes:
- ./docker/data:/data
- ./docker/logs:/logs
- ./docker/logs:/tmp
command: -c "/usr/bin/tail -f /dev/null"
depends_on:
- "tidb"
restart: on-failure
env_file:
- ./docker/minio.env

pd0:
image: pingcap/pd:latest
Expand Down Expand Up @@ -64,6 +66,8 @@ services:
# soft: 1000000
# hard: 1000000
restart: on-failure
env_file:
- ./docker/minio.env

tikv1:
image: pingcap/tikv:latest
Expand All @@ -87,6 +91,8 @@ services:
# soft: 1000000
# hard: 1000000
restart: on-failure
env_file:
- ./docker/minio.env

tikv2:
image: pingcap/tikv:latest
Expand All @@ -110,6 +116,8 @@ services:
# soft: 1000000
# hard: 1000000
restart: on-failure
env_file:
- ./docker/minio.env

tikv3:
image: pingcap/tikv:latest
Expand All @@ -133,6 +141,8 @@ services:
# soft: 1000000
# hard: 1000000
restart: on-failure
env_file:
- ./docker/minio.env

tikv4:
image: pingcap/tikv:latest
Expand All @@ -156,6 +166,8 @@ services:
# soft: 1000000
# hard: 1000000
restart: on-failure
env_file:
- ./docker/minio.env

tidb:
image: pingcap/tidb:latest
Expand Down Expand Up @@ -185,6 +197,16 @@ services:
# hard: 1000000
restart: on-failure

minio:
image: minio/minio
ports:
- 24927:24927
volumes:
- ./docker/data/s3:/data/s3
command: server --address=:24927 /data/s3
env_file:
- ./docker/minio.env

tidb-vision:
image: pingcap/tidb-vision:latest
environment:
Expand Down
9 changes: 6 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM golang:1.13.8-buster as builder

# For loading data to TiDB
FROM golang:1.13.8-buster as go-ycsb-builder
WORKDIR /go/src/github.com/pingcap/
RUN git clone https://github.com/pingcap/go-ycsb.git && \
cd go-ycsb && \
make

# For operating minio S3 compatible storage
FROM minio/mc as mc-builder

FROM golang:1.13.8-buster

RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -19,6 +21,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
WORKDIR /go/src/github.com/pingcap/br
COPY . .

COPY --from=builder /go/src/github.com/pingcap/go-ycsb/bin/go-ycsb /go/bin/go-ycsb
COPY --from=go-ycsb-builder /go/src/github.com/pingcap/go-ycsb/bin/go-ycsb /go/bin/go-ycsb
COPY --from=mc-builder /usr/bin/mc /usr/bin/mc

ENTRYPOINT ["/bin/bash"]
6 changes: 6 additions & 0 deletions docker/minio.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MINIO_ACCESS_KEY=brs3accesskey
MINIO_SECRET_KEY=brs3secretkey
MINIO_BROWSER=off
AWS_ACCESS_KEY_ID=brs3accesskey
AWS_SECRET_ACCESS_KEY=brs3secretkey
S3_ENDPOINT=http://minio:24927
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ require (
github.com/onsi/gomega v1.8.1 // indirect
github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011
github.com/pingcap/kvproto v0.0.0-20200317112120-78042b285b75
github.com/pingcap/kvproto v0.0.0-20200330093347-98f910b71904
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd
github.com/pingcap/parser v0.0.0-20200305120128-bde9faa0df84
github.com/pingcap/parser v0.0.0-20200326020624-68d423641be5
github.com/pingcap/pd/v4 v4.0.0-beta.1.0.20200305072537-61d9f9cc35d3
github.com/pingcap/tidb v1.1.0-beta.0.20200310133602-7c39e5e5e0bc
github.com/pingcap/tidb v0.0.0-20200401141416-959eca8f3a39
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible
github.com/pingcap/tipb v0.0.0-20200212061130-c4d518eb1d60
github.com/prometheus/client_golang v1.0.0
Expand All @@ -37,7 +37,7 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
go.etcd.io/etcd v0.5.0-alpha.5.0.20191023171146-3cf2f69b5738
go.opencensus.io v0.22.2 // indirect
go.uber.org/zap v1.14.0
go.uber.org/zap v1.14.1
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
google.golang.org/api v0.14.0
google.golang.org/grpc v1.25.1
Expand Down
23 changes: 11 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -363,25 +363,23 @@ github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17Xtb
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
github.com/pingcap/kvproto v0.0.0-20200214064158-62d31900d88e/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/kvproto v0.0.0-20200221034943-a2aa1d1e20a8/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/kvproto v0.0.0-20200228095611-2cf9a243b8d5 h1:knEvP4R5v5b2T107/Q6VzB0C8/6T7NXB/V7Vl1FtQsg=
github.com/pingcap/kvproto v0.0.0-20200228095611-2cf9a243b8d5/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/kvproto v0.0.0-20200317112120-78042b285b75 h1:DB3NTM0ilba/6sW+vccdEnP10bVvrVunDwWvRa0hSKc=
github.com/pingcap/kvproto v0.0.0-20200317112120-78042b285b75/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/kvproto v0.0.0-20200330093347-98f910b71904 h1:pMFUXvhJ62hX8m0Q4RsL7L+hSW1mAMG26So5eFMoAtI=
github.com/pingcap/kvproto v0.0.0-20200330093347-98f910b71904/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 h1:AJD9pZYm72vMgPcQDww9rkZ1DnWfl0pXV3BOWlkYIjA=
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd h1:CV3VsP3Z02MVtdpTMfEgRJ4T9NGgGTxdHpJerent7rM=
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/parser v0.0.0-20200305120128-bde9faa0df84 h1:u5FOwUw9muF8mBTZVV1dQhoAKiEo2Ci54CxN9XchEEY=
github.com/pingcap/parser v0.0.0-20200305120128-bde9faa0df84/go.mod h1:9v0Edh8IbgjGYW2ArJr19E+bvL8zKahsFp+ixWeId+4=
github.com/pingcap/parser v0.0.0-20200326020624-68d423641be5 h1:fXVqoeYfV+xI8K2he5NNv00c6YksrjeM6+vkNo1ZK2Q=
github.com/pingcap/parser v0.0.0-20200326020624-68d423641be5/go.mod h1:9v0Edh8IbgjGYW2ArJr19E+bvL8zKahsFp+ixWeId+4=
github.com/pingcap/pd/v4 v4.0.0-beta.1.0.20200305072537-61d9f9cc35d3 h1:Yrp99FnjHAEuDrSBql2l0IqCtJX7KwJbTsD5hIArkvk=
github.com/pingcap/pd/v4 v4.0.0-beta.1.0.20200305072537-61d9f9cc35d3/go.mod h1:25GfNw6+Jcr9kca5rtmTb4gKCJ4jOpow2zV2S9Dgafs=
github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20200302022240-21c8c70d0ab1 h1:YUnUZ914SHFMsOSe/xgH5DKK/thtRma8X8hcszRo3CA=
github.com/pingcap/sysutil v0.0.0-20200302022240-21c8c70d0ab1/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20200309085538-962fd285f3bb h1:bDbgLaNTRNK6Qw7KjvEqqfCQstY8WMEcXyXTU7yzYKg=
github.com/pingcap/sysutil v0.0.0-20200309085538-962fd285f3bb/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/tidb v1.1.0-beta.0.20200310133602-7c39e5e5e0bc h1:1aW3qTRJZjnosvXt1b75KL73b28XRJWBx6jtTtHsybg=
github.com/pingcap/tidb v1.1.0-beta.0.20200310133602-7c39e5e5e0bc/go.mod h1:WTmfs5zrUGMPw3Enn5FI3buzkU8BDuJ6BhsO/JC239U=
github.com/pingcap/tidb v0.0.0-20200401141416-959eca8f3a39 h1:nYRL69Qc4kuvp+tlDNB5wXjvDetX0J7g0DsW4RQxfXM=
github.com/pingcap/tidb v0.0.0-20200401141416-959eca8f3a39/go.mod h1:btnHsqUQvJnY18+OP2Z6MCRq1tX4B8JUCrmqctSKxOg=
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible h1:84F7MFMfdAYObrznvRslmVu43aoihrlL+7mMyMlOi0o=
github.com/pingcap/tidb-tools v4.0.0-beta.1.0.20200306084441-875bd09aa3d5+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330/go.mod h1:RtkHW8WbcNxj8lsbzjaILci01CtYnYbIkQhjyZWrWVI=
Expand Down Expand Up @@ -501,6 +499,7 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yookoala/realpath v1.0.0 h1:7OA9pj4FZd+oZDsyvXWQvjn5oBdcHRTV44PpdMSuImQ=
github.com/yookoala/realpath v1.0.0/go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
Expand Down Expand Up @@ -535,8 +534,8 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.12.0 h1:dySoUQPFBGj6xwjmBzageVL8jGi8uxc6bEmJQjA06bw=
go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.14.0 h1:/pduUoebOeeJzTDFuoMgC6nRkiasr1sBCIEorly7m4o=
go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.14.1 h1:nYDKopTbvAPq/NrUVZwT15y2lpROBiLLyoRTbXOYWOo=
go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -676,8 +675,8 @@ golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200301222351-066e0c02454c h1:FD7jysxM+EJqg5UYYy3XYDsAiUickFsn4UiaanJkf8c=
golang.org/x/tools v0.0.0-20200301222351-066e0c02454c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb h1:iKlO7ROJc6SttHKlxzwGytRtBUqX4VARrNTgP2YLX5M=
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
golang.org/x/tools v0.0.0-20200325203130-f53864d0dba1 h1:odiryKYJy7CjdrZxhrcE1Z8L9+kGyGZOnfpuauvdCeU=
golang.org/x/tools v0.0.0-20200325203130-f53864d0dba1/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
Use: "br",
Short: "br is a TiDB/TiKV cluster backup restore tool.",
TraverseChildren: true,
SilenceUsage: false,
SilenceUsage: true,
}
cmd.AddFlags(rootCmd)
cmd.SetDefaultContext(ctx)
Expand Down
Loading

0 comments on commit 194a4ff

Please sign in to comment.