mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 05:33:11 +01:00
fix: ensure restore configuration points to manager wal-restore
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
parent
74d4f5d190
commit
0141ff33ab
@ -4,11 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/cloudnative-pg/barman-cloud/pkg/api"
|
"github.com/cloudnative-pg/barman-cloud/pkg/api"
|
||||||
barmanArchiver "github.com/cloudnative-pg/barman-cloud/pkg/archiver"
|
barmanArchiver "github.com/cloudnative-pg/barman-cloud/pkg/archiver"
|
||||||
barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
|
barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
|
||||||
@ -17,6 +12,7 @@ import (
|
|||||||
barmanCredentials "github.com/cloudnative-pg/barman-cloud/pkg/credentials"
|
barmanCredentials "github.com/cloudnative-pg/barman-cloud/pkg/credentials"
|
||||||
barmanRestorer "github.com/cloudnative-pg/barman-cloud/pkg/restorer"
|
barmanRestorer "github.com/cloudnative-pg/barman-cloud/pkg/restorer"
|
||||||
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
|
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
|
||||||
|
"github.com/cloudnative-pg/cloudnative-pg/pkg/postgres"
|
||||||
"github.com/cloudnative-pg/cloudnative-pg/pkg/utils"
|
"github.com/cloudnative-pg/cloudnative-pg/pkg/utils"
|
||||||
"github.com/cloudnative-pg/cnpg-i-machinery/pkg/pluginhelper/decoder"
|
"github.com/cloudnative-pg/cnpg-i-machinery/pkg/pluginhelper/decoder"
|
||||||
restore "github.com/cloudnative-pg/cnpg-i/pkg/restore/job"
|
restore "github.com/cloudnative-pg/cnpg-i/pkg/restore/job"
|
||||||
@ -25,6 +21,9 @@ import (
|
|||||||
"github.com/cloudnative-pg/machinery/pkg/log"
|
"github.com/cloudnative-pg/machinery/pkg/log"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
||||||
@ -152,10 +151,7 @@ func (impl JobHookImpl) Restore(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := getRestoreWalConfig(ctx, backup, &recoveryObjectStore.Spec.Configuration)
|
config := getRestoreWalConfig()
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
contextLogger.Info("sending restore response", "config", config, "env", env)
|
contextLogger.Info("sending restore response", "config", config, "env", env)
|
||||||
return &restore.RestoreResponse{
|
return &restore.RestoreResponse{
|
||||||
@ -336,33 +332,17 @@ func (impl JobHookImpl) restoreCustomWalDir(ctx context.Context) (bool, error) {
|
|||||||
// getRestoreWalConfig obtains the content to append to `custom.conf` allowing PostgreSQL
|
// getRestoreWalConfig obtains the content to append to `custom.conf` allowing PostgreSQL
|
||||||
// to complete the WAL recovery from the object storage and then start
|
// to complete the WAL recovery from the object storage and then start
|
||||||
// as a new primary
|
// as a new primary
|
||||||
func getRestoreWalConfig(
|
func getRestoreWalConfig() string {
|
||||||
ctx context.Context,
|
restoreCmd := fmt.Sprintf(
|
||||||
backup *cnpgv1.Backup,
|
"/controller/manager wal-restore --log-destination %s/%s.json %%f %%p",
|
||||||
barmanConfiguration *cnpgv1.BarmanObjectStoreConfiguration,
|
postgres.LogPath, postgres.LogFileName)
|
||||||
) (string, error) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
cmd := []string{barmanCapabilities.BarmanCloudWalRestore}
|
|
||||||
if backup.Status.EndpointURL != "" {
|
|
||||||
cmd = append(cmd, "--endpoint-url", backup.Status.EndpointURL)
|
|
||||||
}
|
|
||||||
cmd = append(cmd, backup.Status.DestinationPath)
|
|
||||||
cmd = append(cmd, backup.Status.ServerName)
|
|
||||||
|
|
||||||
cmd, err = barmanCommand.AppendCloudProviderOptionsFromConfiguration(ctx, cmd, barmanConfiguration)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = append(cmd, "%f", "%p")
|
|
||||||
|
|
||||||
recoveryFileContents := fmt.Sprintf(
|
recoveryFileContents := fmt.Sprintf(
|
||||||
"recovery_target_action = promote\n"+
|
"recovery_target_action = promote\n"+
|
||||||
"restore_command = '%s'\n",
|
"restore_command = '%s'\n",
|
||||||
strings.Join(cmd, " "))
|
restoreCmd)
|
||||||
|
|
||||||
return recoveryFileContents, nil
|
return recoveryFileContents
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadBackupObjectFromExternalCluster generates an in-memory Backup structure given a reference to
|
// loadBackupObjectFromExternalCluster generates an in-memory Backup structure given a reference to
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user