Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtbackup: Make initial backup idempotent again. #5147

Merged
merged 1 commit into from
Aug 30, 2019
Merged
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
15 changes: 8 additions & 7 deletions go/cmd/vtbackup/vtbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,21 @@ func parseBackupTime(name string) (time.Time, error) {
}

func shouldBackup(ctx context.Context, topoServer *topo.Server, backupStorage backupstorage.BackupStorage, backupDir string) (bool, error) {
// Look for the most recent, complete backup.
backups, err := backupStorage.ListBackups(ctx, backupDir)
if err != nil {
return false, fmt.Errorf("can't list backups: %v", err)
}
lastBackup := lastCompleteBackup(ctx, backups)

// Check preconditions for initial_backup mode.
if *initialBackup {
// Check if any backups for the shard already exist in this backup storage location.
if lastBackup != nil {
log.Infof("At least one complete backup already exists, so there's no need to seed an empty backup. Doing nothing.")
return false, nil
}

// Check whether the shard exists.
_, shardErr := topoServer.GetShard(ctx, *initKeyspace, *initShard)
switch {
Expand Down Expand Up @@ -505,11 +513,6 @@ func shouldBackup(ctx context.Context, topoServer *topo.Server, backupStorage ba
return false, fmt.Errorf("failed to check whether shard %v/%v exists before doing initial backup: %v", *initKeyspace, *initShard, err)
}

// Check if any backups for the shard exist in this backup storage location.
if len(backups) > 0 {
log.Infof("At least one backup already exists, so there's no need to seed an empty backup. Doing nothing.")
return false, nil
}
log.Infof("Shard %v/%v has no existing backups. Creating initial backup.", *initKeyspace, *initShard)
return true, nil
}
Expand All @@ -518,8 +521,6 @@ func shouldBackup(ctx context.Context, topoServer *topo.Server, backupStorage ba
if len(backups) == 0 && !*allowFirstBackup {
return false, fmt.Errorf("no existing backups to restore from; backup is not possible since -initial_backup flag was not enabled")
}
// Look for the most recent, complete backup.
lastBackup := lastCompleteBackup(ctx, backups)
if lastBackup == nil {
if *allowFirstBackup {
// There's no complete backup, but we were told to take one from scratch anyway.
Expand Down