Home / Platform management / Clusters / Backup & recovery / Backup Manage / Create an application backup policy

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

Cautions

Procedure

Basic Information

  1. In the left navigation bar, click Clusters > Backup and Recovery.

  2. Switch to the Backup Management tab.

  3. 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 hostpath type 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.

  4. After configuring the basic information, click Next.

Backup resources

Backup application resources under the namespace.

Note

  1. 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.

  2. Click Next.

Method

Configure the time policy for backing up data.

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.

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

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:

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: 10s

Relevant 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.

  1. On the left navigation bar, click Clusters > Backup and Recovery.

  2. Switch to the Backup Management tab.

  3. 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

  1. On the left navigation bar, click Clusters > Backup and Recovery.

  2. Switch to the Backup Management tab.

  3. Click the Backup Policy Name of the backup record to be deleted.

  4. In the Backup Records area, click the > Export Log button on the right side of the backup record.