mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-03 11:45:20 +00:00
create backups from schedules using velero create backup (#1734)
* add --from-schedule to `velero backup create` to create backups from schedules Signed-off-by: Adnan Abdulhussein <aadnan@vmware.com>
This commit is contained in:
committed by
KubeKween
parent
686f41ebec
commit
6aa0215137
@@ -33,7 +33,7 @@ import (
|
||||
"k8s.io/client-go/tools/cache"
|
||||
|
||||
api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
"github.com/heptio/velero/pkg/builder"
|
||||
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
|
||||
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
|
||||
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
|
||||
@@ -286,29 +286,15 @@ func getNextRunTime(schedule *api.Schedule, cronSchedule cron.Schedule, asOf tim
|
||||
}
|
||||
|
||||
func getBackup(item *api.Schedule, timestamp time.Time) *api.Backup {
|
||||
backup := &api.Backup{
|
||||
Spec: item.Spec.Template,
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: item.Namespace,
|
||||
Name: fmt.Sprintf("%s-%s", item.Name, timestamp.Format("20060102150405")),
|
||||
},
|
||||
}
|
||||
|
||||
addLabelsToBackup(item, backup)
|
||||
name := fmt.Sprintf("%s-%s", item.Name, timestamp.Format("20060102150405"))
|
||||
backup := builder.
|
||||
ForBackup(item.Namespace, name).
|
||||
FromSchedule(item).
|
||||
Result()
|
||||
|
||||
return backup
|
||||
}
|
||||
|
||||
func addLabelsToBackup(item *api.Schedule, backup *api.Backup) {
|
||||
labels := item.Labels
|
||||
if labels == nil {
|
||||
labels = make(map[string]string)
|
||||
}
|
||||
labels[velerov1api.ScheduleNameLabel] = item.Name
|
||||
|
||||
backup.Labels = labels
|
||||
}
|
||||
|
||||
func patchSchedule(original, updated *api.Schedule, client velerov1client.SchedulesGetter) (*api.Schedule, error) {
|
||||
origBytes, err := json.Marshal(original)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user