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.05.12 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.

NATS Backup Overview
Fig: NATS Backup Overview

The backup process consists of the following steps:

  1. At first, a user creates a secret with access credentials of the backend where the backed up data will be stored.

  2. Then, she creates a Repository crd that specifies the backend information along with the secret that holds the credentials to access the backend.

  3. Then, she creates a BackupConfiguration crd targeting the AppBinding crd of the respective NATS server. The BackupConfiguration object also specifies the Task to use to backup the NATS streams.

  4. Stash operator watches for BackupConfiguration crd.

  5. Once Stash operator finds a BackupConfiguration crd, it creates a CronJob with the schedule specified in BackupConfiguration object to trigger backup periodically.

  6. On the next scheduled slot, the CronJob triggers a backup by creating a BackupSession crd.

  7. Stash operator also watches for BackupSession crd.

  8. When it finds a BackupSession object, it resolves the respective Task and Function and prepares a Job definition to backup.

  9. Then, it creates the Job to backup the targeted NATS server.

  10. The backup Job reads necessary information to connect with the NATS server from the AppBinding crd. It also reads backend information and access credentials from Repository crd and Storage Secret respectively.

  11. 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.interimVolumeTemplate field of BackupConfiguration crd 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.

  12. Finally, when the backup is completed, the Job sends Prometheus metrics to the Pushgateway running inside Stash operator pod. It also updates the BackupSession and Repository status 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.

NATS Restore Overview
Fig: NATS Restore Process

The restore process consists of the following steps:

  1. At first, a user creates a RestoreSession crd targeting the AppBinding of the desired NATS server where the backed up data will be restored. It also specifies the Repository crd which holds the backend information and the Task to use to restore the target.

  2. Stash operator watches for RestoreSession object.

  3. Once it finds a RestoreSession object, it resolves the respective Task and Function and prepares a Job definition to restore.

  4. Then, it creates the Job to restore the target.

  5. The Job reads necessary information to connect with the NATS server from respective AppBinding crd. It also reads backend information and access credentials from Repository crd and Storage Secret respectively.

  6. 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.interimVolumeTemplate field of RestoreSession crd 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.

  7. Finally, when the restore process is completed, the Job sends Prometheus metrics to the Pushgateway and update the RestoreSession status to reflect restore completion.

Next Steps

  • Backup your NATS using Stash following the guide from here.