You are looking at the documentation of a prior release. To read the documentation of the latest release, please
visit here.
New to Stash? Please start here.
Task
What is Task
An entire backup or restore process needs an ordered execution of one or more steps. A Function represents a step of a backup or restore process. A Task
is a Kubernetes CustomResourceDefinition
(CRD) which specifies a sequence of functions along with their parameters in a Kubernetes native way.
When you install Stash, some Task
s will be pre-installed for supported targets like databases, etc. However, you can create your own Task
to customize or extend the backup/restore process. Stash will execute these steps in the order you have specified.
Task CRD Specification
Like any official Kubernetes resource, a Task
has TypeMeta
, ObjectMeta
and Spec
sections. However, unlike other Kubernetes resources, it does not have a Status
section.
A sample Task
object to backup a PostgreSQL database is shown below:
apiVersion: stash.appscode.com/v1beta1
kind: Task
metadata:
name: postgres-backup-11.2
spec:
steps:
- name: postgres-backup-11.2
params:
- name: outputDir # specifies where to write output file
value: /tmp/output
- name: secretVolume # specifies where backend secret has been mounted
value: secret-volume
- name: update-status
params:
- name: outputDir
value: /tmp/output
- name: secretVolume
value: secret-volume
volumes:
- name: secret-volume
secret:
secretName: ${REPOSITORY_SECRET_NAME}
This Task
uses two functions to backup a PostgreSQL database. The first step uses postgres-backup-11.2
function that dumps PostgreSQL database and uploads the dumped file. The second step uses update-status
function which updates the status of the BackupSession
and Repository
crd for respective backup.
Here, we are going to describe the various sections of a Task
crd.
Task Spec
A Task
object has the following fields in the spec
section:
spec.steps
spec.steps
section specifies a list of functions and their parameters in the order they should be executed. You can also templatize this section using the variables that Stash can resolve itself. Stash will resolve all the variables and create a pod definition with a container specification for each Function
specified in steps
section.
Each step
consists of the following fields:
- name :
name
specifies the name of theFunction
that will be executed at this step. - params :
params
specifies an optional list of variables names and their values that Stash should use to resolve the respectiveFunction
. If you use a variable in aFunction
specification whose value Stash cannot provide, you can pass the value of that variable using thisparams
section. You have to specify the following fields for a variable:- name :
name
of the variable. - value : value of the variable.
- name :
In the above example Task
, we have used outputDir
variable in postgres-backup-11.2
function that Stash can’t resolve automatically. So, we have passed the value using the params
section in the Task
object.
Stash executes the
Functions
in the order they appear inspec.steps
section. All the functions except the last one will be used to createinit-container
specification and the last function will be used to createcontainer
specification for respective backup job. This guarantees an ordered execution of the steps.
spec.volumes
spec.volumes
specifies a list of volumes that should be mounted in the respective job created for this Task
. In the sample we have shown above, we need to mount storage secret for the backup job. So, we have added the secret volume in spec.volumes
section. Note that, we have used REPOSITORY_SECRET_NAME
variable as secret name. This variable will be resolved by Stash from Repository
specification.
Why Function and Task?
You might be wondering why we have introduced Function
and Task
crd. We have designed Function-Task
model for the following reasons:
Customizability:
Function
andTask
enables you to customize backup/recovery process. For example, currently we use mysqldump inmysql-backup
Function to backup MySQL database. You can build a customFunction
using Percona’s xtrabackup tool instead ofmysqldump
. Then you can write aTask
with this customFunction
and use it to backup your target MySQL database.You can also customize backup/restore process by executing hooks before or after the backup/restore process. For example, if you want to execute some logic to prepare your apps for backup or you want to send an email notification after each backup, you just need to add
Function
with your custom logic and respectiveTask
to execute them.Extensibility: Currently, Stash supports backup of MySQL, MongoDB and PostgreSQL databases. You can easily backup the databases that are not officially supported by Stash. You just need to create a
Function
and aTask
for your desired database.Re-usability:
Function
’s are self-sufficient and independent of Stash. So, you can reuse them in any application that usesFunction-Task
model.