diff --git a/cmd/internal/database/postgres/upgrade.go b/cmd/internal/database/postgres/upgrade.go index 19a268f..3160eeb 100644 --- a/cmd/internal/database/postgres/upgrade.go +++ b/cmd/internal/database/postgres/upgrade.go @@ -138,7 +138,7 @@ func (db *Postgres) Upgrade(ctx context.Context) error { cmd.Stderr = os.Stderr cmd.Env = os.Environ() cmd.SysProcAttr = &syscall.SysProcAttr{ - Credential: &syscall.Credential{Uid: uint32(uid)}, + Credential: &syscall.Credential{Uid: uint32(uid)}, //nolint:gosec } err = cmd.Run() if err != nil { @@ -203,7 +203,7 @@ func (db *Postgres) Upgrade(ctx context.Context) error { cmd.Stderr = os.Stderr cmd.Env = os.Environ() cmd.SysProcAttr = &syscall.SysProcAttr{ - Credential: &syscall.Credential{Uid: uint32(uid)}, + Credential: &syscall.Credential{Uid: uint32(uid)}, //nolint:gosec } cmd.Dir = pgUser.HomeDir @@ -253,7 +253,7 @@ func (db *Postgres) getBinaryVersion(ctx context.Context, pgConfigCmd string) (i return 0, fmt.Errorf("unable to parse postgres binary version in %q: %w", binaryVersionString, err) } - return int(v.Major()), nil + return int(v.Major()), nil //nolint:gosec } func (db *Postgres) getDatabaseVersion(pgVersionFile string) (int, error) { diff --git a/cmd/internal/initializer/initializer.go b/cmd/internal/initializer/initializer.go index a24f3ea..135645d 100644 --- a/cmd/internal/initializer/initializer.go +++ b/cmd/internal/initializer/initializer.go @@ -53,7 +53,7 @@ func New(log *slog.Logger, addr string, db database.Database, bp providers.Backu } // Start starts the initializer, which includes a server component and the initializer itself, which is potentially restoring a backup -func (i *Initializer) Start(ctx context.Context) error { +func (i *Initializer) Start(ctx context.Context, backuper *backup.Backuper) error { opts := []grpc.ServerOption{ grpc.StreamInterceptor(grpc_middleware.ChainStreamServer( grpc_ctxtags.StreamServerInterceptor(), @@ -72,14 +72,6 @@ func (i *Initializer) Start(ctx context.Context) error { initializerService := newInitializerService(i.currentStatus) backupService := newBackupProviderService(i.bp, i.Restore) databaseService := newDatabaseService(func() error { - backuper := backup.New(&backup.BackuperConfig{ - Log: i.log, - DatabaseProber: i.db, - BackupProvider: i.bp, - Metrics: i.metrics, - Compressor: i.comp, - }) - return backuper.CreateBackup(ctx) }) diff --git a/cmd/main.go b/cmd/main.go index 1f3c6f4..25c2df8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -150,14 +150,6 @@ var startCmd = &cobra.Command{ metrics := metrics.New() metrics.Start(logger.WithGroup("metrics")) - if err := initializer.New(logger.WithGroup("initializer"), addr, db, bp, comp, metrics, viper.GetString(databaseDatadirFlg)).Start(stop); err != nil { - return err - } - - if err := probe.Start(stop, logger.WithGroup("probe"), db); err != nil { - return err - } - backuper := backup.New(&backup.BackuperConfig{ Log: logger.WithGroup("backup"), BackupSchedule: viper.GetString(backupCronScheduleFlg), @@ -167,6 +159,14 @@ var startCmd = &cobra.Command{ Compressor: comp, }) + if err := initializer.New(logger.WithGroup("initializer"), addr, db, bp, comp, metrics, viper.GetString(databaseDatadirFlg)).Start(stop, backuper); err != nil { + return err + } + + if err := probe.Start(stop, logger.WithGroup("probe"), db); err != nil { + return err + } + return backuper.Start(stop) }, }