Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create multiple backupers, which can interfere. #96

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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