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 Etcd Database
Stash v2022.12.11
supports backup and restore operation of many databases. This guide will give you an overview of how Etcd database backup and restore process works in Stash.
Backup
Stash supports taking backup of Etcd database using etcdctl. It is the most flexible way to perform backup and restore of Etcd database.
How Backup Works
The following diagram shows how Stash takes backup of a Etcd 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
Repository
crd that specifies the backend information along with the secret that holds the credentials to access the backend.Then, she creates a
BackupConfiguration
crd targeting the AppBinding crd of the desired database. TheBackupConfiguration
object also specifies theTask
to use to backup the database.Stash operator watches for
BackupConfiguration
crd.Once Stash operator finds a
BackupConfiguration
crd, it creates a CronJob with the schedule specified inBackupConfiguration
object to trigger backup periodically.On the next scheduled slot, the CronJob triggers a backup by creating a
BackupSession
crd.Stash operator also watches for
BackupSession
crd.When it finds a
BackupSession
object, it resolves the respectiveTask
andFunction
and prepares a Job definition to backup.Then, it creates the Job to backup the targeted database.
The backup Job reads the necessary information to connect with the database from the
AppBinding
crd. It also reads backend information and access credentials fromRepository
crd and Storage Secret respectively.Then, the Job takes snapshot of the targeted database using
etcdctl
and uploads the snapshot to the backend. Stash stores the snapshot temporarily in a directory before uploading that into the backend. You can limit the temporary directory size usingspec.TempDir
field ofBackupConfiguration
crd.Finally, when the backup is complete, the Job sends Prometheus metrics to the Pushgateway running inside Stash operator pod. It also updates the
BackupSession
andRepository
status to reflect the backup completion.
How Restore from Backup Works
The following diagram shows how Stash restores an Etcd database from a backup. 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
RestoreSession
crd targeting theAppBinding
of the desired database where the backed up data will be restored. It also specifies theRepository
crd which holds the backend information and theTask
to use to restore the target.Stash operator watches for
RestoreSession
object.Once it finds a
RestoreSession
object, it resolves the respectiveTask
andFunction
and 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
AppBinding
crd. It also reads backend information and access credentials fromRepository
crd and Storage Secret respectively.Then, the job downloads the backed up snapshot from the backend and restore that snapshot into the
Etcd
database. Stash stores the downloaded files temporarily before inserting into the targeted database.Finally, when the restore process is complete, the Job sends Prometheus metrics to the Pushgateway and update the
RestoreSession
status to reflect restore completion.
Next Steps
- Backup your Etcd database using Stash following the guide from here.