Skip to content

Commit

Permalink
pb-4844: Addressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: kgarg-px <[email protected]>
  • Loading branch information
kgarg-px committed Nov 28, 2023
1 parent 0d4b003 commit df6762d
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 102 deletions.
25 changes: 16 additions & 9 deletions pkg/executor/kopia/kopiabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
bkpNamespace string
compression string
excludeFileList string
logLevel string
logLevelDebug string
)

var (
Expand Down Expand Up @@ -70,7 +70,7 @@ func newBackupCommand() *cobra.Command {
backupCommand.Flags().StringVar(&sourcePathGlob, "source-path-glob", "", "The regexp should match only one path that will be used for backup")
backupCommand.Flags().StringVar(&compression, "compression", "", "Compression type to be used")
backupCommand.Flags().StringVar(&excludeFileList, "exclude-file-list", "", " list of dir names that need to be exclude in the kopia snapshot")
backupCommand.Flags().StringVar(&logLevel, "log-level", "", "If debug mode in kopia is to be used")
backupCommand.Flags().StringVar(&logLevelDebug, "log-level", "", "If debug mode in kopia is to be used")

return backupCommand
}
Expand Down Expand Up @@ -237,6 +237,7 @@ func runKopiaCreateRepo(repository *executor.Repository) error {
kopiaProviderType[repository.Type],
repository.S3Config.Region,
repository.S3Config.DisableSSL,
logLevelDebug,
)
default:
repoCreateCmd, err = kopia.GetCreateCommand(
Expand All @@ -246,6 +247,7 @@ func runKopiaCreateRepo(repository *executor.Repository) error {
kopiaProviderType[repository.Type],
"",
false,
logLevelDebug,
)
}
if err != nil {
Expand All @@ -263,7 +265,7 @@ func runKopiaCreateRepo(repository *executor.Repository) error {
}

initExecutor := kopia.NewCreateExecutor(repoCreateCmd)
if err := initExecutor.Run(logLevel); err != nil {
if err := initExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run repository create command: %v", err)
return err
}
Expand Down Expand Up @@ -321,6 +323,7 @@ func runKopiaBackup(repository *executor.Repository, sourcePath string) error {
repository.Password,
string(repository.Type),
sourcePath,
logLevelDebug,
)
if err != nil {
return err
Expand All @@ -329,7 +332,7 @@ func runKopiaBackup(repository *executor.Repository, sourcePath string) error {
// the pod got terminated. Now user triggers another backup, so we need to pass
// credentials for "snapshot create".
backupExecutor := kopia.NewBackupExecutor(backupCmd)
if err := backupExecutor.Run(logLevel); err != nil {
if err := backupExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run backup command: %v", err)
return err
}
Expand Down Expand Up @@ -374,6 +377,7 @@ func runKopiaRepositoryConnect(repository *executor.Repository) error {
kopiaProviderType[repository.Type],
repository.S3Config.Region,
repository.S3Config.DisableSSL,
logLevelDebug,
)
default:
connectCmd, err = kopia.GetConnectCommand(
Expand All @@ -383,6 +387,7 @@ func runKopiaRepositoryConnect(repository *executor.Repository) error {
kopiaProviderType[repository.Type],
"",
false,
logLevelDebug,
)
}
if err != nil {
Expand All @@ -398,7 +403,7 @@ func runKopiaRepositoryConnect(repository *executor.Repository) error {
connectCmd = populateAzureccessDetails(connectCmd, repository)
}
connectExecutor := kopia.NewConnectExecutor(connectCmd)
if err := connectExecutor.Run(logLevel); err != nil {
if err := connectExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run repository connect command: %v", err)
return err
}
Expand Down Expand Up @@ -428,15 +433,15 @@ func runKopiaRepositoryConnect(repository *executor.Repository) error {

func setGlobalPolicy() error {
logrus.Infof("Setting global policy")
policyCmd, err := kopia.SetGlobalPolicyCommand()
policyCmd, err := kopia.SetGlobalPolicyCommand(logLevelDebug)
if err != nil {
return err
}
// As we don't want kopia maintenance to kick in and trigger global policy on default values
// for the repository, setting them to very high values
policyCmd = addPolicySetting(policyCmd)
policyExecutor := kopia.NewSetGlobalPolicyExecutor(policyCmd)
if err := policyExecutor.Run(logLevel); err != nil {
if err := policyExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("failed to run setting global policy command: %v", err)
logrus.Errorf("%v", errMsg)
return fmt.Errorf(errMsg)
Expand Down Expand Up @@ -481,12 +486,13 @@ func runKopiaExcludeFileList(repository *executor.Repository, sourcePath string)
excludeFileListCmd, err := kopia.GetExcludeFileListCommand(
sourcePath,
excludeFileList,
logLevelDebug,
)
if err != nil {
return err
}
excludeFileListExecutor := kopia.NewExcludeFileListExecutor(excludeFileListCmd)
if err := excludeFileListExecutor.Run(logLevel); err != nil {
if err := excludeFileListExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run exclude file list command: %v", err)
return err
}
Expand Down Expand Up @@ -527,12 +533,13 @@ func runKopiaCompression(repository *executor.Repository, sourcePath string) err
compressionCmd, err := kopia.GetCompressionCommand(
sourcePath,
compression,
logLevelDebug,
)
if err != nil {
return err
}
compressionExecutor := kopia.NewCompressionExecutor(compressionCmd)
if err := compressionExecutor.Run(logLevel); err != nil {
if err := compressionExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run compression command: %v", err)
return err
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/executor/kopia/kopiadelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func newDeleteCommand() *cobra.Command {
credSecretNamespace string
volumeBackupDeleteName string
volumeBackupDeleteNamespace string
logLevel string
logLevelDebug string
)
deleteCommand := &cobra.Command{
Use: "delete",
Expand All @@ -35,7 +35,7 @@ func newDeleteCommand() *cobra.Command {
deleteCommand.Flags().StringVar(&credSecretNamespace, "cred-secret-namespace", "", "cred secret namespace for kopia backup snapshot that need to be deleted")
deleteCommand.Flags().StringVar(&volumeBackupDeleteName, "volume-backup-delete-name", "", "volumeBackupdelete CR name for kopia backup snapshot that need to be deleted")
deleteCommand.Flags().StringVar(&volumeBackupDeleteNamespace, "volume-backup-delete-namespace", "", "volumeBackupdelete CR namespace for kopia backup snapshot that need to be deleted")
deleteCommand.Flags().StringVar(&logLevel, "log-level", "", "If debug mode in kopia is to be used")
deleteCommand.Flags().StringVar(&logLevelDebug, "log-level", "", "If debug mode in kopia is to be used")
return deleteCommand
}

Expand Down Expand Up @@ -129,14 +129,15 @@ func runKopiaDelete(repository *executor.Repository, snapshotID string) error {
logrus.Infof("kopia delete started")
deleteCmd, err := kopia.GetDeleteCommand(
snapshotID,
logLevelDebug,
)
if err != nil {
errMsg := fmt.Sprintf("getting delete backup snapshot command for snapshot ID [%v] failed: %v", snapshotID, err)
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
}
initExecutor := kopia.NewDeleteExecutor(deleteCmd)
if err := initExecutor.Run(logLevel); err != nil {
if err := initExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("running delete backup snapshot command for snapshotID [%v] failed: %v", snapshotID, err)
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
Expand Down Expand Up @@ -164,14 +165,14 @@ func runKopiaSnapshotList(repository *executor.Repository) ([]string, error) {
var err error
var listCmd *kopia.Command
logrus.Infof("Executing kopia snapshot list command")
listCmd, err = kopia.GetListCommand()
listCmd, err = kopia.GetListCommand(logLevelDebug)

if err != nil {
return nil, err
}

listExecutor := kopia.NewListExecutor(listCmd)
if err := listExecutor.Run(logLevel); err != nil {
if err := listExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run snapshot list command: %v", err)
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/executor/kopia/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newMaintenanceCommand() *cobra.Command {
credSecretName string
credSecretNamespace string
maintenanceType string
logLevel string
logLevelDebug string
)
maintenanceCommand := &cobra.Command{
Use: "maintenance",
Expand All @@ -52,7 +52,7 @@ func newMaintenanceCommand() *cobra.Command {
maintenanceCommand.Flags().StringVar(&maintenanceStatusName, "maintenance-status-name", "", "backuplocation maintenance status CR name, where repo maintenance status will be stored")
maintenanceCommand.Flags().StringVar(&maintenanceStatusNamespace, "maintenance-status-namespace", "", "backuplocation maintenance status CR namespace, where repo maintenance status will be stored")
maintenanceCommand.Flags().StringVar(&maintenanceType, "maintenance-type", "", "full - will run full maintenance and quick - will run quick maintenance")
maintenanceCommand.Flags().StringVar(&logLevel, "log-level", "", "If debug mode in kopia is to be used")
maintenanceCommand.Flags().StringVar(&logLevelDebug, "log-level", "", "If debug mode in kopia is to be used")
return maintenanceCommand
}

Expand Down Expand Up @@ -276,15 +276,15 @@ func getBackupPathWithRepoName(repoName string) string {
}
func runKopiaQuickMaintenanceExecute(repository *executor.Repository) error {
fn := "runKopiaQuickMaintenanceExecute:"
maintenanceRunCmd, err := kopia.GetMaintenanceRunCommand()
maintenanceRunCmd, err := kopia.GetMaintenanceRunCommand(logLevelDebug)
if err != nil {
errMsg := fmt.Sprintf("getting maintenance run command for [%v] failed: %v", repository.Name, err)
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
}

initExecutor := kopia.NewMaintenanceRunExecutor(maintenanceRunCmd)
if err := initExecutor.Run(logLevel); err != nil {
if err := initExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("running maintenance run command for [%v] failed: %v", repository.Name, err)
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
Expand All @@ -308,14 +308,14 @@ func runKopiaQuickMaintenanceExecute(repository *executor.Repository) error {

func runKopiaMaintenanceExecute(repository *executor.Repository) error {
fn := "runKopiaMaintenanceRun:"
maintenanceRunCmd, err := kopia.GetMaintenanceRunCommand()
maintenanceRunCmd, err := kopia.GetMaintenanceRunCommand(logLevelDebug)
if err != nil {
errMsg := fmt.Sprintf("getting maintenance run command for [%v] failed: %v", repository.Name, err)
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
}
initExecutor := kopia.NewMaintenanceRunExecutor(maintenanceRunCmd)
if err := initExecutor.Run(logLevel); err != nil {
if err := initExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("running maintenance run command for [%v] failed: %v", repository.Name, err)
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
Expand All @@ -339,14 +339,14 @@ func runKopiaMaintenanceExecute(repository *executor.Repository) error {

func runKopiaMaintenanceSet(repository *executor.Repository) error {
fn := "runKopiaMaintenanceSet:"
maintenanceSetCmd, err := kopia.GetMaintenanceSetCommand()
maintenanceSetCmd, err := kopia.GetMaintenanceSetCommand(logLevelDebug)
if err != nil {
errMsg := fmt.Sprintf("getting maintenance set command for failed: %v", err)
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
}
initExecutor := kopia.NewMaintenanceSetExecutor(maintenanceSetCmd)
if err := initExecutor.Run(logLevel); err != nil {
if err := initExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("running maintenance set command for failed: %v", err)
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
Expand Down
11 changes: 6 additions & 5 deletions pkg/executor/kopia/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var (

func newRestoreCommand() *cobra.Command {
var (
targetPath string
snapshotID string
logLevel string
targetPath string
snapshotID string
logLevelDebug string
)
restoreCommand := &cobra.Command{
Use: "restore",
Expand All @@ -41,7 +41,7 @@ func newRestoreCommand() *cobra.Command {
restoreCommand.Flags().StringVar(&targetPath, "target-path", "", "Destination path for kopia restore")
restoreCommand.Flags().StringVar(&snapshotID, "snapshot-id", "", "Snapshot id of the restore")
restoreCommand.Flags().StringVar(&appRestoreCR, "app-restore-cr", "", "ApplicationRestore CR name")
restoreCommand.Flags().StringVar(&logLevel, "log-level", "", "If debug mode in kopia is to be used")
restoreCommand.Flags().StringVar(&logLevelDebug, "log-level", "", "If debug mode in kopia is to be used")

return restoreCommand
}
Expand Down Expand Up @@ -105,13 +105,14 @@ func runKopiaRestore(repository *executor.Repository, targetPath, snapshotID str
string(repository.Type),
targetPath,
snapshotID,
logLevelDebug,
)
if err != nil {
return err
}

initExecutor := kopia.NewRestoreExecutor(restoreCmd)
if err := initExecutor.Run(logLevel); err != nil {
if err := initExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run restore command: %v", err)
return err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/kopia/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type backupExecutor struct {
}

// GetBackupCommand returns a wrapper over the kopia backup command
func GetBackupCommand(path, repoName, password, provider, sourcePath string) (*Command, error) {
func GetBackupCommand(path, repoName, password, provider, sourcePath string, logLevelDebug string) (*Command, error) {
if repoName == "" {
return nil, fmt.Errorf("repository name cannot be empty")
}
Expand All @@ -88,6 +88,7 @@ func GetBackupCommand(path, repoName, password, provider, sourcePath string) (*C
Dir: sourcePath,
Provider: provider,
Args: []string{"."},
LoglevelDebug: logLevelDebug,
}, nil
}

Expand All @@ -101,8 +102,8 @@ func NewBackupExecutor(cmd *Command) Executor {
}
}

func (b *backupExecutor) Run(debugMode string) error {
b.execCmd = b.cmd.BackupCmd(debugMode)
func (b *backupExecutor) Run() error {
b.execCmd = b.cmd.BackupCmd()
b.execCmd.Stdout = b.outBuf
b.execCmd.Stderr = b.errBuf

Expand Down
Loading

0 comments on commit df6762d

Please sign in to comment.