Skip to content

Commit

Permalink
Don't create multiple backupers, which can interfere.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Sep 11, 2024
1 parent 74d950f commit f23aaff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
10 changes: 1 addition & 9 deletions cmd/internal/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)
})

Expand Down
16 changes: 8 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
},
}
Expand Down

0 comments on commit f23aaff

Please sign in to comment.