vmware-tanzu / velero

Backup and migrate Kubernetes applications and their persistent volumes
https://velero.io
Apache License 2.0
8.63k stars 1.39k forks source link

Velero CSI plugin restore PV and PVC resources with --restore-volumes=false #7778

Closed Lingkar closed 4 months ago

Lingkar commented 4 months ago

Describe the problem/challenge you have In the scenario of a full cluster restore, we might not want to restore-volumes based on the latest snapshot, as this can loose the latest data. In such a scenario I would expect running a restore with the flag --restore-volumes=false would just recreate the PV and PVC k8s resources, just like it does without the CSI plugin installed. And thus pointing to the already provisioned disks, without restoring and creating new ones from snapshot.

Without the CSI plugin: velero restore create --from-backup backup-1 --include-resources=pvc,pv --restore-volumes=false

velero restore describe backup-1-20240507105024 --details
Name:         backup-1-20240507105024
Namespace:    velero
Labels:       <none>
Annotations:  <none>

Phase:                       Completed
Total items to be restored:  11
Items restored:              11

Started:    2024-05-07 10:50:24 +0200 CEST
Completed:  2024-05-07 10:50:26 +0200 CEST

Backup:  backup-1

Namespaces:
  Included:  all namespaces found in the backup
  Excluded:  <none>

Resources:
  Included:        pvc, pv
  Excluded:        nodes, events, events.events.k8s.io, backups.velero.io, restores.velero.io, resticrepositories.velero.io, csinodes.storage.k8s.io, volumeattachments.storage.k8s.io, backuprepositories.velero.io
  Cluster-scoped:  auto

Namespace mappings:  <none>

Label selector:  <none>

Or label selector:  <none>

Restore PVs:  false

Existing Resource Policy:   <none>
ItemOperationTimeout:       4h0m0s

Preserve Service NodePorts:  auto

HooksAttempted:   0
HooksFailed:      0

Resource List:
  v1/Namespace:
    - monitoring(created)
  v1/PersistentVolume:
    - pvc-464cf8d2-bcc1-41e3-9357-432dc6190edc(created)
    - pvc-46d341b7-978e-426e-bf90-2f61ba2c21a8(created)
    - pvc-97c8b72e-0c33-4105-bb95-68152b11f9db(created)
    - pvc-c54306db-66d9-4b4f-b3cc-83179704e2eb(created)
    - pvc-c8df73fc-e681-46f0-b319-d4a912d66945(created)
  v1/PersistentVolumeClaim:
    - monitoring/prometheus-server(created)
    - monitoring/storage-loki-0(created)
    - monitoring/storage-prometheus-alertmanager-0(created)
    - monitoring/test-pvc-disk(created)
    - monitoring/test-pvc-file(created)

When using the CSI plugin I seem to loose the ability to just restore the PV and PVC resources without restoring the data on the volumes. I guess due to the PV's being skipped in favor of restoring from snapshot, even though --restore-volumes=false

With CSI plugin: velero restore create --from-backup backup-2 --include-resources=pvc,pv --restore-volumes=false

velero restore describe backup-2-20240507111333 --details
Name:         backup-2-20240507111333
Namespace:    velero
Labels:       <none>
Annotations:  <none>

Phase:                       Completed
Total items to be restored:  11
Items restored:              11

Started:    2024-05-07 11:13:33 +0200 CEST
Completed:  2024-05-07 11:13:35 +0200 CEST

Backup:  backup-2

Namespaces:
  Included:  all namespaces found in the backup
  Excluded:  <none>

Resources:
  Included:        pvc, pv
  Excluded:        nodes, events, events.events.k8s.io, backups.velero.io, restores.velero.io, resticrepositories.velero.io, csinodes.storage.k8s.io, volumeattachments.storage.k8s.io, backuprepositories.velero.io
  Cluster-scoped:  auto

Namespace mappings:  <none>

Label selector:  <none>

Or label selector:  <none>

Restore PVs:  false

Existing Resource Policy:   <none>
ItemOperationTimeout:       4h0m0s

Preserve Service NodePorts:  auto

HooksAttempted:   0
HooksFailed:      0

Resource List:
  v1/Namespace:
    - monitoring(created)
  v1/PersistentVolume:
    - pvc-464cf8d2-bcc1-41e3-9357-432dc6190edc(skipped)
    - pvc-46d341b7-978e-426e-bf90-2f61ba2c21a8(skipped)
    - pvc-97c8b72e-0c33-4105-bb95-68152b11f9db(skipped)
    - pvc-c54306db-66d9-4b4f-b3cc-83179704e2eb(skipped)
    - pvc-c8df73fc-e681-46f0-b319-d4a912d66945(skipped)
  v1/PersistentVolumeClaim:
    - monitoring/prometheus-server(created)
    - monitoring/storage-loki-0(created)
    - monitoring/storage-prometheus-alertmanager-0(created)
    - monitoring/test-pvc-disk(created)
    - monitoring/test-pvc-file(created)

Describe the solution you'd like I would like the CSI plugin to not skip the PersistentVolume resources when the flag --restore-volumes=false is used. Thus behaving in a similar way when the CSI plugin is not used. Or I would love to hear which part I am missing. And if this is not possible why it is not possible and the design decision behind it, or if I am approaching this problem incorrectly.

Anything else you would like to add: If this seems like a good "first-issue" I would love to discuss it further and try to pick it up.

Environment:

Vote on this issue!

This is an invitation to the Velero community to vote on issues, you can see the project's top voted issues listed here.
Use the "reaction smiley face" up to the right of this comment to vote.

blackpiglet commented 4 months ago

I suggest doing a backup with --snapshot-volumes=false at first. But it requires setting the PVC's DeletionPolicy to Retain to restore the PV with the same content as the backed-up PV.

Lingkar commented 4 months ago

@blackpiglet Thanks for your response, I will try it out! DeletionPolicy are on Retain, so that will not be an issue.

Lingkar commented 4 months ago

@blackpiglet Works like a charm, thanks!