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.
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
Tasks 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.
Like any official Kubernetes resource, a
Spec sections. However, unlike other Kubernetes resources, it does not have a
Task object to backup a PostgreSQL database is shown below:
- name: postgres-backup-11.2
- name: outputDir # specifies where to write output file
- name: secretVolume # specifies where backend secret has been mounted
- name: update-status
- name: outputDir
- name: secretVolume
- name: secret-volume
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
Repository crd for respective backup.
Here, we are going to describe the various sections of a
Task object has the following fields in the
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
step consists of the following fields:
name specifies the name of the
Function that will be executed at this step.
params specifies an optional list of variables names and their values that Stash should use to resolve the respective
Function. If you use a variable in a
Function specification whose value Stash cannot provide, you can pass the value of that variable using this
params section. You have to specify the following fields for a variable:
name of the variable.
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
Stash executes the
Functionsin the order they appear in
spec.stepssection. All the functions except the last one will be used to create
init-containerspecification and the last function will be used to create
containerspecification for respective backup job. This guarantees an ordered execution of the steps.
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
You might be wondering why we have introduced
Task crd. We have designed
Function-Task model for the following reasons:
Task enables you to customize backup/recovery process. For example, currently we use mysqldump in
mysql-backup Function to backup MySQL database. You can build a custom
Function using Percona’s xtrabackup tool instead of
mysqldump. Then you can write a
Task with this custom
Function 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 respective
Task 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 a
Task for your desired database.
Function’s are self-sufficient and independent of Stash. So, you can reuse them in any application that uses