From 6dd158f62ff004d02e454e6199d3c2d12b891472 Mon Sep 17 00:00:00 2001 From: luancheng Date: Wed, 5 Feb 2020 21:38:36 +0800 Subject: [PATCH] fix ci --- go.mod | 1 + go.sum | 3 +++ pkg/backup/client.go | 25 ++++++++++++++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 9951c2922..a0169a4c0 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/pingcap/tidb v1.1.0-beta.0.20191213040028-9009da737834 github.com/pingcap/tipb v0.0.0-20191209145133-44f75c9bef33 github.com/prometheus/client_golang v1.0.0 + github.com/prometheus/common v0.4.1 github.com/sirupsen/logrus v1.4.2 github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.3 diff --git a/go.sum b/go.sum index 085e00355..56c7af7ef 100644 --- a/go.sum +++ b/go.sum @@ -24,7 +24,9 @@ github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUW github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/aws/aws-sdk-go v1.26.1 h1:JGQggXhOiNJIqsmbYUl3cYtJZUffeOWlHtxfzGK7WPI= @@ -567,6 +569,7 @@ google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/gometalinter.v2 v2.0.12/go.mod h1:NDRytsqEZyolNuAgTzJkZMkSQM7FIKyzVzGhjB/qfYo= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/backup/client.go b/pkg/backup/client.go index 799e93977..9fc0e5316 100644 --- a/pkg/backup/client.go +++ b/pkg/backup/client.go @@ -4,7 +4,6 @@ import ( "context" "encoding/hex" "encoding/json" - "fmt" "io" "sync" "time" @@ -123,14 +122,26 @@ func (bc *Client) SetStorage(ctx context.Context, backend *backup.StorageBackend // SaveBackupTS saves the backup ts at the given path. func (bc *Client) SaveBackupTS(ctx context.Context, backupTS uint64) error { + if exists, _ := bc.storage.FileExists(ctx, utils.TSFile); exists { + return errors.New("this storage has backup file, consider clear this storage or change to new one") + } backendURL := storage.FormatBackendURL(bc.backend) + log.Info("save backup ts", zap.Stringer("path", &backendURL)) - fileString := fmt.Sprintf( - "**************************************"+ - "\nStarted backup at: %v\nBackupTS: %d\n"+ - "**************************************", - time.Now().Format("2006-01-02 15:04:05"), backupTS) - return bc.storage.Write(ctx, utils.TSFile, []byte(fileString)) + type fileContent struct { + StartedAt string `json:"started_at"` + BackupTS uint64 `json:"backup_ts"` + } + f := &fileContent{ + StartedAt: time.Now().Format("2006-01-02 15:04:05"), + BackupTS: backupTS, + } + fileBytes, err := json.MarshalIndent(f, "", "\t") + if err != nil { + return err + } + + return bc.storage.Write(ctx, utils.TSFile, fileBytes) } // GetBackupTS get the backup ts from given path.