Skip to content

Pgbackrest check and pgcontroldata #104

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

Merged
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
17 changes: 17 additions & 0 deletions internal/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ func (exec Executor) pgBackRestInfo(output, repoNum string) (string, string, err
return stdout.String(), stderr.String(), err
}

// bashCommand defines a one-line bash command to exec in a container
func (exec Executor) bashCommand(command string) (string, string, error) {
var stdout, stderr bytes.Buffer
err := exec(nil, &stdout, &stderr, "bash", "-ceu", "--", command)
return stdout.String(), stderr.String(), err
}

// pgBackRestCheck defines a pgBackRest check command
// Force log-level-console=detail to override if set elsewhere
func (exec Executor) pgBackRestCheck() (string, string, error) {
var stdout, stderr bytes.Buffer
command := "pgbackrest check --log-level-console=detail"
err := exec(nil, &stdout, &stderr, "bash", "-ceu", "--", command)

return stdout.String(), stderr.String(), err
}

// postgresqlListLogFiles returns the full path of numLogs log files.
func (exec Executor) listPGLogFiles(numLogs int) (string, string, error) {
var stdout, stderr bytes.Buffer
Expand Down
54 changes: 54 additions & 0 deletions internal/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,45 @@ func gatherPostgresLogsAndConfigs(ctx context.Context,
}
}

// We will execute several bash commands in the DB container
// text is command to execute and desc is a short description
type Command struct {
path string
description string
}

commands := []Command{
{path: "pg_controldata", description: "pg_controldata"},
}

var buf bytes.Buffer

for _, command := range commands {
stdout, stderr, err := Executor(exec).bashCommand(command.path)
if err != nil {
if apierrors.IsForbidden(err) {
writeInfo(cmd, err.Error())
return nil
}
writeDebug(cmd, fmt.Sprintf("Error executing %s\n", command.path))
writeDebug(cmd, fmt.Sprintf("%s\n", err.Error()))
writeDebug(cmd, "This is acceptable in some configurations.\n")
continue
}
buf.Write([]byte(fmt.Sprintf("%s\n", command.description)))
buf.Write([]byte(stdout))
if stderr != "" {
buf.Write([]byte(stderr))
}
buf.Write([]byte("\n\n"))
}

// Write the buffer to a file
path := clusterName + fmt.Sprintf("/pods/%s/%s", pod.Name, "postgres-info")
if err := writeTar(tw, buf.Bytes(), path, cmd); err != nil {
return err
}

}
return nil
}
Expand Down Expand Up @@ -1518,6 +1557,21 @@ func gatherPgBackRestInfo(ctx context.Context,
buf.Write([]byte(stderr))
}

buf.Write([]byte("pgbackrest check\n"))
stdout, stderr, err = Executor(exec).pgBackRestCheck()
if err != nil {
if apierrors.IsForbidden(err) {
writeInfo(cmd, err.Error())
return nil
}
return err
}

buf.Write([]byte(stdout))
if stderr != "" {
buf.Write([]byte(stderr))
}

path := clusterName + "/pgbackrest-info"
return writeTar(tw, buf.Bytes(), path, cmd)
}
Expand Down