From 832a1f9d9aa3bf09e3e6af3599d9363cd04cb94d Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Sat, 11 Oct 2025 19:35:20 +0200 Subject: [PATCH] Lay out control flow for spawning container --- cmd/backup/command.go | 36 ++++++++++++++++++++++++++++-------- cmd/backup/config.go | 3 ++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/cmd/backup/command.go b/cmd/backup/command.go index 10fa0e1..46d8b40 100644 --- a/cmd/backup/command.go +++ b/cmd/backup/command.go @@ -36,8 +36,15 @@ func (c *command) runAsCommand() error { } for _, config := range configurations { - if err := runScript(config); err != nil { - return errwrap.Wrap(err, "error running script") + switch config.ExecutionMode { + case "process": + if err := runScript(config); err != nil { + return errwrap.Wrap(err, "error running script") + } + case "container": + panic("execution mode container not implemented") + default: + return errwrap.Wrap(nil, fmt.Sprintf("unknown execution mode %s", config.ExecutionMode)) } } @@ -110,16 +117,29 @@ func (c *command) schedule(strategy configStrategy) error { ), ) - if err := runScript(config); err != nil { + switch config.ExecutionMode { + case "process": + if err := runScript(config); err != nil { + c.logger.Error( + fmt.Sprintf( + "Unexpected error running schedule %s: %v", + config.BackupCronExpression, + errwrap.Unwrap(err), + ), + "error", + err, + ) + } + case "container": + panic("execution mode container not implemented") + default: c.logger.Error( fmt.Sprintf( - "Unexpected error running schedule %s: %v", - config.BackupCronExpression, - errwrap.Unwrap(err), + "Unkown execution mode %s, please check your configuration", + config.ExecutionMode, ), - "error", - err, ) + return } }) diff --git a/cmd/backup/config.go b/cmd/backup/config.go index 08232a8..35605a8 100644 --- a/cmd/backup/config.go +++ b/cmd/backup/config.go @@ -30,7 +30,6 @@ type Config struct { AwsIamRoleEndpoint string `split_words:"true"` AwsPartSize int64 `split_words:"true"` BackupCompression CompressionType `split_words:"true" default:"gz"` - GzipParallelism WholeNumber `split_words:"true" default:"1"` BackupSources string `split_words:"true" default:"/backup"` BackupFilename string `split_words:"true" default:"backup-%Y-%m-%dT%H-%M-%S.{{ .Extension }}"` BackupFilenameExpand bool `split_words:"true"` @@ -46,6 +45,7 @@ type Config struct { BackupFromSnapshot bool `split_words:"true"` BackupExcludeRegexp RegexpDecoder `split_words:"true"` BackupSkipBackendsFromPrune []string `split_words:"true"` + GzipParallelism WholeNumber `split_words:"true" default:"1"` GpgPassphrase string `split_words:"true"` GpgPublicKeyRing string `split_words:"true"` AgePassphrase string `split_words:"true"` @@ -73,6 +73,7 @@ type Config struct { ExecLabel string `split_words:"true"` ExecForwardOutput bool `split_words:"true"` LockTimeout time.Duration `split_words:"true" default:"60m"` + ExecutionMode string `split_words:"true" default:"process"` AzureStorageAccountName string `split_words:"true"` AzureStoragePrimaryAccountKey string `split_words:"true"` AzureStorageConnectionString string `split_words:"true"`