From f23aaffa09e2dfbc146f27ac2a133bba85c28bca Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 11 Sep 2024 11:22:19 +0200 Subject: [PATCH] Don't create multiple backupers, which can interfere. --- cmd/internal/initializer/initializer.go | 10 +--------- cmd/main.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 17 deletions(-) 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) }, }