Skip to content

Commit

Permalink
Refactor restic restore (#5262)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavannd1 authored and Ilya Kislenko committed Mar 23, 2019
1 parent e68377e commit 8d3ef41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/function/restore_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (*restoreDataFunc) Exec(ctx context.Context, tp param.TemplateParams, args
return nil, err
}
// Generate restore command
cmd := restic.RestoreCommand(tp.Profile, backupArtifactPrefix, backupIdentifier, restorePath, encryptionKey)
cmd := restic.RestoreCommandByTag(tp.Profile, backupArtifactPrefix, backupIdentifier, restorePath, encryptionKey)
if len(vols) == 0 {
// Fetch Volumes
vols, err = fetchPodVolumes(pod, tp)
Expand Down
15 changes: 11 additions & 4 deletions pkg/restic/restic.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ func BackupCommand(profile *param.Profile, repository, id, includePath, encrypti
return shCommand(command)
}

// RestoreCommand returns restic restore command
func RestoreCommand(profile *param.Profile, repository, id, restorePath, encryptionKey string) []string {
// RestoreCommandByID returns restic restore command with snapshotID as the identifier
func RestoreCommandByID(profile *param.Profile, repository, id, restorePath, encryptionKey string) []string {
cmd := resticArgs(profile, repository, encryptionKey)
cmd = append(cmd, "restore")
cmd = append(cmd, "restore", id, "--target", restorePath)
command := strings.Join(cmd, " ")
return shCommand(command)
}

// RestoreCommandByTag returns restic restore command with tag as the identifier
func RestoreCommandByTag(profile *param.Profile, repository, tag, restorePath, encryptionKey string) []string {
cmd := resticArgs(profile, repository, encryptionKey)
cmd = append(cmd, "restore", "--tag", tag, "latest", "--target", restorePath)
command := strings.Join(cmd, " ")
command = fmt.Sprintf("%s --tag %s latest --target %s", command, id, restorePath)
return shCommand(command)
}

Expand Down

0 comments on commit 8d3ef41

Please sign in to comment.