You are looking at the documentation of a prior release. To read the documentation of the latest release, please
visit here.
New to KubeDB? Please start here.
Backup & Restore Elasticsearch Using Stash
KubeDB uses Stash to backup and restore databases. Stash by AppsCode is a cloud native data backup and recovery solution for Kubernetes workloads. Stash utilizes restic to securely backup stateful applications to any cloud or on-prem storage backends (for example, S3, GCS, Azure Blob storage, Minio, NetApp, Dell EMC etc.).
How Backup Works
The following diagram shows how Stash takes a backup of an Elasticsearch database. 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 with access credentials of the backend where the backed up data will be stored. 
- Then, she creates a - Repositorycrd that specifies the backend information along with the secret that holds the credentials to access the backend.
- Then, she creates a - BackupConfigurationcrd targeting the AppBinding crd of the desired database. The- BackupConfigurationobject also specifies the- Taskto use to backup the database.
- Stash operator watches for - BackupConfigurationcrd.
- Once Stash operator finds a - BackupConfigurationcrd, it creates a CronJob with the schedule specified in- BackupConfigurationobject to trigger backup periodically.
- On the next scheduled slot, the CronJob triggers a backup by creating a - BackupSessioncrd.
- Stash operator also watches for - BackupSessioncrd.
- When it finds a - BackupSessionobject, it resolves the respective- Taskand- Functionand prepares a Job definition to backup.
- Then, it creates the Job to backup the targeted database. 
- The backup Job reads necessary information to connect with the database from the - AppBindingcrd. It also reads backend information and access credentials from- Repositorycrd and Storage Secret respectively.
- Then, the Job dumps the targeted database and uploads the output to the backend. Stash stores the dumped files temporarily before uploading into the backend. Hence, you should provide a PVC template using - spec.interimVolumeTemplatefield of- BackupConfigurationcrd to use to store those dumped files temporarily.
- Finally, when the backup is completed, the Job sends Prometheus metrics to the Pushgateway running inside Stash operator pod. It also updates the - BackupSessionand- Repositorystatus to reflect the backup procedure.
How Restore Process Works
The following diagram shows how Stash restores backed up data into an Elasticsearch database. Open the image in a new tab to see the enlarged version.
The restore process consists of the following steps:
- At first, a user creates a - RestoreSessioncrd targeting the- AppBindingof the desired database where the backed up data will be restored. It also specifies the- Repositorycrd which holds the backend information and the- Taskto use to restore the target.
- Stash operator watches for - RestoreSessionobject.
- Once it finds a - RestoreSessionobject, it resolves the respective- Taskand- Functionand prepares a Job definition to restore.
- Then, it creates the Job to restore the target. 
- The Job reads necessary information to connect with the database from respective - AppBindingcrd. It also reads backend information and access credentials from- Repositorycrd and Storage Secret respectively.
- Then, the job downloads the backed up data from the backend and insert into the desired database. Stash stores the downloaded files temporarily before inserting into the targeted database. Hence, you should provide a PVC template using - spec.interimVolumeTemplatefield of- RestoreSessioncrd to use to store those restored files temporarily.
- Finally, when the restore process is completed, the Job sends Prometheus metrics to the Pushgateway and update the - RestoreSessionstatus to reflect restore completion.
Next Steps
- Backup your Elasticsearch databases using Stash following the guide from here.
- Configure a generic backup template for all the Elasticsearch databases of your cluster using Stash Auto-backup by following the guide from here.
- Customize the backup & restore process for your cluster by following the guides from here.































