diff --git a/docs/guides/mysql/backup/kubestash/auto-backup/index.md b/docs/guides/mysql/backup/kubestash/auto-backup/index.md index 0159b9a939..b5b2cd920d 100644 --- a/docs/guides/mysql/backup/kubestash/auto-backup/index.md +++ b/docs/guides/mysql/backup/kubestash/auto-backup/index.md @@ -329,7 +329,7 @@ Once a backup is complete, KubeStash will update the respective `Repository` CR ```bash $ kubectl get repository -n demo default-blueprint -NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE default-blueprint true 1 806 B Ready 8m27s 9m18s ``` diff --git a/docs/guides/mysql/backup/kubestash/customization/index.md b/docs/guides/mysql/backup/kubestash/customization/index.md index 3191e7d6c3..0cdd97ef58 100644 --- a/docs/guides/mysql/backup/kubestash/customization/index.md +++ b/docs/guides/mysql/backup/kubestash/customization/index.md @@ -281,6 +281,7 @@ spec: KubeStash also uses `mysql` during the restore process. In this section, we are going to show how you can pass arguments to the restore process, restore a specific snapshot, run restore job as a specific user, etc. + ### Passing arguments to the restore process Similar to the backup process, you can pass arguments to the restore process through the `args` params under `addon.tasks[*].params` section. diff --git a/docs/guides/postgres/backup/kubestash/application-level/index.md b/docs/guides/postgres/backup/kubestash/application-level/index.md index 7e7c0a63a4..6cc1d97d44 100644 --- a/docs/guides/postgres/backup/kubestash/application-level/index.md +++ b/docs/guides/postgres/backup/kubestash/application-level/index.md @@ -497,6 +497,7 @@ gcs-postgres-repo-sample-postgres-backup-frequent-backup-1725449400 gcs-postgr ``` > Note: KubeStash creates a `Snapshot` with the following labels: +> - `kubedb.com/db-version: ` > - `kubestash.com/app-ref-kind: ` > - `kubestash.com/app-ref-name: ` > - `kubestash.com/app-ref-namespace: ` @@ -519,6 +520,7 @@ metadata: - kubestash.com/cleanup generation: 1 labels: + kubedb.com/db-version: "16.1" kubestash.com/app-ref-kind: Postgres kubestash.com/app-ref-name: sample-postgres kubestash.com/app-ref-namespace: demo @@ -630,7 +632,6 @@ spec: manifestOptions: postgres: restoreNamespace: dev - db: true dataSource: repository: gcs-postgres-repo snapshot: latest @@ -682,6 +683,7 @@ sample-postgres 16.1 Ready 9m46s The output confirms that the `PostgreSQL` database has been successfully created with the same configuration as it had at the time of backup. + #### Verify Restored Data: In this section, we are going to verify whether the desired data has been restored successfully. We are going to connect to the database server and check whether the database and the table we created earlier in the original database are restored. @@ -740,15 +742,6 @@ demo=# \d public | company | table | postgres (1 row) -# Verify that the sample data has been restored -demo=# SELECT * FROM COMPANY; - name | employee --------------+---------- - TechCorp | 100 - InnovateInc | 150 - AlphaTech | 200 -(3 rows) - # disconnect from the database demo=# \q diff --git a/docs/guides/postgres/backup/kubestash/auto-backup/index.md b/docs/guides/postgres/backup/kubestash/auto-backup/index.md index a18b1be1b2..f7c4edde7c 100644 --- a/docs/guides/postgres/backup/kubestash/auto-backup/index.md +++ b/docs/guides/postgres/backup/kubestash/auto-backup/index.md @@ -44,6 +44,7 @@ namespace/demo created > **Note:** YAML files used in this tutorial are stored in [docs/guides/postgres/backup/kubestash/auto-backup/examples](https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/postgres/backup/kubestash/auto-backup/examples) directory of [kubedb/docs](https://github.com/kubedb/docs) repository. + ### Prepare Backend We are going to store our backed up data into a `GCS` bucket. We have to create a `Secret` with necessary credentials and a `BackupStorage` CR to use this backend. If you want to use a different backend, please read the respective backend configuration doc from [here](https://kubestash.com/docs/latest/guides/backends/overview/). @@ -160,6 +161,7 @@ spec: from: All backupConfigurationTemplate: deletionPolicy: OnDelete + # ============== Blueprint for Backends of BackupConfiguration ================= backends: - name: gcs-backend storageRef: @@ -168,6 +170,7 @@ spec: retentionPolicy: name: demo-retention namespace: demo + # ============== Blueprint for Sessions of BackupConfiguration ================= sessions: - name: frequent-backup sessionHistoryLimit: 3 @@ -390,6 +393,7 @@ default-blueprint-appbinding-samgres-frequent-backup-1725533628 default-bluepr ``` > Note: KubeStash creates a `Snapshot` with the following labels: +> - `kubedb.com/db-version: ` > - `kubestash.com/app-ref-kind: ` > - `kubestash.com/app-ref-name: ` > - `kubestash.com/app-ref-namespace: ` @@ -553,6 +557,7 @@ backupblueprint.core.kubestash.com/postgres-customize-backup-blueprint created Now, we are ready to backup our `PostgreSQL` databases using few annotations. You can check available auto-backup annotations for a databases from [here](https://kubestash.com/docs/latest/concepts/crds/backupblueprint/). + **Create Database** Now, we are going to create an `PostgreSQL` CR in demo namespace. @@ -727,6 +732,7 @@ appbinding-sample-postgres-frequent-backup-1725597000 BackupConfiguration We can see from the above output that the backup session has succeeded. Now, we are going to verify whether the backed up data has been stored in the backend. + **Verify Backup:** Once a backup is complete, KubeStash will update the respective `Repository` CR to reflect the backup. Check that the repository `customize-blueprint` has been updated by the following command, diff --git a/docs/guides/postgres/backup/kubestash/customization/index.md b/docs/guides/postgres/backup/kubestash/customization/index.md index 40cc2a3ddf..e3f260206a 100644 --- a/docs/guides/postgres/backup/kubestash/customization/index.md +++ b/docs/guides/postgres/backup/kubestash/customization/index.md @@ -279,35 +279,6 @@ spec: `KubeStash` uses [psql](https://www.postgresql.org/docs/current/app-psql.html) during the restore process. In this section, we are going to show how you can pass arguments to the restore process, restore a specific snapshot, run restore job as a specific user, etc. -### Passing arguments to the restore process - -You can pass any supported `psql` arguments to the restore process using the `args` field within the `addon.tasks[*].params` section. This example demonstrates how to specify a database `testdb` to connect to during the restore process. - -```yaml -apiVersion: core.kubestash.com/v1alpha1 -kind: RestoreSession -metadata: - name: sample-postgres-restore - namespace: demo -spec: - target: - apiGroup: kubedb.com - kind: Postgres - namespace: demo - name: restored-postgres - dataSource: - repository: gcs-postgres-repo - snapshot: latest - encryptionSecret: - name: encrypt-secret - namespace: demo - addon: - name: postgres-addon - tasks: - - name: logical-backup-restore - params: - args: --dbname=testdb -``` ### Restore specific snapshot @@ -348,6 +319,7 @@ spec: - name: logical-backup-restore ``` + ### Running restore job as a specific user Similar to the backup process under the `addon.jobTemplate.spec.` you can provide `securityContext` to run the restore job as a specific user. diff --git a/docs/guides/postgres/backup/kubestash/logical/index.md b/docs/guides/postgres/backup/kubestash/logical/index.md index b2ef2a55c7..731a012df7 100644 --- a/docs/guides/postgres/backup/kubestash/logical/index.md +++ b/docs/guides/postgres/backup/kubestash/logical/index.md @@ -497,6 +497,7 @@ gcs-postgres-repo-sample-postgres-backup-frequent-backup-1725449400 gcs-postgr ``` > Note: KubeStash creates a `Snapshot` with the following labels: +> - `kubedb.com/db-version: ` > - `kubestash.com/app-ref-kind: ` > - `kubestash.com/app-ref-name: ` > - `kubestash.com/app-ref-namespace: ` @@ -587,6 +588,7 @@ Now, if we navigate to the GCS bucket, we will see the backed up data stored in > Note: KubeStash stores all dumped data encrypted in the backup directory, meaning it remains unreadable until decrypted. + ## Restore In this section, we are going to restore the database from the backup we have taken in the previous section. We are going to deploy a new database and initialize it from the backup. @@ -631,7 +633,7 @@ If you check the database status, you will see it is stuck in **`Provisioning`** ```bash $ kubectl get postgres -n demo restored-postgres -NAME VERSION STATUS AGE +NAME VERSION STATUS AGE restored-postgres 8.2.0 Provisioning 61s ``` @@ -674,7 +676,7 @@ Here, Let's create the RestoreSession CRD object we have shown above, ```bash -$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/postgres/backup/kubestash/logical/examples/restoresession.yaml +$ kubectl apply -f **https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/postgres/backup/kubestash/logical/examples/restoresession.yaml restoresession.core.kubestash.com/sample-postgres-restore created ``` @@ -764,6 +766,7 @@ demo=# \q So, from the above output, we can see the `demo` database we had created in the original database `sample-postgres` has been restored in the `restored-postgres` database. + ## Cleanup To cleanup the Kubernetes resources created by this tutorial, run: @@ -771,10 +774,10 @@ To cleanup the Kubernetes resources created by this tutorial, run: ```bash kubectl delete backupconfigurations.core.kubestash.com -n demo sample-postgres-backup kubectl delete restoresessions.core.kubestash.com -n demo restore-sample-postgres -kubectl delete retentionpolicies.storage.kubestash.com -n demo demo-retention kubectl delete backupstorage -n demo gcs-storage kubectl delete secret -n demo gcs-secret kubectl delete secret -n demo encrypt-secret +kubectl delete retentionpolicies.storage.kubestash.com -n demo demo-retention kubectl delete postgres -n demo restored-postgres kubectl delete postgres -n demo sample-postgres ``` \ No newline at end of file diff --git a/docs/guides/singlestore/backup/_index.md b/docs/guides/singlestore/backup/_index.md new file mode 100644 index 0000000000..f6b4e6f801 --- /dev/null +++ b/docs/guides/singlestore/backup/_index.md @@ -0,0 +1,10 @@ +--- +title: Backup & Restore SingleStore +menu: + docs_{{ .version }}: + identifier: guides-sdb-backup + name: Backup & Restore + parent: guides-singlestore + weight: 40 +menu_name: docs_{{ .version }} +--- diff --git a/docs/guides/singlestore/backup/kubestash/_index.md b/docs/guides/singlestore/backup/kubestash/_index.md new file mode 100644 index 0000000000..566ec1e175 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/_index.md @@ -0,0 +1,10 @@ +--- +title: Backup & Restore SingleStore | KubeStash +menu: + docs_{{ .version }}: + identifier: guides-sdb-backup-stashv2 + name: KubeStash (aka Stash 2.0) + parent: guides-sdb-backup + weight: 50 +menu_name: docs_{{ .version }} +--- diff --git a/docs/guides/singlestore/backup/kubestash/application-level/examples/backupconfiguration.yaml b/docs/guides/singlestore/backup/kubestash/application-level/examples/backupconfiguration.yaml new file mode 100644 index 0000000000..4f82f73efe --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/application-level/examples/backupconfiguration.yaml @@ -0,0 +1,37 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: manifest-backup + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/application-level/examples/backupstorage.yaml b/docs/guides/singlestore/backup/kubestash/application-level/examples/backupstorage.yaml new file mode 100644 index 0000000000..6ab3df02ac --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/application-level/examples/backupstorage.yaml @@ -0,0 +1,17 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: BackupStorage +metadata: + name: gcs-storage + namespace: demo +spec: + storage: + provider: gcs + gcs: + bucket: kubestash-qa + prefix: demo + secretName: gcs-secret + usagePolicy: + allowedNamespaces: + from: All + default: true + deletionPolicy: Delete \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/application-level/examples/restoresession.yaml b/docs/guides/singlestore/backup/kubestash/application-level/examples/restoresession.yaml new file mode 100644 index 0000000000..252e0c69e4 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/application-level/examples/restoresession.yaml @@ -0,0 +1,20 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + manifestOptions: + singlestore: + restoreNamespace: dev + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup-restore + - name: manifest-restore \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/application-level/examples/retentionpolicy.yaml b/docs/guides/singlestore/backup/kubestash/application-level/examples/retentionpolicy.yaml new file mode 100644 index 0000000000..4591562860 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/application-level/examples/retentionpolicy.yaml @@ -0,0 +1,15 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: RetentionPolicy +metadata: + name: demo-retention + namespace: demo +spec: + default: true + failedSnapshots: + last: 2 + maxRetentionPeriod: 2mo + successfulSnapshots: + last: 5 + usagePolicy: + allowedNamespaces: + from: All \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/application-level/examples/sample-singlestore.yaml b/docs/guides/singlestore/backup/kubestash/application-level/examples/sample-singlestore.yaml new file mode 100644 index 0000000000..a3510d8591 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/application-level/examples/sample-singlestore.yaml @@ -0,0 +1,50 @@ +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sample-singlestore + namespace: demo +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/application-level/index.md b/docs/guides/singlestore/backup/kubestash/application-level/index.md new file mode 100644 index 0000000000..64b7929728 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/application-level/index.md @@ -0,0 +1,841 @@ +--- +title: Application Level Backup & Restore SingleStore | KubeStash +description: Application Level Backup and Restore using KubeStash +menu: + docs_{{ .version }}: + identifier: guides-application-level-backup-stashv2 + name: Application Level Backup + parent: guides-sdb-backup-stashv2 + weight: 40 +menu_name: docs_{{ .version }} +section_menu_id: guides +--- + +# Application Level Backup and Restore SingleStore database using KubeStash + +KubeStash offers application-level backup and restore functionality for `SingleStore` databases. It captures both manifest and logical data backups of any `SingleStore` database in a single snapshot. During the restore process, KubeStash first applies the `SingleStore` manifest to the cluster and then restores the data into it. + +This guide will give you how you can take application-level backup and restore your `SingleStore` databases using `Kubestash`. + +## Before You Begin + +- At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using `Minikube` or `Kind`. +- Install `KubeDB` in your cluster following the steps [here](/docs/setup/README.md). +- Install `KubeStash` in your cluster following the steps [here](https://kubestash.com/docs/latest/setup/install/kubestash). +- Install KubeStash `kubectl` plugin following the steps [here](https://kubestash.com/docs/latest/setup/install/kubectl-plugin/). +- If you are not familiar with how KubeStash backup and restore SingleStore databases, please check the following guide [here](/docs/guides/singlestore/backup/kubestash/overview/index.md). + +You should be familiar with the following `KubeStash` concepts: + +- [BackupStorage](https://kubestash.com/docs/latest/concepts/crds/backupstorage/) +- [BackupConfiguration](https://kubestash.com/docs/latest/concepts/crds/backupconfiguration/) +- [BackupSession](https://kubestash.com/docs/latest/concepts/crds/backupsession/) +- [RestoreSession](https://kubestash.com/docs/latest/concepts/crds/restoresession/) +- [Addon](https://kubestash.com/docs/latest/concepts/crds/addon/) +- [Function](https://kubestash.com/docs/latest/concepts/crds/function/) +- [Task](https://kubestash.com/docs/latest/concepts/crds/addon/#task-specification) + +To keep everything isolated, we are going to use a separate namespace called `demo` throughout this tutorial. + +```bash +$ kubectl create ns demo +namespace/demo created +``` + +> **Note:** YAML files used in this tutorial are stored in [docs/guides/singlestore/backup/kubestash/application-level/examples](/docs/guides/singlestore/backup/kubestash/application-level/examples) directory of [kubedb/docs](https://github.com/kubedb/docs) repository. + +## Backup SingleStore + +KubeStash supports backups for `SingleStore` instances across different configurations, including Standalone, and Cluster setups. In this demonstration, we'll focus on a `SingleStore` database using singlestore clustering. The backup and restore process is similar for Standalone and Cluster configurations as well. + +This section will demonstrate how to take application-level backup of a `SingleStore` database. Here, we are going to deploy a `SingleStore` database using KubeDB. Then, we are going to back up the database at the application level to a `GCS` bucket. Finally, we will restore the entire `SingleStore` database. + +### Create SingleStore License Secret + +We need SingleStore License to create SingleStore Database. So, Ensure that you have acquired a license and then simply pass the license by secret. + +```bash +$ kubectl create secret generic -n demo license-secret \ + --from-literal=username=license \ + --from-literal=password='your-license-set-here' +secret/license-secret created +``` + +### Deploy Sample SingleStore Database + +Let's deploy a sample `SingleStore` database and insert some data into it. + +**Create SingleStore CR:** + +Below is the YAML of a sample `SingleStore` CR that we are going to create for this tutorial: + +```yaml +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sample-singlestore + namespace: demo +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut +``` + + +Here, + +- `spec.version` is the name of the SinglestoreVersion CRD where the docker images are specified. In this tutorial, a SingleStore `8.7.10` database is going to be created. +- `spec.topology` specifies that it will be used as cluster mode. If this field is nil it will be work as standalone mode. +- `spec.topology.aggregator.replicas` or `spec.topology.leaf.replicas` specifies that the number replicas that will be used for aggregator or leaf. +- `spec.storageType` specifies the type of storage that will be used for SingleStore database. It can be `Durable` or `Ephemeral`. Default value of this field is `Durable`. If `Ephemeral` is used then KubeDB will create SingleStore database using `EmptyDir` volume. In this case, you don't have to specify `spec.storage` field. This is useful for testing purposes. +- `spec.topology.aggregator.storage` or `spec.topology.leaf.storage` specifies the StorageClass of PVC dynamically allocated to store data for this database. This storage spec will be passed to the PetSet created by KubeDB operator to run database pods. You can specify any StorageClass available in your cluster with appropriate resource requests. +- `spec.deletionPolicy` gives flexibility whether to `nullify`(reject) the delete operation of `Singlestore` crd or which resources KubeDB should keep or delete when you delete `Singlestore` crd. If admission webhook is enabled, It prevents users from deleting the database as long as the `spec.deletionPolicy` is set to `DoNotTerminate`. Learn details of all `DeletionPolicy` [here](/docs/guides/mysql/concepts/database/index.md#specdeletionpolicy) + +> Note: `spec.storage` section is used to create PVC for database pod. It will create PVC with storage size specified in `storage.resources.requests` field. Don't specify limits here. PVC does not get resized automatically. + +Create the above `SingleStore` CR, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/application-level/examples/sample-singlestore.yaml +singlestore.kubedb.com/sample-singlestore created +``` + +KubeDB will deploy a SingleStore database according to the above specification. It will also create the necessary Secrets and Services to access the database. + +Let's check if the database is ready to use, + +```bash +$ kubectl get singlestores.kubedb.com -n demo +NAME VERSION STATUS AGE +sample-singlestore 8.7.10 Ready 4m22s +``` + +The database is `Ready`. Verify that KubeDB has created a `Secret` and a `Service` for this database using the following commands, + +```bash +$ kubectl get secret -n demo -l=app.kubernetes.io/instance=sample-singlestore +NAME TYPE DATA AGE +sample-singlestore-root-cred kubernetes.io/basic-auth 2 4m58s + +$ kubectl get service -n demo -l=app.kubernetes.io/instance=sample-singlestore +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +sample-singlestore ClusterIP 10.128.230.168 3306/TCP,8081/TCP 5m10s +sample-singlestore-pods ClusterIP None 3306/TCP 5m10s + +``` + +Here, we have to use service `sample-singlestore` and secret `sample-singlestore-root-cred` to connect with the database. `KubeDB` creates an [AppBinding](/docs/guides/mysql/concepts/appbinding/index.md) CR that holds the necessary information to connect with the database. + +**Verify AppBinding:** + +Verify that the `AppBinding` has been created successfully using the following command, + +```bash +$ kubectl get appbindings -n demo +NAME AGE +sample-singlestore 9m24s +``` + +Let's check the YAML of the above `AppBinding`, + +```bash +$ kubectl get appbindings -n demo sample-singlestore -o yaml +``` + +```yaml +apiVersion: appcatalog.appscode.com/v1alpha1 +kind: AppBinding +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"kubedb.com/v1alpha2","kind":"Singlestore","metadata":{"annotations":{},"name":"sample-singlestore","namespace":"demo"},"spec":{"deletionPolicy":"WipeOut","licenseSecret":{"name":"license-secret"},"storageType":"Durable","topology":{"aggregator":{"podTemplate":{"spec":{"containers":[{"name":"singlestore","resources":{"limits":{"cpu":"0.6","memory":"2Gi"},"requests":{"cpu":"0.6","memory":"2Gi"}}}]}},"replicas":2,"storage":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"1Gi"}}}},"leaf":{"podTemplate":{"spec":{"containers":[{"name":"singlestore","resources":{"limits":{"cpu":"0.6","memory":"2Gi"},"requests":{"cpu":"0.6","memory":"2Gi"}}}]}},"replicas":3,"storage":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"10Gi"}}}}},"version":"8.7.10"}} + creationTimestamp: "2024-09-11T07:03:44Z" + generation: 1 + labels: + app.kubernetes.io/component: database + app.kubernetes.io/instance: sample-singlestor + app.kubernetes.io/managed-by: kubedb.com + app.kubernetes.io/name: singlestores.kubedb.com + name: sample-singlestore + namespace: demo + ownerReferences: + - apiVersion: kubedb.com/v1alpha2 + blockOwnerDeletion: true + controller: true + kind: Singlestore + name: sample-singlestore + uid: e08e1f37-d869-437d-9b15-14c6aef3f406 + resourceVersion: "4904220" + uid: 92b2b318-1874-4471-97ec-d789c6e16809 +spec: + appRef: + apiGroup: kubedb.com + kind: Singlestore + name: sample-singlestore + namespace: demo + clientConfig: + service: + name: sample-singlestore + path: / + port: 3306 + scheme: tcp + url: tcp(sample-singlestore.demo.svc:3306)/ + parameters: + apiVersion: config.kubedb.com/v1alpha1 + kind: SinglestoreConfiguration + masterAggregator: sample-singlestore-aggregator-0.sample-singlestore-pods.demo.svc + stash: + addon: + backupTask: + name: "" + restoreTask: + name: "" + secret: + name: sample-singlestore-root-cred + type: kubedb.com/singlestore + version: 8.7.10 + +``` + +KubeStash uses the `AppBinding` CR to connect with the target database. It requires the following two fields to set in AppBinding's `.spec` section. + +- `.spec.parameters.masterAggregator` specifies the dns of master aggregator node that we have to mention in mysqldump command when taken backup or restore. +- `.spec.clientConfig.service.name` specifies the name of the Service that connects to the database. +- `.spec.secret` specifies the name of the Secret that holds necessary credentials to access the database. +- `spec.type` specifies the types of the app that this AppBinding is pointing to. KubeDB generated AppBinding follows the following format: `/`. + +**Insert Sample Data:** + +Now, we are going to exec into the any aggregator pod and create some sample data. At first, find out the database `Pod` using the following command, + +```bash +$ kubectl get pods -n demo --selector="app.kubernetes.io/instance=sample-singlestore" +NAME READY STATUS RESTARTS AGE +sample-singlestore-aggregator-0 2/2 Running 0 15m +sample-singlestore-aggregator-1 2/2 Running 0 15m +sample-singlestore-leaf-0 2/2 Running 0 15m +sample-singlestore-leaf-1 2/2 Running 0 15m +sample-singlestore-leaf-2 2/2 Running 0 15m +``` + +And copy the username and password of the `root` user to access into `memsql` shell. + +```bash +$ kubectl get secret -n demo sample-singlestore-root-cred -o jsonpath='{.data.username}'| base64 -d +root⏎ + +kubectl get secret -n demo sample-singlestore-root-cred -o jsonpath='{.data.password}'| base64 -d +xEJv73q3w_m1~H.G⏎ +``` + +Now, Lets exec into the any aggregator `Pod` to enter into `mysql` shell and create a database and a table, + +```bash +$ kubectl exec -it -n demo sample-singlestore-aggregator-0 -- singlestore --user=root --password=xEJv73q3w_m1~H.G +Defaulted container "singlestore" out of: singlestore, singlestore-coordinator, singlestore-init (init) +singlestore-client: [Warning] Using a password on the command line interface can be insecure. +Welcome to the MySQL monitor. Commands end with ; or \g. +Your MySQL connection id is 300070 +Server version: 5.7.32 SingleStoreDB source distribution (compatible; MySQL Enterprise & MySQL Commercial) + +Copyright (c) 2000, 2022, Oracle and/or its affiliates. + +Oracle is a registered trademark of Oracle Corporation and/or its +affiliates. Other names may be trademarks of their respective +owners. + +Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. + +singlestore> CREATE DATABASE playground partitions 2; +Query OK, 1 row affected (0.01 sec) + +singlestore> show databases; ++--------------------+ +| Database | ++--------------------+ +| cluster | +| demo | +| det | +| information_schema | +| memsql | +| playground | +| singlestore_health | +| test | ++--------------------+ +8 rows in set (0.00 sec) + +singlestore> CREATE TABLE playground.equipment ( id INT NOT NULL AUTO_INCREMENT, type VARCHAR(50), quant INT, color VARCHAR(25), PRIMARY KEY(id)); +Query OK, 0 rows affected, 1 warning (0.27 sec) + +singlestore> SHOW TABLES IN playground; ++----------------------+ +| Tables_in_playground | ++----------------------+ +| equipment | ++----------------------+ +1 row in set (0.00 sec) + +singlestore> INSERT INTO playground.equipment (type, quant, color) VALUES ("slide", 2, "blue"); +Query OK, 1 row affected (1.15 sec) + +singlestore> SELECT * FROM playground.equipment; ++----+-------+-------+-------+ +| id | type | quant | color | ++----+-------+-------+-------+ +| 1 | slide | 2 | blue | ++----+-------+-------+-------+ +1 row in set (0.14 sec) + +singlestore> exit +Bye + +``` + +Now, we are ready to backup the database. + +### Prepare Backend + +We are going to store our backed up data into a GCS bucket. We have to create a Secret with necessary credentials and a `BackupStorage` CR to use this backend. If you want to use a different backend, please read the respective backend configuration doc from [here](https://kubestash.com/docs/latest/guides/backends/overview/). + +**Create Secret:** + +Let's create a secret called `gcs-secret` with access credentials to our desired GCS bucket, + +```bash +$ echo -n '' > GOOGLE_PROJECT_ID +$ cat /path/to/downloaded-sa-key.json > GOOGLE_SERVICE_ACCOUNT_JSON_KEY +$ kubectl create secret generic -n demo gcs-secret \ + --from-file=./GOOGLE_PROJECT_ID \ + --from-file=./GOOGLE_SERVICE_ACCOUNT_JSON_KEY +secret/gcs-secret created +``` + +**Create BackupStorage:** + +Now, create a `BackupStorage` using this secret. Below is the YAML of `BackupStorage` CR we are going to create, + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: BackupStorage +metadata: + name: gcs-storage + namespace: demo +spec: + storage: + provider: gcs + gcs: + bucket: kubestash-qa + prefix: demo + secretName: gcs-secret + usagePolicy: + allowedNamespaces: + from: All + default: true + deletionPolicy: Delete +``` + +Let's create the BackupStorage we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/application-level/examples/backupstorage.yaml +backupstorage.storage.kubestash.com/gcs-storage created +``` + +Now, we are ready to backup our database to our desired backend. + +**Create RetentionPolicy:** + +Now, let's create a `RetentionPolicy` to specify how the old Snapshots should be cleaned up. + +Below is the YAML of the `RetentionPolicy` object that we are going to create, + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: RetentionPolicy +metadata: + name: demo-retention + namespace: demo +spec: + default: true + failedSnapshots: + last: 2 + maxRetentionPeriod: 2mo + successfulSnapshots: + last: 5 + usagePolicy: + allowedNamespaces: + from: All +``` + +Let’s create the above `RetentionPolicy`, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/application-level/examples/retentionpolicy.yaml +retentionpolicy.storage.kubestash.com/demo-retention created +``` + +### Backup + +We have to create a `BackupConfiguration` targeting respective `sample-singlestore` SingleStore database. Then, KubeStash will create a `CronJob` for each session to take periodic backup of that database. + +At first, we need to create a secret with a Restic password for backup data encryption. + +**Create Secret:** + +Let's create a secret called `encrypt-secret` with the Restic password, + +```bash +$ echo -n 'changeit' > RESTIC_PASSWORD +$ kubectl create secret generic -n demo encrypt-secret \ + --from-file=./RESTIC_PASSWORD \ +secret "encrypt-secret" created +``` + +**Create BackupConfiguration:** + +Below is the YAML for `BackupConfiguration` CR to take application-level backup of the `sample-singlestore` database that we have deployed earlier, + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: manifest-backup + - name: logical-backup +``` + +- `.spec.sessions[*].schedule` specifies that we want to backup at `5 minutes` interval. +- `.spec.target` refers to the targeted `sample-singlestore` SingleStore database that we created earlier. +- `.spec.sessions[*].addon.tasks[*].name[*]` specifies that both the `manifest-backup` and `logical-backup` tasks will be executed. + +Let's create the `BackupConfiguration` CR that we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/application-level/examples/backupconfiguration.yaml +backupconfiguration.core.kubestash.com/sample-singlestore-backup created +``` + +**Verify Backup Setup Successful** + +If everything goes well, the phase of the `BackupConfiguration` should be `Ready`. The `Ready` phase indicates that the backup setup is successful. Let's verify the `Phase` of the BackupConfiguration, + +```bash +$ kubectl get backupconfiguration -n demo +NAME PHASE PAUSED AGE +sample-singlestore-backup Ready 2m50s +``` + +Additionally, we can verify that the `Repository` specified in the `BackupConfiguration` has been created using the following command, + +```bash +$ kubectl get repo -n demo +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +gcs-singlestore-repo 0 0 B Ready 3m +``` + +KubeStash keeps the backup for `Repository` YAMLs. If we navigate to the GCS bucket, we will see the `Repository` YAML stored in the `demo/singlestore` directory. + +**Verify CronJob:** + +It will also create a `CronJob` with the schedule specified in `spec.sessions[*].scheduler.schedule` field of `BackupConfiguration` CR. + +Verify that the `CronJob` has been created using the following command, + +```bash +$ kubectl get cronjob -n demo +NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE +trigger-sample-singlestore-backup-frequent-backup */5 * * * * 0 2m45s 3m25s +``` + +**Verify BackupSession:** + +KubeStash triggers an instant backup as soon as the `BackupConfiguration` is ready. After that, backups are scheduled according to the specified schedule. + +Run the following command to watch `BackupSession` CR, + +```bash +$ kubectl get backupsession -n demo -w + +NAME INVOKER-TYPE INVOKER-NAME PHASE DURATION AGE +sample-singlestore-backup-frequent-backup-1724065200 BackupConfiguration sample-singlestore-backup Succeeded 7m22s +``` + +We can see from the above output that the backup session has succeeded. Now, we are going to verify whether the backed up data has been stored in the backend. + +**Verify Backup:** + +Once a backup is complete, KubeStash will update the respective `Repository` CR to reflect the backup. Check that the repository `sample-singlestore-backup` has been updated by the following command, + +```bash +$ kubectl get repository -n demo gcs-singlestore-repo +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +gcs-singlestore-repo true 1 806 B Ready 8m27s 9m18s +``` + +At this moment we have one `Snapshot`. Run the following command to check the respective `Snapshot` which represents the state of a backup run for an application. + +```bash +$ kubectl get snapshots -n demo -l=kubestash.com/repo-name=gcs-demo-repo +NAME REPOSITORY SESSION SNAPSHOT-TIME DELETION-POLICY PHASE AGE +gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725359100 sample-singlestore-backup frequent-backup 2024-01-23T13:10:54Z Delete Succeeded 16h +``` + +> Note: KubeStash creates a `Snapshot` with the following labels: +> - `kubestash.com/app-ref-kind: ` +> - `kubestash.com/app-ref-name: ` +> - `kubestash.com/app-ref-namespace: ` +> - `kubestash.com/repo-name: ` +> +> These labels can be used to watch only the `Snapshot`s related to our target Database or `Repository`. + +If we check the YAML of the `Snapshot`, we can find the information about the backed up components of the Database. + +```bash +$ kubectl get snapshots -n demo gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725359100 -oyaml +``` + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: Snapshot +metadata: + creationTimestamp: "2024-09-03T10:25:00Z" + finalizers: + - kubestash.com/cleanup + generation: 1 + labels: + kubestash.com/app-ref-kind: Singlestore + kubestash.com/app-ref-name: sample-singlestore + kubestash.com/app-ref-namespace: demo + kubestash.com/repo-name: gcs-singlestore-repo + annotations: + kubedb.com/db-version: 8.7.10 + name: gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725359100 + namespace: demo + ownerReferences: + - apiVersion: storage.kubestash.com/v1alpha1 + blockOwnerDeletion: true + controller: true + kind: Repository + name: gcs-singlestore-repo + uid: 1f5ba355-7f99-4b99-8bbf-9f9d4f31c52a + resourceVersion: "213010" + uid: 18cabb10-e594-4655-8763-3daa0872508e +spec: + appRef: + apiGroup: kubedb.com + kind: Singlestore + name: sample-singlestore + namespace: demo + backupSession: sample-singlestore-backup-frequent-backup-1725359100 + deletionPolicy: Delete + repository: gcs-singlestore-repo + session: frequent-backup + snapshotID: 01J6VPN4TPHDFT1M9Q9YVGMTKF + type: FullBackup + version: v1 +status: + components: + dump: + driver: Restic + duration: 7.393324414s + integrity: true + path: repository/v1/frequent-backup/dump + phase: Succeeded + resticStats: + - hostPath: dumpfile.sql + id: f2ffd1bdb98563e15c46d8927d7239873ce7094132d959e12134688e06984736 + size: 3.657 MiB + uploaded: 706.081 KiB + size: 893.009 KiB + manifest: + driver: Restic + duration: 12.672292995s + integrity: true + path: repository/v1/frequent-backup/manifest + phase: Succeeded + resticStats: + - hostPath: /kubestash-tmp/manifest + id: ff99eb7ea769a365f7cdc83a252df610c262fc934ec0a3475499bbbb35ca6931 + size: 2.883 KiB + uploaded: 1.440 KiB + size: 3.788 KiB + conditions: + - lastTransitionTime: "2024-09-03T10:25:00Z" + message: Recent snapshot list updated successfully + reason: SuccessfullyUpdatedRecentSnapshotList + status: "True" + type: RecentSnapshotListUpdated + - lastTransitionTime: "2024-09-03T10:25:49Z" + message: Metadata uploaded to backend successfully + reason: SuccessfullyUploadedSnapshotMetadata + status: "True" + type: SnapshotMetadataUploaded + integrity: true + phase: Succeeded + size: 896.796 KiB + snapshotTime: "2024-09-03T10:25:00Z" + totalComponents: 2 +``` + +> KubeStash uses the `mysqldump` command to take backups of target SingleStore databases. Therefore, the component name for logical backups is set as `dump`. +> KubeStash set component name as `manifest` for the `manifest backup` of SingleStore databases. + +Now, if we navigate to the GCS bucket, we will see the backed up data stored in the `demo/singlestore/repository/v1/frequent-backup/dump` directory. KubeStash also keeps the backup for `Snapshot` YAMLs, which can be found in the `demo/dep/snapshots` directory. + +> Note: KubeStash stores all dumped data encrypted in the backup directory, meaning it remains unreadable until decrypted. + +## Restore + +In this section, we are going to restore the entire database from the backup that we have taken in the previous section. + +For this tutorial, we will restore the database in a separate namespace called `dev`. + +First, create the namespace by running the following command: + +```bash +$ kubectl create ns dev +namespace/dev created +``` + +#### Create RestoreSession: + +We need to create a RestoreSession CR. + +Below, is the contents of YAML file of the `RestoreSession` CR that we are going to create to restore the entire database. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + manifestOptions: + singlestore: + restoreNamespace: dev + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup-restore + - name: manifest-restore +``` + +Here, + +- `.spec.manifestOptions.singlestore.db` specifies whether to restore the DB manifest or not. +- `.spec.dataSource.repository` specifies the Repository object that holds the backed up data. +- `.spec.dataSource.snapshot` specifies to restore from latest `Snapshot`. +- `.spec.addon.tasks[*]` specifies that both the `manifest-restore` and `logical-backup-restore` tasks. + +Let's create the RestoreSession CRD object we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/application-level/examples/restoresession.yaml +restoresession.core.kubestash.com/sample-singlestore-restore created +``` + +Once, you have created the `RestoreSession` object, KubeStash will create restore Job. Run the following command to watch the phase of the `RestoreSession` object, + +```bash +$ watch kubectl get restoresession -n demo +Every 2.0s: kubectl get restores... AppsCode-PC-03: Wed Aug 21 10:44:05 2024 + +NAME REPOSITORY FAILURE-POLICY PHASE DURATION AGE +sample-restore gcs-demo-repo Succeeded 3s 53s +``` +The `Succeeded` phase means that the restore process has been completed successfully. + +#### Verify Restored SingleStore Manifest: + +In this section, we will verify whether the desired `SingleStore` database manifest has been successfully applied to the cluster. + +```bash +$ kubectl get singlestores.kubedb.com -n dev +NAME VERSION STATUS AGE +sample-singlestore 8.7.10 Ready 39m +``` + +The output confirms that the `SingleStore` database has been successfully created with the same configuration as it had at the time of backup. + +#### Verify Restored Data: + +In this section, we are going to verify whether the desired data has been restored successfully. We are going to connect to the database server and check whether the database and the table we created earlier in the original database are restored. + +At first, check if the database has gone into `Ready` state by the following command, + +```bash +$ kubectl get sdb -n dev sample-singlestore +NAME VERSION STATUS AGE +sample-singlestore 8.7.10 Ready 4m +``` + +Now, find out the database `Pod` by the following command, + +```bash +$ kubectl get pods -n demo --selector="app.kubernetes.io/instance=sample-singlestore" +NAME READY STATUS RESTARTS AGE +sample-singlestore-aggregator-0 2/2 Running 0 15m +sample-singlestore-aggregator-1 2/2 Running 0 15m +sample-singlestore-leaf-0 2/2 Running 0 15m +sample-singlestore-leaf-1 2/2 Running 0 15m +sample-singlestore-leaf-2 2/2 Running 0 15m +``` + +And copy the username and password of the `root` user to access into `mysql` shell. + +```bash +$ kubectl get secret -n demo sample-singlestore-root-cred -o jsonpath='{.data.username}'| base64 -d +root⏎ + +kubectl get secret -n demo sample-singlestore-root-cred -o jsonpath='{.data.password}'| base64 -d +xEJv73q3w_m1~H.G⏎ +``` + +Now, Lets exec into the any aggregator `Pod` to enter into `mysql` shell and create a database and a table, + +```bash +$ kubectl exec -it -n demo sample-singlestore-aggregator-0 -- singlestore --user=root --password=xEJv73q3w_m1~H.G +Defaulted container "singlestore" out of: singlestore, singlestore-coordinator, singlestore-init (init) +singlestore-client: [Warning] Using a password on the command line interface can be insecure. +Welcome to the MySQL monitor. Commands end with ; or \g. +Your MySQL connection id is 300070 +Server version: 5.7.32 SingleStoreDB source distribution (compatible; MySQL Enterprise & MySQL Commercial) + +Copyright (c) 2000, 2022, Oracle and/or its affiliates. + +Oracle is a registered trademark of Oracle Corporation and/or its +affiliates. Other names may be trademarks of their respective +owners. + +Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. + +singlestore> show databases; ++--------------------+ +| Database | ++--------------------+ +| cluster | +| demo | +| det | +| information_schema | +| memsql | +| playground | +| singlestore_health | +| test | ++--------------------+ +8 rows in set (0.00 sec) + +singlestore> SHOW TABLES IN playground; ++----------------------+ +| Tables_in_playground | ++----------------------+ +| equipment | ++----------------------+ +1 row in set (0.00 sec) + +singlestore> SELECT * FROM playground.equipment; ++----+-------+-------+-------+ +| id | type | quant | color | ++----+-------+-------+-------+ +| 1 | slide | 2 | blue | ++----+-------+-------+-------+ +1 row in set (0.14 sec) + +singlestore> exit +Bye + +``` + +So, from the above output, we can see that the `playground` database and the `equipment` table we have created earlier in the original database and now, they are restored successfully. + +## Cleanup + +To cleanup the Kubernetes resources created by this tutorial, run: + +```bash +kubectl delete backupconfigurations.core.kubestash.com -n demo sample-singlestore-backup +kubectl delete backupstorage -n demo gcs-storage +kubectl delete secret -n demo gcs-secret +kubectl delete secret -n demo encrypt-secret +kubectl delete retentionpolicies.storage.kubestash.com -n demo demo-retention +kubectl delete restoresessions.core.kubestash.com -n demo restore-sample-singlestore +kubectl delete my -n demo sample-singlestore +kubectl delete my -n dev sample-singlestore +``` \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/auto-backup/examples/backupstorage.yaml b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/backupstorage.yaml new file mode 100644 index 0000000000..f5478706b6 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/backupstorage.yaml @@ -0,0 +1,17 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: BackupStorage +metadata: + name: gcs-storage + namespace: demo +spec: + storage: + provider: gcs + gcs: + bucket: kubestash-qa + prefix: blueprint + secretName: gcs-secret + usagePolicy: + allowedNamespaces: + from: All + default: true + deletionPolicy: Delete \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml new file mode 100644 index 0000000000..83509dc609 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml @@ -0,0 +1,41 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupBlueprint +metadata: + name: singlestore-customize-backup-blueprint + namespace: demo +spec: + usagePolicy: + allowedNamespaces: + from: All + backupConfigurationTemplate: + deletionPolicy: OnDelete + # ============== Blueprint for Backends of BackupConfiguration ================= + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + # ============== Blueprint for Sessions of BackupConfiguration ================= + sessions: + - name: frequent-backup + sessionHistoryLimit: 3 + scheduler: + schedule: ${schedule} + jobTemplate: + backoffLimit: 1 + repositories: + - name: ${repoName} + backend: gcs-backend + directory: ${namespace}/${targetName} + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup + params: + databases: ${targetedDatabases} \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml new file mode 100644 index 0000000000..ed86b82a42 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml @@ -0,0 +1,37 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupBlueprint +metadata: + name: singlestore-default-backup-blueprint + namespace: demo +spec: + usagePolicy: + allowedNamespaces: + from: All + backupConfigurationTemplate: + deletionPolicy: OnDelete + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + sessionHistoryLimit: 3 + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: default-blueprint + backend: gcs-backend + directory: /default-blueprint + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/auto-backup/examples/retentionpolicy.yaml b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/retentionpolicy.yaml new file mode 100644 index 0000000000..4591562860 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/retentionpolicy.yaml @@ -0,0 +1,15 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: RetentionPolicy +metadata: + name: demo-retention + namespace: demo +spec: + default: true + failedSnapshots: + last: 2 + maxRetentionPeriod: 2mo + successfulSnapshots: + last: 5 + usagePolicy: + allowedNamespaces: + from: All \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/auto-backup/examples/sample-singlestore-2.yaml b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/sample-singlestore-2.yaml new file mode 100644 index 0000000000..d951719db8 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/sample-singlestore-2.yaml @@ -0,0 +1,57 @@ +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sample-singlestore-2 + namespace: demo + annotations: + blueprint.kubestash.com/name: singlestore-customize-backup-blueprint + blueprint.kubestash.com/namespace: demo + variables.kubestash.com/schedule: "*/10 * * * *" + variables.kubestash.com/repoName: customize-blueprint + variables.kubestash.com/namespace: demo + variables.kubestash.com/targetName: sample-singlestore-2 +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/auto-backup/examples/sample-singlestore.yaml b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/sample-singlestore.yaml new file mode 100644 index 0000000000..3cafc0950e --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/auto-backup/examples/sample-singlestore.yaml @@ -0,0 +1,53 @@ +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sample-singlestore + namespace: demo + annotations: + blueprint.kubestash.com/name: singlestore-default-backup-blueprint + blueprint.kubestash.com/namespace: demo +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/auto-backup/index.md b/docs/guides/singlestore/backup/kubestash/auto-backup/index.md new file mode 100644 index 0000000000..0fb1a47680 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/auto-backup/index.md @@ -0,0 +1,812 @@ +--- +title: SingleStore Auto-Backup | KubeStash +description: Backup SingleStore using KubeStash Auto-Backup +menu: + docs_{{ .version }}: + identifier: guides-sdb-backup-auto-backup-stashv2 + name: Auto-Backup + parent: guides-sdb-backup-stashv2 + weight: 30 +menu_name: docs_{{ .version }} +section_menu_id: guides +--- + +# Backup SingleStore using KubeStash Auto-Backup + +KubeStash can automatically be configured to backup any `SingleStore` databases in your cluster. KubeStash enables cluster administrators to deploy backup `blueprints` ahead of time so database owners can easily backup any `SingleStore` database with a few annotations. + +In this tutorial, we are going to show how you can configure a backup blueprint for `SingleStore` databases in your cluster and backup them with a few annotations. + +## Before You Begin + +- At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using `Minikube` or `Kind`. +- Install `KubeDB` in your cluster following the steps [here](/docs/setup/README.md). +- Install `KubeStash` in your cluster following the steps [here](https://kubestash.com/docs/latest/setup/install/kubestash). +- Install KubeStash `kubectl` plugin following the steps [here](https://kubestash.com/docs/latest/setup/install/kubectl-plugin/). +- If you are not familiar with how KubeStash backup and restore SingleStore databases, please check the following guide [here](/docs/guides/singlestore/backup/kubestash/overview/index.md). + +You should be familiar with the following `KubeStash` concepts: + +- [BackupStorage](https://kubestash.com/docs/latest/concepts/crds/backupstorage/) +- [BackupConfiguration](https://kubestash.com/docs/latest/concepts/crds/backupconfiguration/) +- [BackupSession](https://kubestash.com/docs/latest/concepts/crds/backupsession/) +- [RestoreSession](https://kubestash.com/docs/latest/concepts/crds/restoresession/) +- [Addon](https://kubestash.com/docs/latest/concepts/crds/addon/) +- [Function](https://kubestash.com/docs/latest/concepts/crds/function/) +- [Task](https://kubestash.com/docs/latest/concepts/crds/addon/#task-specification) + +To keep everything isolated, we are going to use a separate namespace called `demo` throughout this tutorial. + +```bash +$ kubectl create ns demo +namespace/demo created +``` + +### Prepare Backend + +We are going to store our backed up data into a GCS bucket. We have to create a Secret with necessary credentials and a `BackupStorage` CR to use this backend. If you want to use a different backend, please read the respective backend configuration doc from [here](https://kubestash.com/docs/latest/guides/backends/overview/). + +**Create Secret:** + +Let's create a secret called `gcs-secret` with access credentials to our desired GCS bucket, + +```bash +$ echo -n '' > GOOGLE_PROJECT_ID +$ cat /path/to/downloaded-sa-key.json > GOOGLE_SERVICE_ACCOUNT_JSON_KEY +$ kubectl create secret generic -n demo gcs-secret \ + --from-file=./GOOGLE_PROJECT_ID \ + --from-file=./GOOGLE_SERVICE_ACCOUNT_JSON_KEY +secret/gcs-secret created +``` + +**Create BackupStorage:** + +Now, create a `BackupStorage` using this secret. Below is the YAML of `BackupStorage` CR we are going to create, + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: BackupStorage +metadata: + name: gcs-storage + namespace: demo +spec: + storage: + provider: gcs + gcs: + bucket: kubestash-qa + prefix: blueprint + secretName: gcs-secret + usagePolicy: + allowedNamespaces: + from: All + default: true + deletionPolicy: Delete +``` + +Let's create the BackupStorage we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/auto-backup/examples/backupstorage.yaml +backupstorage.storage.kubestash.com/gcs-storage created +``` + +**Create RetentionPolicy:** + +Now, let's create a `RetentionPolicy` to specify how the old Snapshots should be cleaned up. + +Below is the YAML of the `RetentionPolicy` object that we are going to create, + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: RetentionPolicy +metadata: + name: demo-retention + namespace: demo +spec: + default: true + failedSnapshots: + last: 2 + maxRetentionPeriod: 2mo + successfulSnapshots: + last: 5 + usagePolicy: + allowedNamespaces: + from: All +``` + +Let’s create the above `RetentionPolicy`, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/auto-backup/examples/retentionpolicy.yaml +retentionpolicy.storage.kubestash.com/demo-retention created +``` + +**Create Secret:** + +We also need to create a secret with a `Restic` password for backup data encryption. + +Let's create a secret called `encrypt-secret` with the Restic password, + +```bash +$ echo -n 'changeit' > RESTIC_PASSWORD +$ kubectl create secret generic -n demo encrypt-secret \ + --from-file=./RESTIC_PASSWORD +secret "encrypt-secret" created +``` + +## Auto-backup with default configurations + +In this section, we are going to backup a `SingleStore` database of `demo` namespace. We are going to use the default configurations which will be specified in the `Backup Blueprint` CR. + +**Prepare Backup Blueprint** + +A `BackupBlueprint` allows you to specify a template for the `Repository`,`Session` or `Variables` of `BackupConfiguration` in a Kubernetes native way. + +Now, we have to create a `BackupBlueprint` CR with a blueprint for `BackupConfiguration` object. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupBlueprint +metadata: + name: singlestore-default-backup-blueprint + namespace: demo +spec: + usagePolicy: + allowedNamespaces: + from: All + backupConfigurationTemplate: + deletionPolicy: OnDelete + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + sessionHistoryLimit: 3 + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: default-blueprint + backend: gcs-backend + directory: /default-blueprint + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup +``` + +Here, + +- `.spec.backupConfigurationTemplate.backends[*].storageRef` refers our earlier created `gcs-storage` backupStorage. +- `.spec.backupConfigurationTemplate.sessions[*].schedule` specifies that we want to backup the database at `5 minutes` interval. + +Let's create the `BackupBlueprint` we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml +backupblueprint.core.kubestash.com/singlestore-default-backup-blueprint created +``` + +Now, we are ready to backup our `SingleStore` databases using few annotations. + +**Create SingleStore License Secret** + +We need SingleStore License to create SingleStore Database. So, Ensure that you have acquired a license and then simply pass the license by secret. + +```bash +$ kubectl create secret generic -n demo license-secret \ + --from-literal=username=license \ + --from-literal=password='your-license-set-here' +secret/license-secret created +``` + +**Create Database** + +Now, we are going to create an `SingleStore` CR in demo namespace. Below is the YAML of the SingleStore object that we are going to create, + +```yaml +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sample-singlestore + namespace: demo + annotations: + blueprint.kubestash.com/name: singlestore-default-backup-blueprint + blueprint.kubestash.com/namespace: demo +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut +``` + +Here, + +- `.spec.annotations.blueprint.kubestash.com/name: singlestore-default-backup-blueprint` specifies the name of the `BackupBlueprint` that will use in backup. +- `.spec.annotations.blueprint.kubestash.com/namespace: demo` specifies the name of the `namespace` where the `BackupBlueprint` resides. + +Let's create the `SingleStore` we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/auto-backup/examples/sample-singlestore.yaml +singlestore.kubedb.com/sample-singlestore created +``` + +**Verify BackupConfiguration** + +If everything is set up correctly, KubeStash will create a `BackupConfiguration` for our SingleStore instance in the demo namespace. The phase of this `BackupConfiguration` should be Ready. You can verify the `BackupConfiguration` object by running the following command, + +```bash +$ kubectl get backupconfiguration -n demo +NAME PHASE PAUSED AGE +appbinding-sample-singlestore Ready 2m50m +``` + +Now, let’s check the YAML of the `BackupConfiguration`. + +```bash +$ kubectl get backupconfiguration -n demo appbinding-sample-singlestore -o yaml +``` + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + creationTimestamp: "2024-08-21T09:47:34Z" + finalizers: + - kubestash.com/cleanup + generation: 1 + labels: + app.kubernetes.io/managed-by: kubestash.com + kubestash.com/invoker-name: singlestore-default-backup-blueprint + kubestash.com/invoker-namespace: demo + name: appbinding-sample-singlestore + namespace: demo + resourceVersion: "113911" + uid: eef4c853-4df6-4b5e-b462-977c9b2188c0 +spec: + backends: + - name: gcs-backend + retentionPolicy: + name: demo-retention + namespace: demo + storageRef: + name: gcs-storage + namespace: demo + sessions: + - addon: + name: singlestore-addon + tasks: + - name: logical-backup + name: frequent-backup + repositories: + - backend: gcs-backend + directory: /default-blueprint + encryptionSecret: + name: encrypt-secret + namespace: demo + name: default-blueprint + scheduler: + jobTemplate: + backoffLimit: 1 + template: + controller: {} + metadata: {} + spec: + resources: {} + schedule: '*/5 * * * *' + sessionHistoryLimit: 3 + target: + apiGroup: kubedb.com + kind: Singlestore + name: sample-singlestore + namespace: demo +``` + +Notice the `spec.backends`, `spec.sessions` and `spec.target` sections, KubeStash automatically resolved those info from the `BackupBluePrint` and created above `BackupConfiguration`. + +**Verify BackupSession:** + +KubeStash triggers an instant backup as soon as the `BackupConfiguration` is ready. After that, backups are scheduled according to the specified schedule. + +```bash +$ kubectl get backupsession -n demo -w + +NAME INVOKER-TYPE INVOKER-NAME PHASE DURATION AGE +appbinding-sample-singlestore-frequent-backup-1724236500 BackupConfiguration appbinding-sample-singlestore Succeeded 7m22s +``` + +We can see from the above output that the backup session has succeeded. Now, we are going to verify whether the backed up data has been stored in the backend. + +**Verify Backup:** + +Once a backup is complete, KubeStash will update the respective `Repository` CR to reflect the backup. Check that the repository `default-blueprint` has been updated by the following command, + +```bash +$ kubectl get repository -n demo default-blueprint +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +default-blueprint true 1 806 B Ready 8m27s 9m18s +``` + +At this moment we have one `Snapshot`. Run the following command to check the respective `Snapshot` which represents the state of a backup run for an application. + +```bash +$ kubectl get snapshots -n demo -l=kubestash.com/repo-name=default-blueprint +NAME REPOSITORY SESSION SNAPSHOT-TIME DELETION-POLICY PHASE AGE +default-blueprint-appbinding-sample-singlestore-frequent-backup-1724236500 default-blueprint frequent-backup 2024-01-23T13:10:54Z Delete Succeeded 16h +``` + +> Note: KubeStash creates a `Snapshot` with the following labels: +> - `kubedb.com/db-version: ` +> - `kubestash.com/app-ref-kind: ` +> - `kubestash.com/app-ref-name: ` +> - `kubestash.com/app-ref-namespace: ` +> - `kubestash.com/repo-name: ` +> +> These labels can be used to watch only the `Snapshot`s related to our target Database or `Repository`. + +If we check the YAML of the `Snapshot`, we can find the information about the backed up components of the Database. + +```bash +$ kubectl get snapshots -n demo default-blueprint-appbinding-sample-singlestore-frequent-backup-1724236500 -oyaml +``` + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: Snapshot +metadata: + creationTimestamp: "2024-08-21T10:35:00Z" + finalizers: + - kubestash.com/cleanup + generation: 1 + labels: + kubedb.com/db-version: 8.7.10 + kubestash.com/app-ref-kind: Singlestore + kubestash.com/app-ref-name: sample-singlestore + kubestash.com/app-ref-namespace: demo + kubestash.com/repo-name: default-blueprint + name: default-blueprint-appbinding-sample-singlestore-frequent-backup-1724236500 + namespace: demo + ownerReferences: + - apiVersion: storage.kubestash.com/v1alpha1 + blockOwnerDeletion: true + controller: true + kind: Repository + name: default-blueprint + uid: 61e771fc-8262-480c-a9e7-3c5c11c8fd77 + resourceVersion: "118423" + uid: 27e2235a-22c1-449a-be92-c53506fe1fe4 +spec: + appRef: + apiGroup: kubedb.com + kind: Singlestore + name: sample-singlestore + namespace: demo + backupSession: appbinding-sample-singlestore-frequent-backup-1724236500 + deletionPolicy: Delete + repository: default-blueprint + session: frequent-backup + snapshotID: 01J6V48XS6QM489WPKX1MDD4W9 + type: FullBackup + version: v1 +status: + components: + dump: + driver: Restic + duration: 6.692337543s + integrity: true + path: repository/v1/frequent-backup/dump + phase: Succeeded + resticStats: + - hostPath: dumpfile.sql + id: b83d7a5577940d1c8f5bcda0630592c7d5a04168c272c0e7560bf7dacfe35ea8 + size: 3.657 MiB + uploaded: 121.343 KiB + size: 772.958 KiB + integrity: true + phase: Succeeded + size: 772.957 KiB + snapshotTime: "2024-08-21T10:35:00Z" + totalComponents: 1 +``` + +> KubeStash uses the `mysqldump` command to take backups of target SingleStore databases. Therefore, the component name for `logical backups` is set as `dump`. + +Now, if we navigate to the GCS bucket, we will see the backed up data stored in the `/blueprint/default-blueprint/repository/v1/frequent-backup/dump` directory. KubeStash also keeps the backup for `Snapshot` YAMLs, which can be found in the `blueprint/default-blueprintrepository/snapshots` directory. + +> Note: KubeStash stores all dumped data encrypted in the backup directory, meaning it remains unreadable until decrypted. + +## Auto-backup with custom configurations + +In this section, we are going to backup a `SingleStore` database of `demo` namespace. We are going to use the custom configurations which will be specified in the `BackupBlueprint` CR. + +**Prepare Backup Blueprint** + +A `BackupBlueprint` allows you to specify a template for the `Repository`,`Session` or `Variables` of `BackupConfiguration` in a Kubernetes native way. + +Now, we have to create a `BackupBlueprint` CR with a blueprint for `BackupConfiguration` object. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupBlueprint +metadata: + name: singlestore-customize-backup-blueprint + namespace: demo +spec: + usagePolicy: + allowedNamespaces: + from: All + backupConfigurationTemplate: + deletionPolicy: OnDelete + # ============== Blueprint for Backends of BackupConfiguration ================= + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + # ============== Blueprint for Sessions of BackupConfiguration ================= + sessions: + - name: frequent-backup + sessionHistoryLimit: 3 + scheduler: + schedule: ${schedule} + jobTemplate: + backoffLimit: 1 + repositories: + - name: ${repoName} + backend: gcs-backend + directory: ${namespace}/${targetName} + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup + params: + databases: ${targetedDatabases} +``` + +Note that we have used some variables (format: `${}`) in different fields. KubeStash will substitute these variables with values from the respective target’s annotations. You’re free to use any variables you like. + +Here, + +- `.spec.backupConfigurationTemplate.backends[*].storageRef` refers our earlier created `gcs-storage` backupStorage. +- `.spec.backupConfigurationTemplate.sessions[*]`: + - `.schedule` defines `${schedule}` variable, which determines the time interval for the backup. + - `.repositories[*].name` defines the `${repoName}` variable, which specifies the name of the backup `Repository`. + - `.repositories[*].directory` defines two variables, `${namespace}` and `${targetName}`, which are used to determine the path where the backup will be stored. + - `.addon.tasks[*]databases` defines `${targetedDatabases}` variable, which identifies list of databases to backup. + +Let's create the `BackupBlueprint` we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml +backupblueprint.core.kubestash.com/singlestore-customize-backup-blueprint created +``` + +Now, we are ready to backup our `SingleStore` databases using few annotations. You can check available auto-backup annotations for a databases from [here](https://kubestash.com/docs/latest/concepts/crds/backupblueprint/). + +**Create Database** + +Now, we are going to create an `SingleStore` CR in demo namespace. Below is the YAML of the SingleStore object that we are going to create, + +```yaml +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sample-singlestore-2 + namespace: demo + annotations: + blueprint.kubestash.com/name: singlestore-customize-backup-blueprint + blueprint.kubestash.com/namespace: demo + variables.kubestash.com/schedule: "*/10 * * * *" + variables.kubestash.com/repoName: customize-blueprint + variables.kubestash.com/namespace: demo + variables.kubestash.com/targetName: sample-singlestore-2 +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut +``` + +Notice the `metadata.annotations` field, where we have defined the annotations related to the automatic backup configuration. Specifically, we've set the `BackupBlueprint` name as `singlestore-customize-backup-blueprint` and the namespace as `demo`. We have also provided values for the blueprint template variables, such as the backup `schedule`, `repositoryName`, `namespace`, and `targetName`. These annotations will be used to create a `BackupConfiguration` for this `SingleStore` database. + +Let's create the `SingleStore` we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/auto-backup/examples/sample-singlestore-2.yaml +singlestore.kubedb.com/sample-singlestore-2 created +``` + +**Verify BackupConfiguration** + +If everything goes well, KubeStash should create a `BackupConfiguration` for our SingleStore in demo namespace and the phase of that `BackupConfiguration` should be `Ready`. Verify the `BackupConfiguration` object by the following command, + +```bash +$ kubectl get backupconfiguration -n demo +NAME PHASE PAUSED AGE +appbinding-sample-singlestore-2 Ready 2m50m +``` + +Now, let’s check the YAML of the `BackupConfiguration`. + +```bash +$ kubectl get backupconfiguration -n demo appbinding-sample-singlestore-2 -o yaml +``` + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + creationTimestamp: "2024-08-21T12:55:38Z" + finalizers: + - kubestash.com/cleanup + generation: 1 + labels: + app.kubernetes.io/managed-by: kubestash.com + kubestash.com/invoker-name: singlestore-customize-backup-blueprint + kubestash.com/invoker-namespace: demo + name: appbinding-sample-singlestore-2 + namespace: demo + resourceVersion: "129124" + uid: eb42b736-c9c9-4280-8379-bbb581790185 +spec: + backends: + - name: gcs-backend + retentionPolicy: + name: demo-retention + namespace: demo + storageRef: + name: gcs-storage + namespace: demo + sessions: + - addon: + name: singlestore-addon + tasks: + - name: logical-backup + name: frequent-backup + repositories: + - backend: gcs-backend + directory: demo/sample-singlestore-2 + encryptionSecret: + name: encrypt-secret + namespace: demo + name: customize-blueprint + scheduler: + jobTemplate: + backoffLimit: 1 + template: + controller: {} + metadata: {} + spec: + resources: {} + schedule: '*/10 * * * *' + sessionHistoryLimit: 3 + target: + apiGroup: kubedb.com + kind: Singlestore + name: sample-singlestore-2 + namespace: demo +``` + +Notice the `spec.backends`, `spec.sessions` and `spec.target` sections, KubeStash automatically resolved those info from the `BackupBluePrint` and created above `BackupConfiguration`. + +**Verify BackupSession:** + +KubeStash triggers an instant backup as soon as the `BackupConfiguration` is ready. After that, backups are scheduled according to the specified schedule. + +```bash +$ kubectl get backupsession -n demo -w + +NAME INVOKER-TYPE INVOKER-NAME PHASE DURATION AGE +appbinding-sample-singlestore-2-frequent-backup-1725007200 BackupConfiguration appbinding-sample-singlestore-2 Succeeded 7m22s +``` + +We can see from the above output that the backup session has succeeded. Now, we are going to verify whether the backed up data has been stored in the backend. + +**Verify Backup:** + +Once a backup is complete, KubeStash will update the respective `Repository` CR to reflect the backup. Check that the repository `customize-blueprint` has been updated by the following command, + +```bash +$ kubectl get repository -n demo customize-blueprint +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +customize-blueprint true 1 806 B Ready 8m27s 9m18s +``` + +At this moment we have one `Snapshot`. Run the following command to check the respective `Snapshot` which represents the state of a backup run for an application. + +```bash +$ kubectl get snapshots -n demo -l=kubestash.com/repo-name=customize-blueprint +NAME REPOSITORY SESSION SNAPSHOT-TIME DELETION-POLICY PHASE AGE +customize-blueprint-appbinding-sample-singlestore-2-frequent-backup-1725007200 customize-blueprint frequent-backup 2024-01-23T13:10:54Z Delete Succeeded 16h +``` + +> Note: KubeStash creates a `Snapshot` with the following labels: +> - `kubedb.com/db-version: ` +> - `kubestash.com/app-ref-kind: ` +> - `kubestash.com/app-ref-name: ` +> - `kubestash.com/app-ref-namespace: ` +> - `kubestash.com/repo-name: ` +> +> These labels can be used to watch only the `Snapshot`s related to our target Database or `Repository`. + +If we check the YAML of the `Snapshot`, we can find the information about the backed up components of the Database. + +```bash +$ kubectl get snapshots -n demo customize-blueprint-appbinding-sample-singlestore-2-frequent-backup-1725007200 -oyaml +``` + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: Snapshot +metadata: + creationTimestamp: "2024-08-21T10:35:00Z" + finalizers: + - kubestash.com/cleanup + generation: 1 + labels: + kubedb.com/db-version: 8.7.10 + kubestash.com/app-ref-kind: Singlestore + kubestash.com/app-ref-name: sample-singlestore + kubestash.com/app-ref-namespace: demo + kubestash.com/repo-name: customize-blueprint + name: customize-blueprint-appbinding-sample-singlestore-2-frequent-backup-1725007200 + namespace: demo + ownerReferences: + - apiVersion: storage.kubestash.com/v1alpha1 + blockOwnerDeletion: true + controller: true + kind: Repository + name: customize-blueprint + uid: 61e771fc-8262-480c-a9e7-3c5c11c8fd77 + resourceVersion: "118423" + uid: 27e2235a-22c1-449a-be92-c53506fe1fe4 +spec: + appRef: + apiGroup: kubedb.com + kind: Singlestore + name: sample-singlestore-2 + namespace: demo + backupSession: appbinding-sample-singlestore-2-frequent-backup-1725007200 + deletionPolicy: Delete + repository: customize-blueprint + session: frequent-backup + snapshotID: 01J6V48XZW2BJ02GSS4YBW3TWX + type: FullBackup + version: v1 +status: + components: + dump: + driver: Restic + duration: 6.692337543s + integrity: true + path: repository/v1/frequent-backup/dump + phase: Succeeded + resticStats: + - hostPath: dumpfile.sql + id: b83d7a5577940d1c8f5bcda0630592c7d5a04168c272c0e7560bf7dacfe35ea8 + size: 3.657 MiB + uploaded: 121.343 KiB + size: 772.958 KiB + integrity: true + phase: Succeeded + size: 772.957 KiB + snapshotTime: "2024-08-21T10:35:00Z" + totalComponents: 1 +``` + +> KubeStash uses the `mysqldump` command to take backups of target SingleStore databases. Therefore, the component name for `logical backups` is set as `dump`. + +Now, if we navigate to the GCS bucket, we will see the backed up data stored in the `/blueprint/custom-blueprint/repository/v1/frequent-backup/dump` directory. KubeStash also keeps the backup for `Snapshot` YAMLs, which can be found in the `blueprint/custom-blueprint/snapshots` directory. + +> Note: KubeStash stores all dumped data encrypted in the backup directory, meaning it remains unreadable until decrypted. + +## Cleanup + +To cleanup the resources crated by this tutorial, run the following commands, + +```bash +kubectl delete backupblueprints.core.kubestash.com -n demo singlestore-default-backup-blueprint +kubectl delete backupblueprints.core.kubestash.com -n demo singlestore-customize-backup-blueprint +kubectl delete backupstorage -n demo gcs-storage +kubectl delete secret -n demo gcs-secret +kubectl delete secret -n demo encrypt-secret +kubectl delete retentionpolicies.storage.kubestash.com -n demo demo-retention +kubectl delete my -n demo sample-singlestore +kubectl delete my -n demo sample-singlestore-2 +``` \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/backup/multiple-backends.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/multiple-backends.yaml new file mode 100644 index 0000000000..7165e33400 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/multiple-backends.yaml @@ -0,0 +1,49 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + - name: s3-backend + storageRef: + namespace: demo + name: s3-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + - name: s3-singlestore-repo + backend: s3-backend + directory: /singlestore-copy + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/backup/passing-args.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/passing-args.yaml new file mode 100644 index 0000000000..d297d866e0 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/passing-args.yaml @@ -0,0 +1,38 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup + params: + args: --set-gtid-purged=OFF \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/backup/passing-databases.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/passing-databases.yaml new file mode 100644 index 0000000000..cfff9b2b77 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/passing-databases.yaml @@ -0,0 +1,37 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup + params: + databases: db1,db2,db3 \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/backup/resources-limit.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/resources-limit.yaml new file mode 100644 index 0000000000..a7d24412e4 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/resources-limit.yaml @@ -0,0 +1,46 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + jobTemplate: + spec: + resources: + requests: + cpu: "200m" + memory: "1Gi" + limits: + cpu: "200m" + memory: "1Gi" + tasks: + - name: logical-backup + diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/backup/specific-user.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/specific-user.yaml new file mode 100644 index 0000000000..62a56355b7 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/backup/specific-user.yaml @@ -0,0 +1,41 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + jobTemplate: + spec: + securityContext: + runAsUser: 0 + runAsGroup: 0 + tasks: + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/common/gcs-backupstorage.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/common/gcs-backupstorage.yaml new file mode 100644 index 0000000000..6ab3df02ac --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/common/gcs-backupstorage.yaml @@ -0,0 +1,17 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: BackupStorage +metadata: + name: gcs-storage + namespace: demo +spec: + storage: + provider: gcs + gcs: + bucket: kubestash-qa + prefix: demo + secretName: gcs-secret + usagePolicy: + allowedNamespaces: + from: All + default: true + deletionPolicy: Delete \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/common/retentionpolicy.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/common/retentionpolicy.yaml new file mode 100644 index 0000000000..4591562860 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/common/retentionpolicy.yaml @@ -0,0 +1,15 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: RetentionPolicy +metadata: + name: demo-retention + namespace: demo +spec: + default: true + failedSnapshots: + last: 2 + maxRetentionPeriod: 2mo + successfulSnapshots: + last: 5 + usagePolicy: + allowedNamespaces: + from: All \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/common/s3-backupstorage.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/common/s3-backupstorage.yaml new file mode 100644 index 0000000000..a0f1c3ade3 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/common/s3-backupstorage.yaml @@ -0,0 +1,19 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: BackupStorage +metadata: + name: s3-storage + namespace: demo +spec: + storage: + provider: s3 + s3: + bucket: kubestash + region: us-east-1 + endpoint: us-east-1.linodeobjects.com + secretName: s3-secret + prefix: demo + usagePolicy: + allowedNamespaces: + from: All + default: false + deletionPolicy: Delete \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/common/sample-singlestore.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/common/sample-singlestore.yaml new file mode 100644 index 0000000000..f5123df643 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/common/sample-singlestore.yaml @@ -0,0 +1,50 @@ +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sdb-sample + namespace: demo +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/restore/passing-args.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/restore/passing-args.yaml new file mode 100644 index 0000000000..fd37ffb7d4 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/restore/passing-args.yaml @@ -0,0 +1,23 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup-restore + params: + args: --one-database=testdb \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/restore/resources-limit.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/restore/resources-limit.yaml new file mode 100644 index 0000000000..c4d79c7c53 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/restore/resources-limit.yaml @@ -0,0 +1,30 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + jobTemplate: + spec: + resources: + requests: + cpu: "200m" + memory: "1Gi" + limits: + cpu: "200m" + memory: "1Gi" + tasks: + - name: logical-backup-restore \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/restore/specific-snapshot.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/restore/specific-snapshot.yaml new file mode 100644 index 0000000000..8350581145 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/restore/specific-snapshot.yaml @@ -0,0 +1,21 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725257849 + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup-restore diff --git a/docs/guides/singlestore/backup/kubestash/customization/examples/restore/specific-user.yaml b/docs/guides/singlestore/backup/kubestash/customization/examples/restore/specific-user.yaml new file mode 100644 index 0000000000..98f9c51ffe --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/examples/restore/specific-user.yaml @@ -0,0 +1,26 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + jobTemplate: + spec: + securityContext: + runAsUser: 0 + runAsGroup: 0 + tasks: + - name: logical-backup-restore diff --git a/docs/guides/singlestore/backup/kubestash/customization/index.md b/docs/guides/singlestore/backup/kubestash/customization/index.md new file mode 100644 index 0000000000..c276cef037 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/customization/index.md @@ -0,0 +1,427 @@ +--- +title: SingleStore Backup Customization | KubeStash +description: Customizing SingleStore Backup and Restore process with KubeStash +menu: + docs_{{ .version }}: + identifier: guides-sdb-backup-customization-stashv2 + name: Customizing Backup & Restore Process + parent: guides-sdb-backup-stashv2 + weight: 50 +menu_name: docs_{{ .version }} +section_menu_id: guides +--- + +# Customizing Backup and Restore Process + +KubeStash provides rich customization supports for the backup and restore process to meet the requirements of various cluster configurations. This guide will show you some examples of these customizations. + +## Customizing Backup Process + +In this section, we are going to show you how to customize the backup process. Here, we are going to show some examples of providing arguments to the backup process, running the backup process as a specific user, etc. + +### Passing targeted databases to the backup process + +KubeStash SingleStore addon uses the [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html) for backup. Addon has implemented a `databases` params which indicates your targeted backup databases. + +The below example shows how you can pass the `--databases` option during backup. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup + params: + databases: db1,db2,db3 +``` + +> **WARNING**: Make sure that your provides databases has been created before taking backup. + +Here, +- `addon.tasks[*].databases` options indicates targeted databases. By default `singlestore-addon` add `--all-databases` options during backup. If you want to backup all databases keep the `databases` params empty. + +### Passing arguments to the backup process + +KubeStash SingleStore addon uses [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html) for backup. You can pass arguments to the `mysqldump` supported options through `args` param under `addon.tasks[*].params` section. + +The below example shows how you can pass the `--set-gtid-purged=OFF` options during backup. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup + params: + args: --set-gtid-purged=OFF +``` + +### Using multiple backends + +You can configure multiple backends within a single `backupConfiguration`. To back up the same data to different backends, such as S3 and GCS, declare each backend in the `.spe.backends` section. Then, reference these backends in the `.spec.sessions[*].repositories` section. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + - name: s3-backend + storageRef: + namespace: demo + name: s3-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + - name: s3-singlestore-repo + backend: s3-backend + directory: /singlestore-copy + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup +``` + +### Running backup job as a specific user + +If your cluster requires running the backup job as a specific user, you can provide `securityContext` under `addon.jobTemplate.spec.securityContext` section. The below example shows how you can run the backup job as the `root` user. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + jobTemplate: + spec: + securityContext: + runAsUser: 0 + runAsGroup: 0 + tasks: + - name: logical-backup +``` + +### Specifying Memory/CPU limit/request for the backup job + +If you want to specify the Memory/CPU limit/request for your backup job, you can specify `resources` field under `addon.jobTemplate.spec` section. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-singlestore-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sample-singlestore + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-singlestore-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + jobTemplate: + spec: + resources: + requests: + cpu: "200m" + memory: "1Gi" + limits: + cpu: "200m" + memory: "1Gi" + tasks: + - name: logical-backup +``` + +> You can configure additional runtime settings for backup jobs within the `addon.jobTemplate.spec` sections. For further details, please refer to the [reference](https://kubestash.com/docs/latest/concepts/crds/backupconfiguration/#podtemplate-spec). + +## Customizing Restore Process + +KubeStash also uses `singlestore` during the restore process. In this section, we are going to show how you can pass arguments to the restore process, restore a specific snapshot, run restore job as a specific user, etc. + + +### Passing arguments to the restore process + +Similar to the backup process, you can pass arguments to the restore process through the `args` params under `addon.tasks[*].params` section. + +This example will restore data from database `testdb` only. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup-restore + params: + args: --one-database=testdb +``` + +### Restore specific snapshot + +You can also restore a specific snapshot. At first, list the available snapshot as bellow, + +```bash +➤ kubectl get snapshots.storage.kubestash.com -n demo -l=kubestash.com/repo-name=gcs-singlestore-repo +NAME REPOSITORY SESSION SNAPSHOT-TIME DELETION-POLICY PHASE AGE +gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725257849 gcs-singlestore-repo frequent-backup 2024-09-02T06:18:01Z Delete Succeeded 15m +gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725258000 gcs-singlestore-repo frequent-backup 2024-09-02T06:20:00Z Delete Succeeded 13m +gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725258300 gcs-singlestore-repo frequent-backup 2024-09-02T06:25:00Z Delete Succeeded 8m34s +gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725258600 gcs-singlestore-repo frequent-backup 2024-09-02T06:30:00Z Delete Succeeded 3m34s +``` + +The below example shows how you can pass a specific snapshot name in `.dataSource` section. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: gcs-singlestore-repo-sample-singlestore-backup-frequent-backup-1725257849 + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup-restore + +``` + + +### Running restore job as a specific user + +Similar to the backup process under the `addon.jobTemplate.spec.` you can provide `securityContext` to run the restore job as a specific user. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + jobTemplate: + spec: + securityContext: + runAsUser: 0 + runAsGroup: 0 + tasks: + - name: logical-backup-restore + +``` + +### Specifying Memory/CPU limit/request for the restore job + +Similar to the backup process, you can also provide `resources` field under the `addon.jobTemplate.spec.resources` section to limit the Memory/CPU for your restore job. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + jobTemplate: + spec: + resources: + requests: + cpu: "200m" + memory: "1Gi" + limits: + cpu: "200m" + memory: "1Gi" + tasks: + - name: logical-backup-restore +``` + +> You can configure additional runtime settings for restore jobs within the `addon.jobTemplate.spec` sections. For further details, please refer to the [reference](https://kubestash.com/docs/latest/concepts/crds/restoresession/#podtemplate-spec). \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/logical/examples/backupconfiguration.yaml b/docs/guides/singlestore/backup/kubestash/logical/examples/backupconfiguration.yaml new file mode 100644 index 0000000000..5434c03eac --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/logical/examples/backupconfiguration.yaml @@ -0,0 +1,36 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-sdb-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sdb-sample + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-sdb-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/logical/examples/backupstorage.yaml b/docs/guides/singlestore/backup/kubestash/logical/examples/backupstorage.yaml new file mode 100644 index 0000000000..6ab3df02ac --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/logical/examples/backupstorage.yaml @@ -0,0 +1,17 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: BackupStorage +metadata: + name: gcs-storage + namespace: demo +spec: + storage: + provider: gcs + gcs: + bucket: kubestash-qa + prefix: demo + secretName: gcs-secret + usagePolicy: + allowedNamespaces: + from: All + default: true + deletionPolicy: Delete \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/logical/examples/restored-singlestore.yaml b/docs/guides/singlestore/backup/kubestash/logical/examples/restored-singlestore.yaml new file mode 100644 index 0000000000..dd4b4f93bb --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/logical/examples/restored-singlestore.yaml @@ -0,0 +1,52 @@ +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: restored-singlestore + namespace: demo +spec: + version: "8.7.10" + init: + waitForInitialRestore: true + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/logical/examples/restoresession.yaml b/docs/guides/singlestore/backup/kubestash/logical/examples/restoresession.yaml new file mode 100644 index 0000000000..c3a11d8cd3 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/logical/examples/restoresession.yaml @@ -0,0 +1,21 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup-restore \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/logical/examples/retentionpolicy.yaml b/docs/guides/singlestore/backup/kubestash/logical/examples/retentionpolicy.yaml new file mode 100644 index 0000000000..4591562860 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/logical/examples/retentionpolicy.yaml @@ -0,0 +1,15 @@ +apiVersion: storage.kubestash.com/v1alpha1 +kind: RetentionPolicy +metadata: + name: demo-retention + namespace: demo +spec: + default: true + failedSnapshots: + last: 2 + maxRetentionPeriod: 2mo + successfulSnapshots: + last: 5 + usagePolicy: + allowedNamespaces: + from: All \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/logical/examples/sdb-sample.yaml b/docs/guides/singlestore/backup/kubestash/logical/examples/sdb-sample.yaml new file mode 100644 index 0000000000..f5123df643 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/logical/examples/sdb-sample.yaml @@ -0,0 +1,50 @@ +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sdb-sample + namespace: demo +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/logical/index.md b/docs/guides/singlestore/backup/kubestash/logical/index.md new file mode 100644 index 0000000000..b1f798d3ce --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/logical/index.md @@ -0,0 +1,868 @@ +--- +title: Backup & Restore SingleStore | KubeStash +description: Backup SingleStore database using KubeStash +menu: + docs_{{ .version }}: + identifier: guides-sdb-backup-logical-backup-stashv2 + name: Logical Backup + parent: guides-sdb-backup-stashv2 + weight: 20 +menu_name: docs_{{ .version }} +section_menu_id: guides +--- + +# Backup and Restore SingleStore database using KubeStash + +KubeStash allows you to backup and restore `SingleStore` databases. It supports backups for `SingleStore` instances running in Standalone, and cluster configurations. KubeStash makes managing your `SingleStore` backups and restorations more straightforward and efficient. + +This guide will give you how you can take backup and restore your `SingleStore` databases using `Kubestash`. + +## Before You Begin + +- At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using `Minikube` or `Kind`. +- Install `KubeDB` in your cluster following the steps [here](/docs/setup/README.md). +- Install `KubeStash` in your cluster following the steps [here](https://kubestash.com/docs/latest/setup/install/kubestash). +- Install KubeStash `kubectl` plugin following the steps [here](https://kubestash.com/docs/latest/setup/install/kubectl-plugin/). +- If you are not familiar with how KubeStash backup and restore SingleStore databases, please check the following guide [here](/docs/guides/singlestore/backup/kubestash/overview/index.md). + +You should be familiar with the following `KubeStash` concepts: + +- [BackupStorage](https://kubestash.com/docs/latest/concepts/crds/backupstorage/) +- [BackupConfiguration](https://kubestash.com/docs/latest/concepts/crds/backupconfiguration/) +- [BackupSession](https://kubestash.com/docs/latest/concepts/crds/backupsession/) +- [RestoreSession](https://kubestash.com/docs/latest/concepts/crds/restoresession/) +- [Addon](https://kubestash.com/docs/latest/concepts/crds/addon/) +- [Function](https://kubestash.com/docs/latest/concepts/crds/function/) +- [Task](https://kubestash.com/docs/latest/concepts/crds/addon/#task-specification) + +To keep everything isolated, we are going to use a separate namespace called `demo` throughout this tutorial. + +```bash +$ kubectl create ns demo +namespace/demo created +``` + +> **Note:** YAML files used in this tutorial are stored in [docs/guides/singlestore/backup/kubestash/logical/examples](/docs/guides/singlestore/backup/kubestash/logical/examples) directory of [kubedb/docs](https://github.com/kubedb/docs) repository. + +## Backup SingleStore + +KubeStash supports backups for `SingleStore` instances across different configurations, including Standalone, and Cluster setups. In this demonstration, we'll focus on a `SingleStore` database using Clustering mode. The backup and restore process is similar for Standalone and Cluster configurations as well. + +This section will demonstrate how to backup a `SingleStore` database. Here, we are going to deploy a `SingleStore` database using KubeDB. Then, we are going to backup this database into a `GCS` bucket. Finally, we are going to restore the backup up data into another `SingleStore` database. + +### Create SingleStore License Secret + +We need SingleStore License to create SingleStore Database. So, Ensure that you have acquired a license and then simply pass the license by secret. + +```bash +$ kubectl create secret generic -n demo license-secret \ + --from-literal=username=license \ + --from-literal=password='your-license-set-here' +secret/license-secret created +``` + + +### Deploy Sample SingleStore Database + +Let's deploy a sample `SingleStore` database and insert some data into it. + +**Create SingleStore CR:** + +Below is the YAML of a sample `SingleStore` CRD that we are going to create for this tutorial: + +```yaml +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: sdb-sample + namespace: demo +spec: + version: "8.7.10" + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut +``` + +Here, + +- `spec.version` is the name of the SinglestoreVersion CRD where the docker images are specified. In this tutorial, a SingleStore `8.7.10` database is going to be created. +- `spec.topology` specifies that it will be used as cluster mode. If this field is nil it will be work as standalone mode. +- `spec.topology.aggregator.replicas` or `spec.topology.leaf.replicas` specifies that the number replicas that will be used for aggregator or leaf. +- `spec.storageType` specifies the type of storage that will be used for SingleStore database. It can be `Durable` or `Ephemeral`. Default value of this field is `Durable`. If `Ephemeral` is used then KubeDB will create SingleStore database using `EmptyDir` volume. In this case, you don't have to specify `spec.storage` field. This is useful for testing purposes. +- `spec.topology.aggregator.storage` or `spec.topology.leaf.storage` specifies the StorageClass of PVC dynamically allocated to store data for this database. This storage spec will be passed to the PetSet created by KubeDB operator to run database pods. You can specify any StorageClass available in your cluster with appropriate resource requests. +- `spec.deletionPolicy` gives flexibility whether to `nullify`(reject) the delete operation of `Singlestore` crd or which resources KubeDB should keep or delete when you delete `Singlestore` crd. If admission webhook is enabled, It prevents users from deleting the database as long as the `spec.deletionPolicy` is set to `DoNotTerminate`. Learn details of all `DeletionPolicy` [here](/docs/guides/mysql/concepts/database/index.md#specdeletionpolicy) + +> Note: `spec.storage` section is used to create PVC for database pod. It will create PVC with storage size specified in `storage.resources.requests` field. Don't specify limits here. PVC does not get resized automatically. + +Create the above `SingleStore` CR, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/logical/examples/sdb-sample.yaml +singlestore.kubedb.com/sdb-sample created +``` + +KubeDB will deploy a SingleStore database according to the above specification. It will also create the necessary `Secrets` and `Services` to access the database. + +Let's check if the database is ready to use, + +```bash +$ kubectl get singlestores.kubedb.com -n demo +NAME VERSION STATUS AGE +sdb-sample 8.7.10 Ready 4m22s +``` + +The database is `Ready`. Verify that KubeDB has created a `Secret` and a `Service` for this database using the following commands, + +```bash +$ kubectl get secret -n demo -l=app.kubernetes.io/instance=sdb-sample +NAME TYPE DATA AGE +sdb-sample-root-cred kubernetes.io/basic-auth 2 4m58s + +$ kubectl get service -n demo -l=app.kubernetes.io/instance=sdb-sample +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +sdb-sample ClusterIP 10.128.230.168 3306/TCP,8081/TCP 5m10s +sdb-sample-pods ClusterIP None 3306/TCP 5m10s + +``` + +Here, we have to use service `sdb-sample` and secret `sdb-sample-root-cred` to connect with the database. `KubeDB` creates an [AppBinding](/docs/guides/mysql/concepts/appbinding/index.md) CR that holds the necessary information to connect with the database. + +**Verify AppBinding:** + +Verify that the `AppBinding` has been created successfully using the following command, + +```bash +$ kubectl get appbindings -n demo +NAME AGE +sdb-sample 9m24s +``` + +Let's check the YAML of the above `AppBinding`, + +```bash +$ kubectl get appbindings -n demo sdb-sample -o yaml +``` + +```yaml +apiVersion: appcatalog.appscode.com/v1alpha1 +kind: AppBinding +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"kubedb.com/v1alpha2","kind":"Singlestore","metadata":{"annotations":{},"name":"sdb-sample","namespace":"demo"},"spec":{"deletionPolicy":"WipeOut","licenseSecret":{"name":"license-secret"},"storageType":"Durable","topology":{"aggregator":{"podTemplate":{"spec":{"containers":[{"name":"singlestore","resources":{"limits":{"cpu":"0.6","memory":"2Gi"},"requests":{"cpu":"0.6","memory":"2Gi"}}}]}},"replicas":2,"storage":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"1Gi"}}}},"leaf":{"podTemplate":{"spec":{"containers":[{"name":"singlestore","resources":{"limits":{"cpu":"0.6","memory":"2Gi"},"requests":{"cpu":"0.6","memory":"2Gi"}}}]}},"replicas":3,"storage":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"10Gi"}}}}},"version":"8.7.10"}} + creationTimestamp: "2024-09-11T07:03:44Z" + generation: 1 + labels: + app.kubernetes.io/component: database + app.kubernetes.io/instance: sdb-sample + app.kubernetes.io/managed-by: kubedb.com + app.kubernetes.io/name: singlestores.kubedb.com + name: sdb-sample + namespace: demo + ownerReferences: + - apiVersion: kubedb.com/v1alpha2 + blockOwnerDeletion: true + controller: true + kind: Singlestore + name: sdb-sample + uid: e08e1f37-d869-437d-9b15-14c6aef3f406 + resourceVersion: "4904220" + uid: 92b2b318-1874-4471-97ec-d789c6e16809 +spec: + appRef: + apiGroup: kubedb.com + kind: Singlestore + name: sdb-sample + namespace: demo + clientConfig: + service: + name: sdb-sample + path: / + port: 3306 + scheme: tcp + url: tcp(sdb-sample.demo.svc:3306)/ + parameters: + apiVersion: config.kubedb.com/v1alpha1 + kind: SinglestoreConfiguration + masterAggregator: sdb-sample-aggregator-0.sdb-sample-pods.demo.svc + stash: + addon: + backupTask: + name: "" + restoreTask: + name: "" + secret: + name: sdb-sample-root-cred + type: kubedb.com/singlestore + version: 8.7.10 + +``` + +KubeStash uses the `AppBinding` CR to connect with the target database. It requires the following two fields to set in AppBinding's `.spec` section. + +- `.spec.parameters.masterAggregator` specifies the dns of master aggregator node that we have to mention in mysqldump command when taken backup or restore. +- `.spec.clientConfig.service.name` specifies the name of the Service that connects to the database. +- `.spec.secret` specifies the name of the Secret that holds necessary credentials to access the database. +- `spec.type` specifies the types of the app that this AppBinding is pointing to. KubeDB generated AppBinding follows the following format: `/`. + +**Insert Sample Data:** + +Now, we are going to exec into the any aggregator pod and create some sample data. At first, find out the database `Pod` using the following command, + +```bash +$ kubectl get pods -n demo --selector="app.kubernetes.io/instance=sdb-sample" +NAME READY STATUS RESTARTS AGE +sdb-sample-aggregator-0 2/2 Running 0 15m +sdb-sample-aggregator-1 2/2 Running 0 15m +sdb-sample-leaf-0 2/2 Running 0 15m +sdb-sample-leaf-1 2/2 Running 0 15m +sdb-sample-leaf-2 2/2 Running 0 15m +``` + +And copy the username and password of the `root` user to access into `memsql` shell. + +```bash +$ kubectl get secret -n demo sdb-sample-root-cred -o jsonpath='{.data.username}'| base64 -d +root⏎ + +kubectl get secret -n demo sdb-sample-root-cred -o jsonpath='{.data.password}'| base64 -d +xEJv73q3w_m1~H.G⏎ +``` + +Now, Lets exec into the any aggregator `Pod` to enter into `mysql` shell and create a database and a table, + +```bash +$ kubectl exec -it -n demo sdb-sample-aggregator-0 -- singlestore --user=root --password=xEJv73q3w_m1~H.G +Defaulted container "singlestore" out of: singlestore, singlestore-coordinator, singlestore-init (init) +singlestore-client: [Warning] Using a password on the command line interface can be insecure. +Welcome to the MySQL monitor. Commands end with ; or \g. +Your MySQL connection id is 300070 +Server version: 5.7.32 SingleStoreDB source distribution (compatible; MySQL Enterprise & MySQL Commercial) + +Copyright (c) 2000, 2022, Oracle and/or its affiliates. + +Oracle is a registered trademark of Oracle Corporation and/or its +affiliates. Other names may be trademarks of their respective +owners. + +Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. + +singlestore> CREATE DATABASE playground partitions 2; +Query OK, 1 row affected (0.01 sec) + +singlestore> show databases; ++--------------------+ +| Database | ++--------------------+ +| cluster | +| demo | +| det | +| information_schema | +| memsql | +| playground | +| singlestore_health | +| test | ++--------------------+ +8 rows in set (0.00 sec) + +singlestore> CREATE TABLE playground.equipment ( id INT NOT NULL AUTO_INCREMENT, type VARCHAR(50), quant INT, color VARCHAR(25), PRIMARY KEY(id)); +Query OK, 0 rows affected, 1 warning (0.27 sec) + +singlestore> SHOW TABLES IN playground; ++----------------------+ +| Tables_in_playground | ++----------------------+ +| equipment | ++----------------------+ +1 row in set (0.00 sec) + +singlestore> INSERT INTO playground.equipment (type, quant, color) VALUES ("slide", 2, "blue"); +Query OK, 1 row affected (1.15 sec) + +singlestore> SELECT * FROM playground.equipment; ++----+-------+-------+-------+ +| id | type | quant | color | ++----+-------+-------+-------+ +| 1 | slide | 2 | blue | ++----+-------+-------+-------+ +1 row in set (0.14 sec) + +singlestore> exit +Bye + +``` + +Now, we are ready to backup the database. + +### Prepare Backend + +We are going to store our backed up data into a GCS bucket. We have to create a Secret with necessary credentials and a `BackupStorage` CR to use this backend. If you want to use a different backend, please read the respective backend configuration doc from [here](https://kubestash.com/docs/latest/guides/backends/overview/). + +**Create Secret:** + +Let's create a secret called `gcs-secret` with access credentials to our desired GCS bucket, + +```bash +$ echo -n '' > GOOGLE_PROJECT_ID +$ cat /path/to/downloaded-sa-key.json > GOOGLE_SERVICE_ACCOUNT_JSON_KEY +$ kubectl create secret generic -n demo gcs-secret \ + --from-file=./GOOGLE_PROJECT_ID \ + --from-file=./GOOGLE_SERVICE_ACCOUNT_JSON_KEY +secret/gcs-secret created +``` + +**Create BackupStorage:** + +Now, create a `BackupStorage` using this secret. Below is the YAML of `BackupStorage` CR we are going to create, + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: BackupStorage +metadata: + name: gcs-storage + namespace: demo +spec: + storage: + provider: gcs + gcs: + bucket: kubestash-qa + prefix: demo + secretName: gcs-secret + usagePolicy: + allowedNamespaces: + from: All + default: true + deletionPolicy: Delete +``` + +Let's create the BackupStorage we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/logical/examples/backupstorage.yaml +backupstorage.storage.kubestash.com/gcs-storage created +``` + +Now, we are ready to backup our database to our desired backend. + +**Create RetentionPolicy:** + +Now, let's create a `RetentionPolicy` to specify how the old Snapshots should be cleaned up. + +Below is the YAML of the `RetentionPolicy` object that we are going to create, + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: RetentionPolicy +metadata: + name: demo-retention + namespace: demo +spec: + default: true + failedSnapshots: + last: 2 + maxRetentionPeriod: 2mo + successfulSnapshots: + last: 5 + usagePolicy: + allowedNamespaces: + from: All +``` + +Let’s create the above `RetentionPolicy`, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/logical/examples/retentionpolicy.yaml +retentionpolicy.storage.kubestash.com/demo-retention created +``` + +### Backup + +We have to create a `BackupConfiguration` targeting respective `sdb-sample` SingleStore database. Then, KubeStash will create a `CronJob` for each session to take periodic backup of that database. + +At first, we need to create a secret with a Restic password for backup data encryption. + +**Create Secret:** + +Let's create a secret called `encrypt-secret` with the Restic password, + +```bash +$ echo -n 'changeit' > RESTIC_PASSWORD +$ kubectl create secret generic -n demo encrypt-secret \ + --from-file=./RESTIC_PASSWORD \ +secret "encrypt-secret" created +``` + +**Create BackupConfiguration:** + +Below is the YAML for `BackupConfiguration` CR to backup the `sdb-sample` database that we have deployed earlier, + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-sdb-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: sdb-sample + backends: + - name: gcs-backend + storageRef: + namespace: demo + name: gcs-storage + retentionPolicy: + name: demo-retention + namespace: demo + sessions: + - name: frequent-backup + scheduler: + schedule: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: gcs-sdb-repo + backend: gcs-backend + directory: /singlestore + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup +``` + +- `.spec.sessions[*].schedule` specifies that we want to backup the database at `5 minutes` interval. +- `.spec.target` refers to the targeted `sdb-sample` SigleStore database that we created earlier. + +Let's create the `BackupConfiguration` CR that we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/logical/examples/backupconfiguration.yaml +backupconfiguration.core.kubestash.com/sample-sdb-backup created +``` + +**Verify Backup Setup Successful** + +If everything goes well, the phase of the `BackupConfiguration` should be `Ready`. The `Ready` phase indicates that the backup setup is successful. Let's verify the `Phase` of the BackupConfiguration, + +```bash +$ kubectl get backupconfiguration -n demo +NAME PHASE PAUSED AGE +sample-sdb-backup Ready 2m50s +``` + +Additionally, we can verify that the `Repository` specified in the `BackupConfiguration` has been created using the following command, + +```bash +$ kubectl get repo -n demo +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +gcs-sdb-repo 0 0 B Ready 3m +``` + +KubeStash keeps the backup for `Repository` YAMLs. If we navigate to the GCS bucket, we will see the `Repository` YAML stored in the `demo/singlestore` directory. + +**Verify CronJob:** + +It will also create a `CronJob` with the schedule specified in `spec.sessions[*].scheduler.schedule` field of `BackupConfiguration` CR. + +Verify that the `CronJob` has been created using the following command, + +```bash +$ kubectl get cronjob -n demo +NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE +trigger-sample-sdb-backup-frequent-backup */5 * * * * 0 2m45s 3m25s +``` + +**Verify BackupSession:** + +KubeStash triggers an instant backup as soon as the `BackupConfiguration` is ready. After that, backups are scheduled according to the specified schedule. + +```bash +$ kubectl get backupsession -n demo -w + +NAME INVOKER-TYPE INVOKER-NAME PHASE DURATION AGE +sample-sdb-backup-frequent-backup-1724065200 BackupConfiguration sdb-sample-backup Succeeded 7m22s +``` + +We can see from the above output that the backup session has succeeded. Now, we are going to verify whether the backed up data has been stored in the backend. + +**Verify Backup:** + +Once a backup is complete, KubeStash will update the respective `Repository` CR to reflect the backup. Check that the repository `sample-sdb-backup` has been updated by the following command, + +```bash +$ kubectl get repository -n demo gcs-sdb-repo +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +gcs-sdb-repo true 1 806 B Ready 8m27s 9m18s +``` + +At this moment we have one `Snapshot`. Run the following command to check the respective `Snapshot` which represents the state of a backup run for an application. + +```bash +$ kubectl get snapshots -n demo -l=kubestash.com/repo-name=gcs-demo-repo +NAME REPOSITORY SESSION SNAPSHOT-TIME DELETION-POLICY PHASE AGE +gcs-sdb-repo-sample-sdb-backup-frequent-backup-1724065200 sample-sdb-backup frequent-backup 2024-01-23T13:10:54Z Delete Succeeded 16h +``` + +> Note: KubeStash creates a `Snapshot` with the following labels: +> - `kubestash.com/app-ref-kind: ` +> - `kubestash.com/app-ref-name: ` +> - `kubestash.com/app-ref-namespace: ` +> - `kubestash.com/repo-name: ` +> +> These labels can be used to watch only the `Snapshot`s related to our target Database or `Repository`. + +If we check the YAML of the `Snapshot`, we can find the information about the backed up components of the Database. + +```bash +$ kubectl get snapshots -n demo gcs-sdb-repo-sample-sdb-backup-frequent-backup-1724065200 -oyaml +``` + +```yaml +apiVersion: storage.kubestash.com/v1alpha1 +kind: Snapshot +metadata: + creationTimestamp: "2024-08-19T12:10:00Z" + finalizers: + - kubestash.com/cleanup + generation: 1 + labels: + kubestash.com/app-ref-kind: Singlestore + kubestash.com/app-ref-name: sdb-sample + kubestash.com/app-ref-namespace: demo + kubestash.com/repo-name: gcs-sdb-repo + annotations: + kubedb.com/db-version: 8.7.10 + name: gcs-sdb-repo-sample-sdb-backup-frequent-backup-1724065200 + namespace: demo + ownerReferences: + - apiVersion: storage.kubestash.com/v1alpha1 + blockOwnerDeletion: true + controller: true + kind: Repository + name: gcs-sdb-repo + uid: 036a2605-0dcc-43bd-a921-363d5c3e8cf0 + resourceVersion: "33742" + uid: d7f14919-4c31-4b46-84e9-0a75f303ad92 +spec: + appRef: + apiGroup: kubedb.com + kind: Singlestore + name: sdb-sample + namespace: demo + backupSession: sample-sdb-backup-frequent-backup-1724065200 + deletionPolicy: Delete + repository: gcs-sdb-repo + session: frequent-backup + snapshotID: 01J6V4P4J0R33C8EG0JWK82118 + type: FullBackup + version: v1 +status: + components: + dump: + driver: Restic + duration: 7.472499073s + integrity: true + path: repository/v1/frequent-backup/dump + phase: Succeeded + resticStats: + - hostPath: dumpfile.sql + id: fbab3af5c38f51b7aa9096799d8ce4b71ea0092dd8297526fed0adbd9f62f3f1 + size: 3.657 MiB + uploaded: 1.036 MiB + size: 1.456 MiB + ... +``` + +> KubeStash uses the `mysqldump` command to take backups of target SingleStore databases. Therefore, the component name for logical backups is set as `dump`. + +Now, if we navigate to the GCS bucket, we will see the backed up data stored in the `demo/singlestore/repository/v1/frequent-backup/dump` directory. KubeStash also keeps the backup for `Snapshot` YAMLs, which can be found in the `demo/dep/snapshots` directory. + +> Note: KubeStash stores all dumped data encrypted in the backup directory, meaning it remains unreadable until decrypted. + +## Restore + +In this section, we are going to restore the database from the backup we have taken in the previous section. We are going to deploy a new database and initialize it from the backup. + +#### Deploy Restored Database: + +Now, we have to deploy the restored database similarly as we have deployed the original `sdb-sample` database. However, this time there will be the following differences: + +- We are going to specify `.spec.init.waitForInitialRestore` field that tells KubeDB to wait for first restore to complete before marking this database is ready to use. + +Below is the YAML for `SingleStore` CRD we are going deploy to initialize from backup, + +```yaml +apiVersion: kubedb.com/v1alpha2 +kind: Singlestore +metadata: + name: restored-singlestore + namespace: demo +spec: + version: "8.7.10" + init: + waitForInitialRestore: true + topology: + aggregator: + replicas: 2 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + leaf: + replicas: 3 + podTemplate: + spec: + containers: + - name: singlestore + resources: + limits: + memory: "2Gi" + cpu: "600m" + requests: + memory: "2Gi" + cpu: "600m" + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + licenseSecret: + name: license-secret + storageType: Durable + deletionPolicy: WipeOut +``` + +Let's create the above database, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/logical/examples/restored-singlestore.yaml +singlestore.kubedb.com/restored-singlestore created +``` + +If you check the database status, you will see it is stuck in `Provisioning` state. + +```bash +$ kubectl get singlestore -n demo restored-singlestore +NAME VERSION STATUS AGE +restored-singlestore 8.7.10 Provisioning 61s +``` + +#### Create RestoreSession: + +Now, we need to create a RestoreSession CRD pointing to targeted `SingleStore` database. + +Below, is the contents of YAML file of the `RestoreSession` object that we are going to create to restore backed up data into the newly created database provisioned by SingleStore object named `restored-singlestore`. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-singlestore + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: Singlestore + namespace: demo + name: restored-singlestore + dataSource: + repository: gcs-singlestore-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: singlestore-addon + tasks: + - name: logical-backup-restore +``` + +Here, + +- `.spec.target` refers to the newly created `restored-singlestore` SingleStore object to where we want to restore backup data. +- `.spec.dataSource.repository` specifies the Repository object that holds the backed up data. +- `.spec.dataSource.snapshot` specifies to restore from latest `Snapshot`. + +Let's create the RestoreSession CRD object we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/singlestore/backup/kubestash/logical/examples/restoresession.yaml +restoresession.core.kubestash.com/sample-singlestore-restore created +``` + +Once, you have created the `RestoreSession` object, KubeStash will create restore Job. Run the following command to watch the phase of the `RestoreSession` object, + +```bash +$ watch kubectl get restoresession -n demo +Every 2.0s: kubectl get restores... AppsCode-PC-03: Wed Sep 20 10:44:05 2024 + +NAME REPOSITORY FAILURE-POLICY PHASE DURATION AGE +sample-restore gcs-demo-repo Succeeded 3s 53s +``` + +The `Succeeded` phase means that the restore process has been completed successfully. + + +#### Verify Restored Data: + +In this section, we are going to verify whether the desired data has been restored successfully. We are going to connect to the database server and check whether the database and the table we created earlier in the original database are restored. + +At first, check if the database has gone into `Ready` state by the following command, + +```bash +$ kubectl get singlestore -n demo restored-singlestore +NAME VERSION STATUS AGE +restored-singlestore 8.7.10 Ready 34m +``` + +Now, find out the database `Pod` by the following command, + +```bash +$ kubectl get pods -n demo --selector="app.kubernetes.io/instance=restored-singlestore" +NAME READY STATUS RESTARTS AGE +restored-singlestore-aggregator-0 2/2 Running 0 34m +restored-singlestore-aggregator-1 2/2 Running 0 34m +restored-singlestore-leaf-0 2/2 Running 0 34m +restored-singlestore-leaf-1 2/2 Running 0 34m +restored-singlestore-leaf-2 2/2 Running 0 34m +``` + +And then copy the user name and password of the `root` user to access into `memsql` shell. + +```bash +$ kubectl get secret -n demo restored-singlestore-root-cred -o jsonpath='{.data.username}'| base64 -d +root⏎ + +kubectl get secret -n demo restored-singlestore-root-cred -o jsonpath='{.data.password}'| base64 -d +QMm1hi0T*7QFz_yh⏎ +``` + +Now, Lets exec into the any aggregator `Pod` to enter into `mysql` shell and create a database and a table, + +```bash +$ kubectl exec -it -n demo restored-singlestore-aggregator-0 -- singlestore --user=root --password=QMm1hi0T*7QFz_yh +Defaulted container "singlestore" out of: singlestore, singlestore-coordinator, singlestore-init (init) +singlestore-client: [Warning] Using a password on the command line interface can be insecure. +Welcome to the MySQL monitor. Commands end with ; or \g. +Your MySQL connection id is 300070 +Server version: 5.7.32 SingleStoreDB source distribution (compatible; MySQL Enterprise & MySQL Commercial) + +Copyright (c) 2000, 2022, Oracle and/or its affiliates. + +Oracle is a registered trademark of Oracle Corporation and/or its +affiliates. Other names may be trademarks of their respective +owners. + +Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. + +singlestore> show databases; ++--------------------+ +| Database | ++--------------------+ +| cluster | +| demo | +| det | +| information_schema | +| memsql | +| playground | +| singlestore_health | +| test | ++--------------------+ +8 rows in set (0.00 sec) + +singlestore> SHOW TABLES IN playground; ++----------------------+ +| Tables_in_playground | ++----------------------+ +| equipment | ++----------------------+ +1 row in set (0.00 sec) + +singlestore> SELECT * FROM playground.equipment; ++----+-------+-------+-------+ +| id | type | quant | color | ++----+-------+-------+-------+ +| 1 | slide | 2 | blue | ++----+-------+-------+-------+ +1 row in set (0.14 sec) + +singlestore> exit +Bye + +``` + +So, from the above output, we can see that the `playground` database and the `equipment` table we have created earlier in the original database and now, they are restored successfully. + +## Cleanup + +To cleanup the Kubernetes resources created by this tutorial, run: + +```bash +kubectl delete backupconfigurations.core.kubestash.com -n demo sample-sdb-backup +kubectl delete restoresessions.core.kubestash.com -n demo sample-restore +kubectl delete retentionpolicies.storage.kubestash.com -n demo demo-retention +kubectl delete backupstorage -n demo gcs-storage +kubectl delete secret -n demo gcs-secret +kubectl delete secret -n demo encrypt-secret +kubectl delete my -n demo restored-singlestore +kubectl delete my -n demo sdb-sample +``` \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/overview/images/backup_overview.svg b/docs/guides/singlestore/backup/kubestash/overview/images/backup_overview.svg new file mode 100644 index 0000000000..9d245e0dcd --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/overview/images/backup_overview.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/overview/images/kubedb_plus_kubestash.svg b/docs/guides/singlestore/backup/kubestash/overview/images/kubedb_plus_kubestash.svg new file mode 100644 index 0000000000..380d92d969 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/overview/images/kubedb_plus_kubestash.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/guides/singlestore/backup/kubestash/overview/images/restore_overview.svg b/docs/guides/singlestore/backup/kubestash/overview/images/restore_overview.svg new file mode 100644 index 0000000000..f2c2488962 --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/overview/images/restore_overview.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/guides/singlestore/backup/kubestash/overview/index.md b/docs/guides/singlestore/backup/kubestash/overview/index.md new file mode 100644 index 0000000000..046af600ec --- /dev/null +++ b/docs/guides/singlestore/backup/kubestash/overview/index.md @@ -0,0 +1,98 @@ +--- +title: Backup & Restore SingleStore Using KubeStash +menu: + docs_{{ .version }}: + identifier: guides-sdb-backup-overview-stashv2 + name: Overview + parent: guides-sdb-backup-stashv2 + weight: 10 +menu_name: docs_{{ .version }} +section_menu_id: guides +--- + +> New to KubeDB? Please start [here](/docs/README.md). + +{{< notice type="warning" message="Please install [KubeStash](https://kubestash.com/docs/latest/setup/install/kubestash/) to try this feature. Database backup with KubeStash is already included in the KubeDB license. So, you don't need a separate license for KubeStash." >}} + +# SingleStore Backup & Restore Overview + +KubeDB also uses [KubeStash](https://kubestash.com) 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](https://github.com/restic/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.). + +
+  KubeDB + KubeStash +
Fig: Backup KubeDB Databases Using KubeStash
+
+ +## How Backup Works + +The following diagram shows how KubeStash takes backup of a `SingleStore` database. Open the image in a new tab to see the enlarged version. + +
+  SingleStore Backup Overview +
Fig: SingleStore Backup Overview
+
+ +The backup process consists of the following steps: + +1. At first, a user creates a `Secret`. This secret holds the credentials to access the backend where the backed up data will be stored. + +2. Then, the user creates a `BackupStorage` custom resource that specifies the backend information, along with the `Secret` containing the credentials needed to access the backend. + +3. KubeStash operator watches for `BackupStorage` custom resources. When it finds a `BackupStorage` object, it initializes the `BackupStorage` by uploading the `metadata.yaml` file to the specified backend. + +4. Next, user creates a `BackupConfiguration` custom resource that specifies the target database, addon information (including backup tasks), backup schedules, storage backends for storing the backup data, and other additional settings. + +5. KubeStash operator watches for `BackupConfiguration` objects. + +6. Once the KubeStash operator finds a `BackupConfiguration` object, it creates `Repository` with the information specified in the `BackupConfiguration`. + +7. KubeStash operator watches for `Repository` custom resources. When it finds the `Repository` object, it Initializes `Repository` by uploading `repository.yaml` file into the `spec.sessions[*].repositories[*].directory` path specified in `BackupConfiguration`. + +8. The Operator creates a `CronJob` for each session with the schedule specified in the corresponding `BackupConfiguration` to trigger backup periodically. + +9. KubeStash operator triggers an instant backup as soon as the `BackupConfiguration` is ready. Backups are otherwise triggered by the `CronJob` based on the specified schedule. + +10. KubeStash operator watches also for `BackupSession` custom resources. + +11. When it finds a `BackupSession` object, it creates a `Snapshot` custom resource for each `Repository` specified in the `BackupConfiguration`. + +12. Then it resolves the respective `Addon` and `Function` and prepares backup `Job` definition. + +13. Then, it creates the `Job` to backup the targeted `SingleStore` database. + +14. The backup `Job` reads necessary information (e.g. auth secret, port) to connect with the database from the `AppBinding` CR. It also reads backend information and access credentials from `BackupStorage` CR, Storage Secret and `Repository` path respectively. + +15. Then, the `Job` dumps the targeted `SingleStore` database and uploads the output to the backend. KubeStash pipes the output of dump command to uploading process. Hence, backup `Job` does not require a large volume to hold the entire dump output. + +16. After the backup process is completed, the backup `Job` updates the `status.components[dump]` field of the `Snapshot` resources with backup information of the target `SingleStore` database. + +## How Restore Process Works + +The following diagram shows how KubeStash restores backed up data into a `SingleStore` database. Open the image in a new tab to see the enlarged version. + +
+  Database Restore Overview +
Fig: SingleStore Restore Process Overview
+
+ +The restore process consists of the following steps: + +1. At first, a user creates a `SingleStore` database where the data will be restored or the user can use the same `SingleStore` database. + +2. Then, user creates a `RestoreSession` custom 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. + +3. KubeStash operator watches for `RestoreSession` custom resources. + +4. When it finds a `RestoreSession` custom resource, it resolves the respective `Addon` and `Function` and prepares a restore `Job` definition. + +5. Then, it creates the `Job` to restore the target. + +6. The `Job` reads necessary information to connect with the database from respective `AppBinding` CR. It also reads backend information and access credentials from `Repository` CR and storage `Secret` respectively. + +7. Then, the `Job` downloads 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 `Job` does not require a large volume to download entire backup data inside it. + +8. Finally, when the restore process is completed, the `Job` updates the `status.components[*]` field of the `RestoreSession` with restore information of the target database. + +## Next Steps + +- Backup a `SingleStore` database using KubeStash by the following guides from [here](/docs/guides/singlestore/backup/kubestash/logical/index.md). \ No newline at end of file