Fix restic backup volume snapshot to the second location failed (#2244)

* Fix restic backup volume snapshot to the second location failed

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>
pull/2291/head
JenTing Hsiao 2020-02-20 03:01:22 +08:00 committed by GitHub
parent 4a6febd4db
commit b4446bd358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -0,0 +1 @@
Bug fix: restic backup volume snapshot to the second location failed

View File

@ -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
}