Repository: cloudnative-pg/cloudnative-pg

Issue:
[Chore]: Drop support for Barman legacy backup (<= 3.4)
### Is there an existing issue already for this bug?

- [X] I have searched for an existing issue, and could not find anything. I believe this is a new bug.

### I have read the troubleshooting guide

- [X] I have read the troubleshooting guide and I think this is a new bug.

### I am running a supported version of CloudNativePG

- [X] I have read the troubleshooting guide and I think this is a new bug.

### Contact Details

_No response_

### Version

1.22.1

### What version of Kubernetes are you using?

1.28

### What is your Kubernetes environment?

Self-managed: kind (evaluation)

### How did you install the operator?

YAML manifest

### What happened?

We still supporting Barman <= 3.4 which is not ideal since those are really old versions and we shouldn't support this anymore.
Supporting old versions require more tests and Barman <= 3.4 is not even in our latest images because we updated all the images, even PostgreSQL 11 until November 2023, meaning that even the latest version of that image with the latest security patches contains a newer version of Barman

### Cluster resource

_No response_

### Relevant log output

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Discussion:
@gbartolini: Let's get rid of all that logic.@phisco: Less is more! ✂️

Solution patch:
diff --git a/config/crd/bases/postgresql.cnpg.io_clusters.yaml b/config/crd/bases/postgresql.cnpg.io_clusters.yaml
index 4e27dd29..38de43f0 100644
--- a/config/crd/bases/postgresql.cnpg.io_clusters.yaml
+++ b/config/crd/bases/postgresql.cnpg.io_clusters.yaml
@@ -1152,14 +1152,11 @@ spec:
                             description: |-
                               Compress a backup file (a tar file per tablespace) while streaming it
                               to the object store. Available options are empty string (no
-                              compression, default), `gzip`, `bzip2`, `lz4`, `snappy`, `xz`, and `zstd`.
+                              compression, default), `gzip`, `bzip2`, and `snappy`.
                             enum:
                             - bzip2
                             - gzip
-                            - lz4
                             - snappy
-                            - xz
-                            - zstd
                             type: string
                           encryption:
                             description: |-
@@ -2661,14 +2658,11 @@ spec:
                               description: |-
                                 Compress a backup file (a tar file per tablespace) while streaming it
                                 to the object store. Available options are empty string (no
-                                compression, default), `gzip`, `bzip2`, `lz4`, `snappy`, `xz`, and `zstd`.
+                                compression, default), `gzip`, `bzip2`, and `snappy`.
                               enum:
                               - bzip2
                               - gzip
-                              - lz4
                               - snappy
-                              - xz
-                              - zstd
                               type: string
                             encryption:
                               description: |-
diff --git a/go.mod b/go.mod
index dd710e3a..3a7aff37 100644
--- a/go.mod
+++ b/go.mod
@@ -8,9 +8,9 @@ require (
 	github.com/avast/retry-go/v4 v4.6.1
 	github.com/blang/semver v3.5.1+incompatible
 	github.com/cheynewallace/tabby v1.1.1
-	github.com/cloudnative-pg/barman-cloud v0.3.0
+	github.com/cloudnative-pg/barman-cloud v0.3.1
 	github.com/cloudnative-pg/cnpg-i v0.1.1-0.20250321093050-de4ab51537cb
-	github.com/cloudnative-pg/machinery v0.1.0
+	github.com/cloudnative-pg/machinery v0.2.0
 	github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
 	github.com/evanphx/json-patch/v5 v5.9.11
 	github.com/go-logr/logr v1.4.2
diff --git a/go.sum b/go.sum
index cb017ef1..b37382fc 100644
--- a/go.sum
+++ b/go.sum
@@ -18,12 +18,12 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
 github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 github.com/cheynewallace/tabby v1.1.1 h1:JvUR8waht4Y0S3JF17G6Vhyt+FRhnqVCkk8l4YrOU54=
 github.com/cheynewallace/tabby v1.1.1/go.mod h1:Pba/6cUL8uYqvOc9RkyvFbHGrQ9wShyrn6/S/1OYVys=
-github.com/cloudnative-pg/barman-cloud v0.3.0 h1:tCtIF7nsHDH5X7nAXXd7VqNKKNGHrycXAyyKKKpdGS4=
-github.com/cloudnative-pg/barman-cloud v0.3.0/go.mod h1:8m6W117343zT28ctcskUYEu/dy+MX3hUUW4DynH8MLI=
+github.com/cloudnative-pg/barman-cloud v0.3.1 h1:kzkY77k2lN/caoyh7ibXDSZjJeSJTNvnVt6Gfa8Iq5M=
+github.com/cloudnative-pg/barman-cloud v0.3.1/go.mod h1:4HL3AjY9oEl2Ed0HSkyvTZEQPhwyFOaAnuCz9lfVeYQ=
 github.com/cloudnative-pg/cnpg-i v0.1.1-0.20250321093050-de4ab51537cb h1:FPORwCxjZwlnKnF7dOkuOAz0GBSQ3Hrn+8lm4uMiWeM=
 github.com/cloudnative-pg/cnpg-i v0.1.1-0.20250321093050-de4ab51537cb/go.mod h1:n+kbHm3rzRCY5IJKuE1tGMbG6JaeYz8yycYoLt7BeKo=
-github.com/cloudnative-pg/machinery v0.1.0 h1:tjRmsqQmsO/OlaT0uFmkEtVqgr+SGPM88cKZOHYKLBo=
-github.com/cloudnative-pg/machinery v0.1.0/go.mod h1:0V3vm44FaIsY+x4pm8ORry7xCC3AJiO+ebfPNxeP5Ck=
+github.com/cloudnative-pg/machinery v0.2.0 h1:x8OAwxdeL/6wkbxqorz+nX6UovTyx7/TBeCfiRebR2o=
+github.com/cloudnative-pg/machinery v0.2.0/go.mod h1:Kg8W8Tb/1UFGGtw3hR8S5SytSWddlHaCnJSgBo4x/nc=
 github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
 github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
 github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
diff --git a/pkg/management/postgres/backup.go b/pkg/management/postgres/backup.go
index 80b6cace..46648c4a 100644
--- a/pkg/management/postgres/backup.go
+++ b/pkg/management/postgres/backup.go
@@ -28,7 +28,6 @@ import (
 	"time"
 
 	barmanBackup "github.com/cloudnative-pg/barman-cloud/pkg/backup"
-	barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
 	barmanCatalog "github.com/cloudnative-pg/barman-cloud/pkg/catalog"
 	barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command"
 	barmanCredentials "github.com/cloudnative-pg/barman-cloud/pkg/credentials"
@@ -68,7 +67,6 @@ type BackupCommand struct {
 	Env          []string
 	Log          log.Logger
 	Instance     *Instance
-	Capabilities *barmanCapabilities.Capabilities
 	barmanBackup *barmanBackup.Command
 }
 
@@ -82,11 +80,6 @@ func NewBarmanBackupCommand(
 	instance *Instance,
 	log log.Logger,
 ) (*BackupCommand, error) {
-	capabilities, err := barmanCapabilities.CurrentCapabilities()
-	if err != nil {
-		return nil, err
-	}
-
 	return &BackupCommand{
 		Cluster:      cluster,
 		Backup:       backup,
@@ -95,8 +88,7 @@ func NewBarmanBackupCommand(
 		Env:          os.Environ(),
 		Instance:     instance,
 		Log:          log,
-		Capabilities: capabilities,
-		barmanBackup: barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore, capabilities),
+		barmanBackup: barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore),
 	}, nil
 }
 
@@ -104,9 +96,6 @@ func NewBarmanBackupCommand(
 // barman-cloud-backup
 func (b *BackupCommand) Start(ctx context.Context) error {
 	contextLogger := log.FromContext(ctx)
-	if err := b.ensureCompatibility(); err != nil {
-		return err
-	}
 
 	b.setupBackupStatus()
 
@@ -145,15 +134,6 @@ func (b *BackupCommand) Start(ctx context.Context) error {
 	return nil
 }
 
-func (b *BackupCommand) ensureCompatibility() error {
-	postgresVers, err := b.Instance.GetPgVersion()
-	if err != nil {
-		return err
-	}
-
-	return b.barmanBackup.IsCompatible(postgresVers)
-}
-
 func (b *BackupCommand) retryWithRefreshedCluster(
 	ctx context.Context,
 	cb func() error,
@@ -234,7 +214,6 @@ func (b *BackupCommand) takeBackup(ctx context.Context) error {
 		b.Backup.Status.BackupName,
 		backupStatus.ServerName,
 		b.Env,
-		b.Cluster,
 		postgres.BackupTemporaryDirectory,
 	)
 	if err != nil {
@@ -249,7 +228,7 @@ func (b *BackupCommand) takeBackup(ctx context.Context) error {
 	b.Backup.Status.SetAsCompleted()
 
 	barmanBackup, err := b.barmanBackup.GetExecutedBackupInfo(
-		ctx, b.Backup.Status.BackupName, backupStatus.ServerName, b.Cluster, b.Env)
+		ctx, b.Backup.Status.BackupName, backupStatus.ServerName, b.Env)
 	if err != nil {
 		return err
 	}
@@ -348,9 +327,7 @@ func (b *BackupCommand) setupBackupStatus() {
 	barmanConfiguration := b.Cluster.Spec.Backup.BarmanObjectStore
 	backupStatus := b.Backup.GetStatus()
 
-	if b.Capabilities.ShouldExecuteBackupWithName(b.Cluster) {
-		backupStatus.BackupName = fmt.Sprintf("backup-%v", pgTime.ToCompactISO8601(time.Now()))
-	}
+	backupStatus.BackupName = fmt.Sprintf("backup-%v", pgTime.ToCompactISO8601(time.Now()))
 	backupStatus.BarmanCredentials = barmanConfiguration.BarmanCredentials
 	backupStatus.EndpointCA = barmanConfiguration.EndpointCA
 	backupStatus.EndpointURL = barmanConfiguration.EndpointURL
diff --git a/pkg/management/postgres/restore.go b/pkg/management/postgres/restore.go
index 58e55569..ee0c63ac 100644
--- a/pkg/management/postgres/restore.go
+++ b/pkg/management/postgres/restore.go
@@ -35,11 +35,11 @@ import (
 	"time"
 
 	barmanArchiver "github.com/cloudnative-pg/barman-cloud/pkg/archiver"
-	barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
 	barmanCatalog "github.com/cloudnative-pg/barman-cloud/pkg/catalog"
 	barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command"
 	barmanCredentials "github.com/cloudnative-pg/barman-cloud/pkg/credentials"
 	barmanRestorer "github.com/cloudnative-pg/barman-cloud/pkg/restorer"
+	barmanUtils "github.com/cloudnative-pg/barman-cloud/pkg/utils"
 	restore "github.com/cloudnative-pg/cnpg-i/pkg/restore/job"
 	"github.com/cloudnative-pg/machinery/pkg/envmap"
 	"github.com/cloudnative-pg/machinery/pkg/execlog"
@@ -452,13 +452,13 @@ func (info InitInfo) restoreDataDir(ctx context.Context, backup *apiv1.Backup, e
 	contextLogger.Info("Starting barman-cloud-restore",
 		"options", options)
 
-	cmd := exec.Command(barmanCapabilities.BarmanCloudRestore, options...) // #nosec G204
+	cmd := exec.Command(barmanUtils.BarmanCloudRestore, options...) // #nosec G204
 	cmd.Env = env
-	err = execlog.RunStreaming(cmd, barmanCapabilities.BarmanCloudRestore)
+	err = execlog.RunStreaming(cmd, barmanUtils.BarmanCloudRestore)
 	if err != nil {
 		var exitError *exec.ExitError
 		if errors.As(err, &exitError) {
-			err = barmanCommand.UnmarshalBarmanCloudRestoreExitCode(ctx, exitError.ExitCode())
+			err = barmanCommand.UnmarshalBarmanCloudRestoreExitCode(exitError.ExitCode())
 		}
 
 		contextLogger.Error(err, "Can't restore backup")
@@ -655,7 +655,7 @@ func (info InitInfo) writeCustomRestoreWalConfig(cluster *apiv1.Cluster, conf st
 func getRestoreWalConfig(ctx context.Context, backup *apiv1.Backup) (string, error) {
 	var err error
 
-	cmd := []string{barmanCapabilities.BarmanCloudWalRestore}
+	cmd := []string{barmanUtils.BarmanCloudWalRestore}
 	if backup.Status.EndpointURL != "" {
 		cmd = append(cmd, "--endpoint-url", backup.Status.EndpointURL)
 	}



Test patch:
diff --git a/pkg/management/postgres/backup_test.go b/pkg/management/postgres/backup_test.go
index a8cfb150..87d654c8 100644
--- a/pkg/management/postgres/backup_test.go
+++ b/pkg/management/postgres/backup_test.go
@@ -25,7 +25,6 @@ import (
 	"strings"
 
 	barmanBackup "github.com/cloudnative-pg/barman-cloud/pkg/backup"
-	barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
 	"github.com/cloudnative-pg/machinery/pkg/log"
 	"k8s.io/apimachinery/pkg/api/meta"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -120,8 +119,6 @@ var _ = Describe("testing backup command", func() {
 				},
 			},
 		}
-		capabilities, err := barmanCapabilities.CurrentCapabilities()
-		Expect(err).ShouldNot(HaveOccurred())
 		backupCommand = BackupCommand{
 			Cluster: cluster,
 			Backup:  backup,
@@ -130,11 +127,10 @@ var _ = Describe("testing backup command", func() {
 				WithObjects(cluster, backup).
 				WithStatusSubresource(cluster, backup).
 				Build(),
-			Recorder:     &record.FakeRecorder{},
-			Env:          os.Environ(),
-			Log:          log.FromContext(context.Background()),
-			Instance:     &Instance{},
-			Capabilities: capabilities,
+			Recorder: &record.FakeRecorder{},
+			Env:      os.Environ(),
+			Log:      log.FromContext(context.Background()),
+			Instance: &Instance{},
 		}
 	})
 
@@ -154,16 +150,9 @@ var _ = Describe("testing backup command", func() {
 var _ = Describe("generate backup options", func() {
 	const namespace = "test"
 
-	var (
-		capabilities *barmanCapabilities.Capabilities
-		cluster      *apiv1.Cluster
-	)
+	var cluster *apiv1.Cluster
 
 	BeforeEach(func() {
-		var err error
-		capabilities, err = barmanCapabilities.CurrentCapabilities()
-		Expect(err).ShouldNot(HaveOccurred())
-
 		cluster = &apiv1.Cluster{
 			ObjectMeta: metav1.ObjectMeta{Name: "test-cluster", Namespace: namespace},
 			Spec: apiv1.ClusterSpec{
@@ -185,7 +174,7 @@ var _ = Describe("generate backup options", func() {
 		extraOptions := []string{"--min-chunk-size=5MB", "--read-timeout=60", "-vv"}
 		cluster.Spec.Backup.BarmanObjectStore.Data.AdditionalCommandArgs = extraOptions
 
-		cmd := barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore, capabilities)
+		cmd := barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore)
 		options, err := cmd.GetDataConfiguration([]string{})
 		Expect(err).ToNot(HaveOccurred())
 
@@ -206,7 +195,7 @@ var _ = Describe("generate backup options", func() {
 			"--encryption=aes256",
 		}
 		cluster.Spec.Backup.BarmanObjectStore.Data.AdditionalCommandArgs = extraOptions
-		cmd := barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore, capabilities)
+		cmd := barmanBackup.NewBackupCommand(cluster.Spec.Backup.BarmanObjectStore)
 		options, err := cmd.GetDataConfiguration([]string{})
 		Expect(err).ToNot(HaveOccurred())