You are looking at the documentation of a prior release. To read the documentation of the latest release, please
visit here.
How Stash Backups & Restores NATS Streams
Stash v2022.03.29 supports backup and restore operation of NATS streams. This guide will give you an overview of how NATS stream backup and restore process works in Stash.
How Backup Works
The following diagram shows how Stash takes a backup of NATS streams. 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 respective NATS server. TheBackupConfigurationobject also specifies theTaskto use to backup the NATS streams.Stash operator watches for
BackupConfigurationcrd.Once Stash operator finds a
BackupConfigurationcrd, it creates a CronJob with the schedule specified inBackupConfigurationobject 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 respectiveTaskandFunctionand prepares a Job definition to backup.Then, it creates the Job to backup the targeted NATS server.
The backup Job reads necessary information to connect with the NATS server from the
AppBindingcrd. It also reads backend information and access credentials fromRepositorycrd and Storage Secret respectively.Then, the Job dumps the targeted streams 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 ofBackupConfigurationcrd to use to store those dumped files temporarily. Make sure that the provided PVC size is capable of storing all (or, specified) the NATS streams.Finally, when the backup is completed, the Job sends Prometheus metrics to the Pushgateway running inside Stash operator pod. It also updates the
BackupSessionandRepositorystatus to reflect the backup procedure.
How Restore Process Works
The following diagram shows how Stash restores backed up data into a NATS streaming server. 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 theAppBindingof the desired NATS server where the backed up data will be restored. It also specifies theRepositorycrd which holds the backend information and theTaskto use to restore the target.Stash operator watches for
RestoreSessionobject.Once it finds a
RestoreSessionobject, it resolves the respectiveTaskandFunctionand prepares a Job definition to restore.Then, it creates the Job to restore the target.
The Job reads necessary information to connect with the NATS server from respective
AppBindingcrd. It also reads backend information and access credentials fromRepositorycrd and Storage Secret respectively.Then, the job downloads the backed up data from the backend and restore the streams. Stash stores the downloaded files temporarily before inserting into the targeted NATS server. Hence, you should provide a PVC template using
spec.interimVolumeTemplatefield ofRestoreSessioncrd to use to store those restored files temporarily. Make sure that the provided PVC size is capable of storing all the backed up NATS streams.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 NATS using Stash following the guide from here.






