diff --git a/changelogs/unreleased/2244-jenting b/changelogs/unreleased/2244-jenting new file mode 100644 index 000000000..c5f8391ac --- /dev/null +++ b/changelogs/unreleased/2244-jenting @@ -0,0 +1 @@ +Bug fix: restic backup volume snapshot to the second location failed diff --git a/pkg/controller/pod_volume_backup_controller.go b/pkg/controller/pod_volume_backup_controller.go index a9e211cf3..b6f3efe12 100644 --- a/pkg/controller/pod_volume_backup_controller.go +++ b/pkg/controller/pod_volume_backup_controller.go @@ -248,7 +248,7 @@ func (c *podVolumeBackupController) processBackup(req *velerov1api.PodVolumeBack // changed since the PVC's last backup, restic will not be able to identify a suitable // parent snapshot to use, and will have to do a full rescan of the contents of the PVC. if pvcUID, ok := req.Labels[velerov1api.PVCUIDLabel]; ok { - parentSnapshotID := getParentSnapshot(log, pvcUID, c.podVolumeBackupLister.PodVolumeBackups(req.Namespace)) + parentSnapshotID := getParentSnapshot(log, pvcUID, req.Spec.BackupStorageLocation, c.podVolumeBackupLister.PodVolumeBackups(req.Namespace)) if parentSnapshotID == "" { log.Info("No parent snapshot found for PVC, not using --parent flag for this backup") } else { @@ -302,7 +302,7 @@ func (c *podVolumeBackupController) processBackup(req *velerov1api.PodVolumeBack // getParentSnapshot finds the most recent completed pod volume backup for the specified PVC and returns its // restic snapshot ID. Any errors encountered are logged but not returned since they do not prevent a backup // from proceeding. -func getParentSnapshot(log logrus.FieldLogger, pvcUID string, podVolumeBackupLister listers.PodVolumeBackupNamespaceLister) string { +func getParentSnapshot(log logrus.FieldLogger, pvcUID, backupStorageLocation string, podVolumeBackupLister listers.PodVolumeBackupNamespaceLister) string { log = log.WithField("pvcUID", pvcUID) log.Infof("Looking for most recent completed pod volume backup for this PVC") @@ -320,6 +320,14 @@ func getParentSnapshot(log logrus.FieldLogger, pvcUID string, podVolumeBackupLis continue } + if backupStorageLocation != backup.Spec.BackupStorageLocation { + // Check the backup storage location is the same as spec in order to support backup to multiple backup-locations. + // Otherwise, there exists a case that backup volume snapshot to the second location would failed, since the founded + // parent ID is only valid for the first backup location, not the second backup location. + // Also, the second backup should not use the first backup parent ID since its for the first backup location only. + continue + } + if mostRecentBackup == nil || backup.Status.StartTimestamp.After(mostRecentBackup.Status.StartTimestamp.Time) { mostRecentBackup = backup }