Creating a Recipe
You need a recipe to create a custom workflow for the backup and restore process.
The recipe custom resource has three basic specification elements:
- Groups: A group defines a set of resources or PVCs that are processed together within a backup or restore. For example, a group can be a subset of specific resources that are specified with an exclude statement or an include statement.
- Hooks: A hook can be used to start external scripts before and after snapshots, scale deployments up and down, or wait for certain conditions. For example, pods starting up and so on.
- Workflows: A workflow defines the sequence of steps for a backup or restore operation, specifically the order in which the groups of resources and PVCs must be processed and any hooks that need to be applied.
For example:
apiVersion: spp-data-protection.isf.ibm.com/v1alpha1
kind: Recipe
metadata:
name: wp-recipe
namespace: wordpress
spec:
appType: wordpress
groups:
- name: mysql_data
type: volume
labelSelector: app=wordpress
- name: frontend
labelSelector: tier in (frontend),app=wordpress
- name: backend
type: resource
labelSelector: tier notin (frontend)
hooks:
- name: demoexechook
type: exec
namespace: ${GROUP.wp-app.namespace}
nameSelector: wordpress-mysql.*
ops:
- name: pre
command: >
["/bin/bash", "-c", "echo 'This is pretest' > /tmp/cfg_map_pre.txt"]
container: mysql
- name: post
command: >
["/bin/bash", "-c", "echo 'This is posttest' > /tmp/cfg_map_post.txt"]
container: mysql
- name: demoscalehook
type: scale
namespace: ${GROUP.wp-app.namespace}
selectResource: statefulset
nameSelector: wordpress$
workflows:
- name: backup
sequence:
- hook: demoscalehook/down
- group: frontend
- group: backend
- hook: demoscalehook/sync
- hook: demoexechook/pre
- group: mysql_data
- hook: demoexechook/post
- hook: demoscalehook/up
- name: restore
sequence:
- group: mysql_data
- group: backend
- group: frontend
- Specifying a group
- Groups that are defined in the recipe refine the scope of the parent group, which is completely defined by the application CR. For more information about specifying groups in the application CR, see Assigning a Recipe CR with an application CR.
- Specifying a hook
- Hooks can be used to start external scripts before and after snapshots, scale deployments up and
down, or wait for certain conditions (such as pods starting up). The following types of hooks are supported:
exec
: Start arbitrary commands and scripts within target containers.scale
: scale workload resources up and down.check
: check for conditions on workload resources (such asreadiness
,replicaCount
and so on).
- Specifying a workflow
-
A workflow defines the sequence of steps for both backup and restore operations. At least one backup workflow (named "backup") and one restore workflow (named "restore") must be specified in the recipe CR. More or alternative workflows can be specified that can be referenced in on-demand backup or restore requests (overriding the default ones "backup" and "restore").
The following fields are mandatory for creating a workflow:name
: name of workflow.- The names "backup" and "restore" are reserved and implicitly used by default for backup or restore.
sequence
: sequence of steps to be performed.- Sequence can refer to a series of groups, resources, and hooks in a specific order. The actions are processed sequentially in the specified order.
The following fields are optional for creating a workflow:
sequence/step/group
: refer to a group specified.sequence/step/hook
: refer to a hook and one of its operations.failOn
: determines the behavior if failures when processing groups or hooks. The following is one of these values:any-error
: If this value is specified, the operation fails and performs defined rollback operations if any step of the workflow fails.essential-error
: if this value is specified, the operation fails and performs defined rollback operations if any step of the workflow that is defined as essential fails.full-error
: if this value is specified, the entire workflow is attempted. The workflow is only considered a complete failure if all essential steps fail.