Create and Restore backups
When Velero is activated on the platform level, platform admins can create backups of Persistent Volumes (PVs) in Team namespaces using the Console. When creating backups using the Console, a Velero schedule
resource is created that will create the backup at a specified time, defined by a Cron expression.
In this how-to, we'll create a Backup of a PV and then restore it using the velero CLI integrated into the Shell.
Prerequisites
To perform this how-to, first make sure Velero is enabled. Velero requires object storage to be be configured. Linode Object Storage or the local Minio can be used for Object Storage. In this how-to we'll use Minio.
When Velero is activated, only the Velero plug-in for Linode is configured by default. Velero also has support for backing up and restoring Kubernetes volumes using Restic. Note that Restic is not enabled by default.
For this how-to we'll use the PV of a Team's private Prometheus instance, so make sure Prometheus is also enabled.
Create a backup schedule
-
Select the Team name in the top bar to set the context to the namespace that contains the PV to backup. In this how-to we'll use the team
demo
. -
In the Console, click on
Backup
in the left menu underPlatform
and click onCreate
. -
Enter a name for the backup. In this how-to we'll use the name
prom
. -
Add the schedule of the backup. The schedule is a cron-type expression to schedule the backup. Defaults to once a day at 00:00. Create your cron-type expression here.
-
In this how-to, we'll create a backup of the private Prometheus PV in the
demo
team by using alabelSelector
.
If the labelSelector is not used, the backup schedule will backup all PVs of the team.
-
In the Console, click on
Shell
in the bottom of the left menu. -
Run the following cmd in the shell:
kubectl get statefulset prometheus-demo-po-prometheus -n team-demo --show-labels
\NAME READY AGE LABELS
prometheus-demo-po-prometheus 1/1 77m app.kubernetes.io/instance=prometheus-demo,app.kubernetes.io/managed-by=Helm,app.kubernetes.io/part-of=demo-po,app.kubernetes.io/version=46.4.1,app=demo-po-prometheus,chart=kube-prometheus-stack-46.4.1,heritage=Helm,operator.prometheus.io/mode=server,operator.prometheus.io/name=demo-po-prometheus,operator.prometheus.io/shard=0,prometheus=team-demo,release=prometheus-demo
- click on
Add Item
and fill in the following:
name: prometheus
value: team-demo
-
Use the default TTL (expiration of the backup). Defaults to 7 days.
-
Click
Submit
Check if the schedule is created
-
In the Console, click on
Shell
in the bottom of the left menu. -
Run the following cmd in the shell:
velero get schedules
NAME STATUS CREATED SCHEDULE BACKUP TTL LAST BACKUP SELECTOR PAUSED
team-demo-backup-prom Enabled 2023-09-24 11:50:59 +0000 UTC 55 * * * * 168h0m0s n/a <none> false
Check if the backup is created
- Run the following cmd in the shell:
velero get backups
NAME STATUS ERRORS WARNINGS CREATED EXPIRES STORAGE LOCATION SELECTOR
team-demo-backup-prom-20230924115514 Completed 0 0 2023-09-24 11:55:14 +0000 UTC 6d apl prometheus=team-demo
You can see the status of the backup is Completed
. The backup is now stored in the local Minio.
Restore the backup
Now the backup is created, we can restore the backup.
Follow this procedure to restore a backup:
-
Scale down the
replicas
of thedeployment
orstatefulset
that uses the PV. -
Delete the PVC. You can find the name of the PVC in the deployment
spec.template.spec.volumes
. -
Run the following cmd in the shell:
velero restore create --from-backup team-demo-backup-prom-20230924115514
Restore request "team-demo-backup-prom-20230924115514-20230924133133" submitted successfully.
Run `velero restore describe team-demo-backup-prom-20230924115514-20230924133133` or `velero restore logs team-demo-backup-prom-20230924115514-20230924133133` for more details.
- Scale up the
replicas
of thedeployment
orstatefulset
to use the restored PV.
Manually create backups
Only platform administrators are able to use the Backup self-service feature to schedule backups of persistent volumes within Team namespaces. The Shell in the Console includes the Velero CLI, so if you're confortable with Velero you can also create you're own custom backups. Check the docs on https://velero.io/ for more information.
This is an example of creating a custom backup:
- Create a full backup (to backup all resources, including PVs):
velero backup create my-custom-backup-01 --include-namespaces team-demo
- Create a backup of specific resources:
velero backup create my-custom-backup-02 --include-namespaces team-demo --include-resources secret,deployment
- Verify the backup:
velero describe backup my-custom-backup-01 --details
- Restore a backup:
velero restore create --from-backup my-custom-backup-01