You are looking at the documentation of a prior release. To read the documentation of the latest release, please
visit here.
Customizing Backup Process
Stash provides rich customization supports for the backup and restores process to meet the requirements of various cluster configurations. This guide will show you some examples of these customizations.
In this section, we are going to show you how to customize the backup process. Here, we are going to show some examples of filtering resources using a label selector, running the backup process as a specific user, using multiple retention policies, etc.
Note: YAML files used in this tutorial are stored here.
Filtering resources
You can use a label selector to backup the YAML for the resources that have particular labels. You just have to pass the labelSelector
parameter under task.params
section with your desired label selector.
apiVersion: stash.appscode.com/v1beta1
kind: BackupConfiguration
metadata:
name: cluster-resources-backup
namespace: demo
spec:
schedule: "*/5 * * * *"
task:
name: kubedump-backup-0.1.0
params:
- name: labelSelector
value: "k8s-app=kube-dns"
repository:
name: cluster-resource-storage
runtimeSettings:
pod:
serviceAccountName: cluster-resource-reader
retentionPolicy:
name: keep-last-5
keepLast: 5
prune: true
The above backup process will backup only the resources that has k8s-app: kube-dns
label. Here, is a sample of the resources backed up by the above BackupConfiguration.
❯ tree $HOME/Downloads/stash
/home/emruz/Downloads/stash
└── latest
└── tmp
└── resources
└── namespaces
└── kube-system
├── Deployment
│ └── coredns.yaml
├── Endpoints
│ └── kube-dns.yaml
├── EndpointSlice
│ └── kube-dns-m2s5c.yaml
├── Pod
│ ├── coredns-558bd4d5db-hdsw9.yaml
│ └── coredns-558bd4d5db-wk9tx.yaml
├── ReplicaSet
│ └── coredns-558bd4d5db.yaml
└── Service
└── kube-dns.yaml
11 directories, 7 files
Passing arguments
You can pass arguments to the backup process using task.params
section.
The following example shows how passes sanitize
argument value to false
which tells the backup process not to remove decorators (i.e. status
, managedFields
etc.) from the YAML files.
apiVersion: stash.appscode.com/v1beta1
kind: BackupConfiguration
metadata:
name: cluster-resources-backup
namespace: demo
spec:
schedule: "*/5 * * * *"
task:
name: kubedump-backup-0.1.0
params:
- name: sanitize
value: "false"
repository:
name: cluster-resource-storage
runtimeSettings:
pod:
serviceAccountName: cluster-resource-reader
retentionPolicy:
name: keep-last-5
keepLast: 5
prune: true
Running backup job as a specific user
If your cluster requires running the backup job as a specific user, you can provide securityContext
under runtimeSettings.pod
section. The below example shows how you can run the backup job as the root user.
apiVersion: stash.appscode.com/v1beta1
kind: BackupConfiguration
metadata:
name: cluster-resources-backup
namespace: demo
spec:
schedule: "*/5 * * * *"
task:
name: kubedump-backup-0.1.0
repository:
name: cluster-resource-storage
runtimeSettings:
pod:
serviceAccountName: cluster-resource-reader
securityContext:
runAsUser: 0
runAsGroup: 0
retentionPolicy:
name: keep-last-5
keepLast: 5
prune: true
Specifying Memory/CPU limit/request for the backup job
If you want to specify the Memory/CPU limit/request for your backup job, you can specify resources
field under runtimeSettings.container
section.
apiVersion: stash.appscode.com/v1beta1
kind: BackupConfiguration
metadata:
name: cluster-resources-backup
namespace: demo
spec:
schedule: "*/5 * * * *"
task:
name: kubedump-backup-0.1.0
repository:
name: cluster-resource-storage
runtimeSettings:
pod:
serviceAccountName: cluster-resource-reader
container:
resources:
requests:
cpu: "200m"
memory: "1Gi"
limits:
cpu: "200m"
memory: "1Gi"
retentionPolicy:
name: keep-last-5
keepLast: 5
prune: true
Using multiple retention policies
You can also specify multiple retention policies for your backed up data. For example, you may want to keep a few daily snapshots, a few weekly snapshots, and few monthly snapshots, etc. You just need to pass the desired number with the respective key under the retentionPolicy
section.
apiVersion: stash.appscode.com/v1beta1
kind: BackupConfiguration
metadata:
name: cluster-resources-backup
namespace: demo
spec:
schedule: "*/5 * * * *"
task:
name: kubedump-backup-0.1.0
repository:
name: cluster-resource-storage
runtimeSettings:
pod:
serviceAccountName: cluster-resource-reader
retentionPolicy:
name: cluster-resource-retention
keepLast: 5
keepDaily: 10
keepWeekly: 20
keepMonthly: 50
keepYearly: 100
prune: true
To know more about the available options for retention policies, please visit here.