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.
PostgreSQL Backup & Restore Overview
KubeDB also uses KubeStash to backup and restore databases. KubeStash by AppsCode is a cloud native data backup and recovery solution for Kubernetes workloads and databases. KubeStash 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 KubeStash takes backup of a PostgreSQL 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. This secret holds the credentials to access the backend where the backed up data will be stored.
- Then, she creates a - BackupStoragecustom resource that specifies the backend information, along with the- Secretcontaining the credentials needed to access the backend.
- KubeStash operator watches for - BackupStoragecustom resources. When it finds a- BackupStorageobject, it initializes the- BackupStorageby uploading the- metadata.yamlfile to the specified backend.
- Next, she creates a - BackupConfigurationcustom resource that specifies the target database, addon information (including backup tasks), backup schedules, storage backends for storing the backup data, and other additional settings.
- KubeStash operator watches for - BackupConfigurationobjects.
- Once the KubeStash operator finds a - BackupConfigurationobject, it creates- Repositorywith the information specified in the- BackupConfiguration.
- KubeStash operator watches for - Repositorycustom resources. When it finds the- Repositoryobject, it Initializes- Repositoryby uploading- repository.yamlfile into the- spec.sessions[*].repositories[*].directorypath specified in- BackupConfiguration.
- Then, it creates a - CronJobfor each session with the schedule specified in- BackupConfigurationto trigger backup periodically.
- KubeStash operator triggers an instant backup as soon as the - BackupConfigurationis ready. Backups are otherwise triggered by the- CronJobbased on the specified schedule.
- KubeStash operator watches for - BackupSessioncustom resources.
- When it finds a - BackupSessionobject, it creates a- Snapshotcustom resource for each- Repositoryspecified in the- BackupConfiguration.
- Then it resolves the respective - Addonand- Functionand prepares backup- Jobdefinition.
- Then, it creates the - Jobto backup the targeted- PostgreSQLdatabase.
- The backup - Jobreads necessary information (e.g. auth secret, port) to connect with the database from the- AppBindingCR. It also reads backend information and access credentials from- BackupStorageCR, Storage Secret and- Repositorypath respectively.
- Then, the - Jobdumps the targeted- PostgreSQLdatabase and uploads the output to the backend. KubeStash pipes the output of dump command to uploading process. Hence, backup- Jobdoes not require a large volume to hold the entire dump output.
- After the backup process is completed, the backup - Jobupdates the- status.components[dump]field of the- Snapshotresources with backup information of the target- PostgreSQLdatabase.
How Restore Process Works
The following diagram shows how KubeStash restores backed up data into a PostgreSQL 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 - PostgreSQLdatabase where the data will be restored or the user can use the same- PostgreSQLdatabase.
- Then, she creates a - RestoreSessioncustom resource that specifies the target database where the backed-up data will be restored, addon information (including restore tasks), the target snapshot to be restored, the Repository containing that snapshot, and other additional settings.
- KubeStash operator watches for - RestoreSessioncustom resources.
- When it finds a - RestoreSessioncustom resource, it resolves the respective- Addonand- Functionand prepares a restore- Jobdefinition.
- Then, it creates the - Jobto restore the target.
- The - Jobreads necessary information to connect with the database from respective- AppBindingCR. It also reads backend information and access credentials from- RepositoryCR and storage- Secretrespectively.
- Then, the - Jobdownloads the backed up data from the backend and injects into the desired database. KubeStash pipes the downloaded data to the respective database tool to inject into the database. Hence, restore- Jobdoes not require a large volume to download entire backup data inside it.
- Finally, when the restore process is completed, the - Jobupdates the- status.components[*]field of the- RestoreSessionwith restore information of the target database.
Next Steps
- Backup a PostgreSQLdatabase using KubeStash by the following guides from here.































