This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
backup: add backupts file as lock #151
Closed
Closed
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ package cmd | |||||
|
||||||
import ( | ||||||
"context" | ||||||
"fmt" | ||||||
|
||||||
"github.com/pingcap/errors" | ||||||
"github.com/pingcap/log" | ||||||
|
@@ -108,6 +109,11 @@ func runBackup(flagSet *pflag.FlagSet, cmdName, db, table string) error { | |||||
return err | ||||||
} | ||||||
|
||||||
err = client.SaveBackupTS(ctx, backupTS) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
defer summary.Summary(cmdName) | ||||||
|
||||||
ranges, backupSchemas, err := backup.BuildBackupRangeAndSchema( | ||||||
|
@@ -170,6 +176,12 @@ func runBackup(flagSet *pflag.FlagSet, cmdName, db, table string) error { | |||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
content, err := client.GetBackupTS(ctx) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
fmt.Println(string(content)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return nil | ||||||
} | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"sync" | ||
"time" | ||
|
@@ -120,6 +121,23 @@ func (bc *Client) SetStorage(ctx context.Context, backend *backup.StorageBackend | |
return nil | ||
} | ||
|
||
// SaveBackupTS saves the backup ts at the given path. | ||
func (bc *Client) SaveBackupTS(ctx context.Context, backupTS uint64) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a test. |
||
backendURL := storage.FormatBackendURL(bc.backend) | ||
log.Info("save backup ts", zap.Stringer("path", &backendURL)) | ||
fileString := fmt.Sprintf( | ||
"**************************************"+ | ||
"\nStarted backup at: %v\nBackupTS: %d\n"+ | ||
"**************************************", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be pretty-printed json? |
||
time.Now().Format("2006-01-02 15:04:05"), backupTS) | ||
return bc.storage.Write(ctx, utils.TSFile, []byte(fileString)) | ||
} | ||
|
||
// GetBackupTS get the backup ts from given path. | ||
func (bc *Client) GetBackupTS(ctx context.Context) ([]byte, error) { | ||
return bc.storage.Read(ctx, utils.TSFile) | ||
} | ||
|
||
// SaveBackupMeta saves the current backup meta at the given path. | ||
func (bc *Client) SaveBackupMeta(ctx context.Context) error { | ||
backupMetaData, err := proto.Marshal(&bc.backupMeta) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ import ( | |
const ( | ||
// MetaFile represents file name | ||
MetaFile = "backupmeta" | ||
// TSFile represents backup ts file, it generated before backup | ||
TSFile = "backupts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// MetaJSONFile represents backup meta json file name | ||
MetaJSONFile = "backupmeta.json" | ||
) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we still need to log the backup TS if we write it to a human-readable file.