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

feat: implementation of the Backup service #7

Merged
merged 10 commits into from
Feb 15, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: add executor getters
Signed-off-by: Armando Ruocco <[email protected]>
armru committed Feb 13, 2024
commit fe53d7ddd0257b27112e2cafa8f159eae6d4160e
4 changes: 2 additions & 2 deletions internal/backup/backup.go
Original file line number Diff line number Diff line change
@@ -83,8 +83,8 @@ func (Implementation) Backup(
BackupName: backupInfo.BackupName,
StartedAt: startedAt.Unix(),
StoppedAt: time.Now().Unix(),
BeginWal: exec.BeginWal,
EndWal: exec.EndWal,
BeginWal: exec.GetBeginWal(),
EndWal: exec.GetEndWal(),
BeginLsn: string(backupInfo.BeginLSN),
EndLsn: string(backupInfo.EndLSN),
BackupLabelFile: backupInfo.LabelFile,
31 changes: 26 additions & 5 deletions internal/backup/executor/executor.go
Original file line number Diff line number Diff line change
@@ -32,14 +32,31 @@ var backupModeBackoff = wait.Backoff{
type Executor struct {
backupClient webserver.BackupClient

// TODO: these should be a getter that return an error if empty
BeginWal string
EndWal string
beginWal string
endWal string

cluster *apiv1.Cluster
backup *apiv1.Backup
repository *Repository
backupClientEndpoint string

executed bool
}

// GetBeginWal returns the beginWal value, panics if the executor was not executed
func (executor *Executor) GetBeginWal() string {
if !executor.executed {
panic("beginWal: please run take backup before trying to access this value")
}
return executor.beginWal
}

// GetEndWal returns the endWal value, panics if the executor was not executed
func (executor *Executor) GetEndWal() string {
if !executor.executed {
panic("endWal: please run take backup before trying to access this value")
}
return executor.endWal
}

// tablespace represent a tablespace location
@@ -69,6 +86,10 @@ func NewLocalExecutor(cluster *apiv1.Cluster, backup *apiv1.Backup, repo *Reposi

// TakeBackup executes a backup. Returns the result and any error encountered
func (executor *Executor) TakeBackup(ctx context.Context) (*webserver.BackupResultData, error) {
defer func() {
executor.executed = true
}()

contextLogger := logging.FromContext(ctx)
contextLogger.Info("Preparing physical backup")
if err := executor.setBackupMode(ctx); err != nil {
@@ -89,7 +110,7 @@ func (executor *Executor) setBackupMode(ctx context.Context) error {
logger := logging.FromContext(ctx)

var currentWALErr error
executor.BeginWal, currentWALErr = executor.getCurrentWALFile(ctx)
executor.beginWal, currentWALErr = executor.getCurrentWALFile(ctx)
if currentWALErr != nil {
return currentWALErr
}
@@ -226,7 +247,7 @@ func (executor *Executor) unsetBackupMode(ctx context.Context) (*webserver.Backu
logger.Info("PostgreSQL Backup mode stopped")

var err error
executor.EndWal, err = executor.getCurrentWALFile(ctx)
executor.endWal, err = executor.getCurrentWALFile(ctx)
if err != nil {
return nil, err
}