Skip to content

Commit

Permalink
Don't create multiple backupers, which can interfere. (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Sep 11, 2024
1 parent 74d950f commit 81b0f20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cmd/internal/database/postgres/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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) {
Expand Down
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 81b0f20

Please sign in to comment.