k8up-io / k8up

Kubernetes and OpenShift Backup Operator
https://k8up.io/
Apache License 2.0
684 stars 66 forks source link

Add easy way to create an backup instance of a schedule #955

Open toabi opened 7 months ago

toabi commented 7 months ago

Summary

As "cluster operator or developer"\ I want "to quickly create a new backup off-schedule"\ So that "I can run a upgrade or restore it somewhere else quickly"

Context

The Schedule objects are great to have backups in regular intervals.

But sometimes you want to have a backup now. E.g. before a cluster/app upgrade or when restoring the current state of a customer application in a local dev environment.

It would be cool to have something similar as with CronJob: kubectl create job test-job --from=cronjob/a-cronjob for Schedules.

Implementation Ideas

Maybe the Backup(https://k8up.io/k8up/2.8/how-tos/backup.html) could get a spec.backend.fromSchedule.name field where it then pulls all its info? That would be very minimal and save lots of copy-pasting that info.

johbo commented 5 months ago

Just was looking for this feature. Think it would be very convenient to trigger a schedule in some form manually.

When experimenting with restore options for my setup I got cross the trigger concept of Volsync: https://volsync.readthedocs.io/en/stable/usage/triggers.html

Not too sure though if this would be a good fit. I still would like the idea to be able to annotate a Schedule in some form, so that the operator knows that I'd like it to trigger a backup from it now.

From Flux I know that they work with a different type of annotation which is based on a timestamp: https://fluxcd.io/flux/components/kustomize/kustomizations/#triggering-a-reconcile

My case behind is to ensure that I have fresh backups before re-creating my application or before making a 2nd environment for troubleshooting.

johbo commented 5 months ago

Did put a jq / yq script together to trigger backups of my schedules as an interim solution:

# Generate Backup instances from Schedule objects for k8up
#
# Use as follows:
# - kubectl get schedule/k8up-backup-schedule -o yaml | yq -f ./backup-from-schedule.jq -y
# - kubectl get -A schedule -o yaml | yq -f ./backup-from-schedule.jq -y | kubectl apply -f -
#
# Supports the followings args:
# - suffix: Appends the value as suffix to the resource name

# Allow to the results of "kubectl get" and "kubectl get -A" as input
if .items then .items[] else . end |

{
  apiVersion: "k8up.io/v1",
  kind: "Backup",
  metadata: {
    name: ["manual-from", .metadata.name, $ARGS.named.suffix] | map(select(.)) | join("-"),
    namespace: .metadata.namespace,
  },
  spec: (.spec.backup + {
    backend: .spec.backend,
    podSecurityContext: .spec.podSecurityContext,
  }),
} |
del(.spec.schedule)