Skip to content

Commit

Permalink
feat(backup): modify system backup controller
Browse files Browse the repository at this point in the history
Ref: 5411

Signed-off-by: James Lu <james.lu@suse.com>
  • Loading branch information
mantissahz committed Sep 26, 2024
1 parent 2d98a2a commit 1a76623
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions controller/system_backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,17 @@ func (c *SystemBackupController) createVolumeBackup(volume *longhorn.Volume, sys
return nil, errors.Wrapf(err, "failed to create Volume %v snapshot %s", volume.Name, snapshot.Name)
}

backupTargetName := volume.Spec.BackupTargetName
backup = &longhorn.Backup{
ObjectMeta: metav1.ObjectMeta{
Name: volumeBackupName,
Labels: map[string]string{
types.LonghornLabelBackupTarget: backupTargetName,
},
},
Spec: longhorn.BackupSpec{
SnapshotName: snapshot.Name,
SnapshotName: snapshot.Name,
BackupTargetName: backupTargetName,
},
}
backup, err = c.ds.CreateBackup(backup, volume.Name)
Expand Down Expand Up @@ -946,25 +951,34 @@ func (c *SystemBackupController) WaitForBackingImageBackupToComplete(backupBacki
}

func (c *SystemBackupController) createBackingImageBackup(backingImage *longhorn.BackingImage) (backupBackingImage *longhorn.BackupBackingImage, err error) {
backupBackingImage, err = c.ds.GetBackupBackingImage(backingImage.Name)
backupTargetName := types.DefaultBackupTargetName
backingImageName := backingImage.Name
backupBackingImage, err = c.ds.GetBackupBackingImagesWithBackupTargetNameRO(backupTargetName, backingImageName)
if err != nil {
if !apierrors.IsNotFound(err) {
return nil, errors.Wrapf(err, "failed to get backup backing image %v", backingImage.Name)
return nil, errors.Wrapf(err, "failed to get backup backing image %v", backingImageName)
}
}

if backupBackingImage == nil {
backupBackingImageName := types.GetBackupBackingImageNameFromBIName(backingImageName)
backupBackingImage = &longhorn.BackupBackingImage{
ObjectMeta: metav1.ObjectMeta{
Name: backingImage.Name,
Name: backupBackingImageName,
Labels: map[string]string{
types.LonghornLabelBackingImage: backingImageName,
types.LonghornLabelBackupTarget: backupTargetName,
},
},
Spec: longhorn.BackupBackingImageSpec{
UserCreated: true,
UserCreated: true,
BackingImage: backingImageName,
BackupTargetName: backupTargetName,
},
}
backupBackingImage, err = c.ds.CreateBackupBackingImage(backupBackingImage)
if err != nil && !apierrors.IsAlreadyExists(err) {
return nil, errors.Wrapf(err, "failed to create backup backing image %s", backingImage.Name)
return nil, errors.Wrapf(err, "failed to create backup backing image %s", backingImageName)
}
}
return backupBackingImage, nil
Expand Down

0 comments on commit 1a76623

Please sign in to comment.