Backup and Restore Workloads using Stash
This guide will show you how Stash backs up and restores volumes of various workload types (Deployment, StatefulSet, DaemonSet etc.).
Before You Begin
- You should be familiar with the following
Stash
concepts:
How Backup Process Works
The following diagram shows how Stash takes backup of the volumes of a workload. Open the image in a new tab to see the enlarged version.
The backup process consists of the following steps:
At first, a user creates a Secret. This secret holds the credentials to access the backend where the backed up data will be stored.
Then, she creates a
Repository
crd which represents the original repository in the backend.Then, she creates a
BackupConfiguration
crd which specifies the targeted workload and desired file paths to backup. It also specifies theRepository
object that holds the backend information where the backed up data will be stored.Stash operator watches for
BackupConfiguration
objects.When it finds a
BackupConfiguration
object, it finds the targeted workload and injects a sidecar namedstash
.It also creates a
CronJob
to trigger backups periodically.The
CronJob
triggers backup on each scheduled slot by creating aBackupSession
crd.The
stash
sidecar inside the workload watches forBackupSession
crd.When it finds a
BackupSession
crd, it initiates backup of the targeted file paths.Once the backup process is completed, the
sidecar
sends Prometheus metrics to the Pushgateway running inside thestash-operator
pod. It also updates respectiveBackupSession
andRepository
status to reflect the backup process.
How Restore Process Works
The following diagram shows how Stash restores backed up data inside a workload. Open the image in a new tab to see the enlarged version.
The restore process consists of the following steps:
At first, the user creates a workload where the data will be restored.
Then, she creates a
RestoreSession
crd that specifies the targeted workload where the backed up data will be restored. It also specifies the respectiveRepository
that holds the respective backend information.Stash operator watches for
RestoreSession
crds.When it finds a
RestoreSession
crd, it injects an init-container namedstash-init
to the workload and restart it.The init-container restores the desired data from the backend on start-up.
Finally, when the restore process is completed it sends Prometheus metrics to the
pushgateway
running inside the stash operator. It also update theRestoreSession
status to reflect the restore process.
Note: If your workload restarts with the
stash-init
init-container for any reason, the init-container will skip running restore process if there is no pendingRestoreSession
for this workload.