Create an application backup policy
You can create an application backup policy to specify the scope of application data to be backed up (by namespace), the backup data storage location, backup method, and other information. Each backup executed based on the policy generates a new backup record, making it easy for you to automatically back up data for business resources such as applications running in the cluster namespace at any time or on a periodic basis.
Prerequisites
-
The backup and recovery component has been deployed for the current cluster.
-
If you need to back up the cluster’s resource data to external storage, please prepare the docking information for the external storage in advance. Currently, only S3 (Simple Storage Service) compatible object storage is supported, such as Amazon S3, MinIO, Tencent Cloud Object Storage COS, Huawei Cloud Object Storage OBS, Alibaba Cloud Object Storage OSS, etc.
Cautions
-
If you need to back up application data, you can choose to back up the persistent volume claim (PVC). At this time, backing up the persistent volume claim bound to the persistent volume of the
hostpathtype is not supported. -
To ensure the reliability and integrity of data, it is not recommended to back up database data, such as MySQL-PXC and Redis databases. If you need to back up data, switch to Data Services for data backup.
-
During the backup process, it is recommended not to perform any read, write, update, delete, and other operations in the namespace to be backed up to avoid data differences during the backup process, resulting in inconsistent data after migration.
Procedure
Basic Information
-
In the left navigation bar, click Clusters > Backup and Recovery.
-
Switch to the Backup Management tab.
-
Click Create Backup Policy > Create Application Backup and configure the relevant parameters according to the following instructions.
-
Backup Resource Type: Kubernetes Resources includes all Kubernetes resource files in the namespaces created by users; PVCs are persistent volume claims created by users in the platform, used to back up application data bound to the persistent volumes, and do not support backing up persistent volume claims bound to
hostpathtype persistent volumes.Tip:
-
If the storage resource used by your persistent volume claim has a Recycle Strategy of Retain, only Kubernetes resources need to be backed up.
-
If the storage resource used by your persistent volume claim has a Recycle Strategy of Delete, both Kubernetes resources and persistent volume claims need to be backed up.
-
-
Backup Repository: Select a backup repository that has passed connectivity verification, or click Create Backup Repository .
Tip: After creating a backup repository, you can click OK and Create Application Backup to return to this page and continue creating, or click Create to return to the backup repository list page to view the created backup repositories.
-
-
After configuring the basic information, click Next.
Backup resources
Backup application resources under the namespace.
Note:
-
If there are namespaces that have not been imported in the cluster, they will not be displayed on this page. If you need to back up resources under that namespace, please import the namespace into the project first.
-
To ensure the reliability and integrity of data, it is not recommended to back up database data, such as MySQL-PXC and Redis databases. If you need to back up data, please switch to Data Services for data backup.
-
Select the Namespaces that need to be backed up, either by single selection or multiple selection.
Tip: When selecting Backup Kubernetes resources and Persistent Volume Claims as the resource type to be backed up, you can view all the Persistent Volume Claims under the namespace in the Persistent Volume Claims column.
-
Click Next.
Method
Configure the time policy for backing up data.
-
Backup once only: After the policy is created, a backup will be executed immediately. After configuring the Backup retention period, backup files that exceed the retention period will be automatically cleaned up by the system.
-
Scheduled: Set a scheduled Backup rule to automatically execute the backup policy periodically. You can enter a Crontab expression. For detailed configuration methods, please refer to How to set a scheduled trigger rule? . After configuring the Backup retention period, backup files that exceed the retention period will be automatically cleaned up by the system.
Tip:
-
Click the input box to expand the platform’s preset Backup rule templates. Select a suitable template and modify it slightly to quickly set up the backup rule.
-
Depending on the Backup resource type you choose, it is recommended to configure the scheduled backup rule reasonably. When selecting Backup Kubernetes resources and Persistent Volume Claims as the resource type to be backed up, the minimum backup frequency is once a day; when selecting Backup Kubernetes resources as the resource type to be backed up, the minimum backup frequency is once an hour.
-
Advanced configuration
Custom hooks are extension commands that run in the cluster container. By customizing hooks, you can flexibly perform some custom operations during the backup and restore process. If you have special configuration requirements, please contact technical support personnel.
- Backup Hook
During the backup task execution, when a Pod is being backed up, you can set one or more commands to be executed on the container(s) inside the Pod. These commands can be executed before (pre) or after (post) the Pod backup operation is completed.
Hooks can be configured under the .spec.template.spec.hooks field of the schedule resource or the .spec.hooks field of the backup resource.
The configuration example and parameter description are as follows:
hooks:
resources:
-
# Hook Name,Show in logs。
name: my-hook
# (Optional)Execute Hook List of namespace names to execute in(Array)。If not set,Hook Execute in all namespaces of the cluster。
includedNamespaces:
- '*'
# (Optional)Execute Hook List of namespace names to execute in(Array)。
excludedNamespaces:
- some-namespace
# Execute Hook List of resources to execute on。Currently only supports pods。
includedResources:
- pods
# (Optional)match Execute Hook Label selector for resources to execute on
labelSelector:
matchLabels:
app: velero
component: server
# Pod Actions to execute before backup Hook List of actions(Array)。Only supports exec Type of Hook。
pre:
-
exec:
# (Optional)Name of container to execute command in。If not set,Default selection Pod First container in。
container: my-container
# Command to execute, Array,Must be set。
command:
- /bin/uname
- -a
# (Optional)Strategy for failed command execution,Valid values are Continue or Fail,Default is Fail。
onError: Fail
# (Optional)Duration to wait for command execution to complete。Default is 30s。
timeout: 10s
# Pod Actions to execute after backup Hook List of actions(Array),Only supports exec Type of Hook。
post:
# Please refer to pre Set- Restore Hooks
The backup and restore component supports executing custom operations through hooks during or after the restore task.
For restore tasks, there are two types of hooks supported:
-
initContainer restore hook: adds an init container to the restored Pod to perform necessary setup before the application container starts.
-
exec restore hook: used to execute commands or scripts in the container of the restored Pod.
Restore hooks can be set in the .spec.hooks field of the restore resource. The configuration example and parameter description are as follows:
hooks:
resources:
# hook Name
- name: restore-hook-1
# (Optional)Execute Hook List of namespace names to execute in(Array)。If not set,Hook Execute in all namespaces of the cluster。
includedNamespaces:
- ns1
# (Optional)Execute Hook List of namespace names to execute in(Array)。
excludedNamespaces:
- ns3
# Execute Hook List of resources to execute on。Currently only supports pods。
includedResources:
- pods
# (Optional)match Execute Hook Label selector for resources to execute on.
labelSelector:
matchLabels:
app: velero
component: server
# Hook List,Only supports init and exec Type of Hook。
postHooks:
- init:
# containers List,These containers will be added to the Hook Will be executed on initContainers in。
initContainers:
- name: restore-hook-init1
image: alpine:latest
volumeMounts:
- mountPath: /restores/pvc1-vm
name: pvc1-vm
command:
- /bin/ash
- -c
- echo -n "FOOBARBAZ" >> /restores/pvc1-vm/foobarbaz
- name: restore-hook-init2
image: alpine:latest
volumeMounts:
- mountPath: /restores/pvc2-vm
name: pvc2-vm
command:
- /bin/ash
- -c
- echo -n "DEADFEED" >> /restores/pvc2-vm/deadfeed
- exec:
# (Optional)Name of container to execute command in。If not set,Default selection Pod First container in。
container: my-container
# Command to execute,is array,Must be set。
command:
- /bin/uname
- -a
# (Optional)Strategy for failed command execution,Valid values are Continue or Fail,Default is Fail。
onError: Fail
# (Optional)Duration to wait for command execution to complete。Default is 30s。
timeout: 10sRelevant operations
Perform the backup policy manually
Manually execute the created backup policy (including policies with scheduled backup rules) for data backup. Each execution generates a new backup record.
-
On the left navigation bar, click Clusters > Backup and Recovery.
-
Switch to the Backup Management tab.
-
Click the
> Execute Backup button on the right side of the policy to be executed, and confirm.
Export the backup task log
Supports manually exporting the backup task log under a specified backup policy.
Tip: Log export is not supported while the backup task is in progress.
Procedure
-
On the left navigation bar, click Clusters > Backup and Recovery.
-
Switch to the Backup Management tab.
-
Click the Backup Policy Name of the backup record to be deleted.
-
In the Backup Records area, click the
> Export Log button on the right side of the backup record.