From e1c24ecaae6d789c4fca5de8ccaa5ba582d13e2c Mon Sep 17 00:00:00 2001 From: Anisur Rahman Date: Fri, 30 Aug 2024 12:48:13 +0600 Subject: [PATCH] Add logical backup/restore Add auto backup Signed-off-by: Anisur Rahman --- docs/guides/mysql/README.md | 2 +- docs/guides/mysql/backup/kubestash/_index.md | 10 + .../examples/backupconfiguration.yaml | 37 + .../examples/backupstorage.yaml | 17 + .../examples/restoresession.yaml | 21 + .../examples/retentionpolicy.yaml | 15 + .../examples/sample-mysql.yaml | 18 + .../kubestash/application-level/index.md | 759 ++++++++++++++++++ .../auto-backup/examples/backupstorage.yaml | 17 + .../examples/customize-backupblueprint.yaml | 41 + .../examples/default-backupblueprint.yaml | 37 + .../auto-backup/examples/retentionpolicy.yaml | 15 + .../auto-backup/examples/sample-mysql-2.yaml | 25 + .../auto-backup/examples/sample-mysql.yaml | 20 + .../backup/kubestash/auto-backup/index.md | 735 +++++++++++++++++ .../examples/backup/multiple-repository.yaml | 42 + .../examples/backup/passing-args.yaml | 38 + .../examples/backup/passing-databases.yaml | 38 + .../examples/backup/resources-limit.yaml | 46 ++ .../examples/backup/specific-user.yaml | 41 + .../examples/common/backupstorage.yaml | 17 + .../examples/common/retentionpolicy.yaml | 15 + .../examples/common/sample-mysql.yaml | 18 + .../examples/restore/passing-args.yaml | 23 + .../examples/restore/resources-limit.yaml | 30 + .../examples/restore/specific-snapshot.yaml | 21 + .../examples/restore/specific-user.yaml | 26 + .../backup/kubestash/customization/index.md | 437 ++++++++++ .../logical/examples/backupconfiguration.yaml | 36 + .../logical/examples/backupstorage.yaml | 17 + .../logical/examples/restored-mysql.yaml | 20 + .../logical/examples/restoresession.yaml | 21 + .../logical/examples/retentionpolicy.yaml | 15 + .../logical/examples/sample-mysql.yaml | 18 + .../mysql/backup/kubestash/logical/index.md | 753 +++++++++++++++++ .../overview/images/backup_overview.svg | 1 + .../overview/images/kubedb_plus_kubestash.svg | 21 + .../overview/images/restore_overview.svg | 1 + .../mysql/backup/kubestash/overview/index.md | 98 +++ docs/guides/mysql/backup/stash/_index.md | 10 + .../auto-backup/examples/backupblueprint.yaml | 0 .../auto-backup/examples/sample-mysql-2.yaml | 0 .../auto-backup/examples/sample-mysql-3.yaml | 0 .../auto-backup/examples/sample-mysql.yaml | 0 .../auto-backup/images/sample-mysql-2.png | Bin .../auto-backup/images/sample-mysql-3.png | Bin .../auto-backup/images/sample-mysql.png | Bin .../backup/{ => stash}/auto-backup/index.md | 22 +- .../backup/multi-retention-policy.yaml | 0 .../examples/backup/passing-args.yaml | 0 .../examples/backup/resource-limit.yaml | 0 .../examples/backup/specific-user.yaml | 0 .../customization/examples/repository.yaml | 0 .../examples/restore/passing-args.yaml | 0 .../examples/restore/resource-limit.yaml | 0 .../examples/restore/specific-snapshot.yaml | 0 .../examples/restore/specific-user.yaml | 0 .../customization/examples/sample-mysql.yaml | 0 .../backup/{ => stash}/customization/index.md | 4 +- .../overview/images/backup_overview.svg | 0 .../overview/images/restore_overview.svg | 0 .../backup/{ => stash}/overview/index.md | 10 +- .../examples/backupconfiguration.yaml | 0 .../standalone/examples/repository.yaml | 0 .../standalone/examples/restored-mysql.yaml | 0 .../standalone/examples/restoresession.yaml | 0 .../standalone/examples/sample-mysql.yaml | 0 .../standalone/images/sample-mysql-backup.png | Bin .../backup/{ => stash}/standalone/index.md | 18 +- docs/guides/mysql/pitr/archiver.md | 2 +- 70 files changed, 3599 insertions(+), 29 deletions(-) create mode 100644 docs/guides/mysql/backup/kubestash/_index.md create mode 100644 docs/guides/mysql/backup/kubestash/application-level/examples/backupconfiguration.yaml create mode 100644 docs/guides/mysql/backup/kubestash/application-level/examples/backupstorage.yaml create mode 100644 docs/guides/mysql/backup/kubestash/application-level/examples/restoresession.yaml create mode 100644 docs/guides/mysql/backup/kubestash/application-level/examples/retentionpolicy.yaml create mode 100644 docs/guides/mysql/backup/kubestash/application-level/examples/sample-mysql.yaml create mode 100644 docs/guides/mysql/backup/kubestash/application-level/index.md create mode 100644 docs/guides/mysql/backup/kubestash/auto-backup/examples/backupstorage.yaml create mode 100644 docs/guides/mysql/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml create mode 100644 docs/guides/mysql/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml create mode 100644 docs/guides/mysql/backup/kubestash/auto-backup/examples/retentionpolicy.yaml create mode 100644 docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql-2.yaml create mode 100644 docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql.yaml create mode 100644 docs/guides/mysql/backup/kubestash/auto-backup/index.md create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/backup/multiple-repository.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/backup/passing-args.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/backup/passing-databases.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/backup/resources-limit.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/backup/specific-user.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/common/backupstorage.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/common/retentionpolicy.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/common/sample-mysql.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/restore/passing-args.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/restore/resources-limit.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/restore/specific-snapshot.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/examples/restore/specific-user.yaml create mode 100644 docs/guides/mysql/backup/kubestash/customization/index.md create mode 100644 docs/guides/mysql/backup/kubestash/logical/examples/backupconfiguration.yaml create mode 100644 docs/guides/mysql/backup/kubestash/logical/examples/backupstorage.yaml create mode 100644 docs/guides/mysql/backup/kubestash/logical/examples/restored-mysql.yaml create mode 100644 docs/guides/mysql/backup/kubestash/logical/examples/restoresession.yaml create mode 100644 docs/guides/mysql/backup/kubestash/logical/examples/retentionpolicy.yaml create mode 100644 docs/guides/mysql/backup/kubestash/logical/examples/sample-mysql.yaml create mode 100644 docs/guides/mysql/backup/kubestash/logical/index.md create mode 100644 docs/guides/mysql/backup/kubestash/overview/images/backup_overview.svg create mode 100644 docs/guides/mysql/backup/kubestash/overview/images/kubedb_plus_kubestash.svg create mode 100644 docs/guides/mysql/backup/kubestash/overview/images/restore_overview.svg create mode 100644 docs/guides/mysql/backup/kubestash/overview/index.md create mode 100644 docs/guides/mysql/backup/stash/_index.md rename docs/guides/mysql/backup/{ => stash}/auto-backup/examples/backupblueprint.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/auto-backup/examples/sample-mysql-2.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/auto-backup/examples/sample-mysql-3.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/auto-backup/examples/sample-mysql.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/auto-backup/images/sample-mysql-2.png (100%) rename docs/guides/mysql/backup/{ => stash}/auto-backup/images/sample-mysql-3.png (100%) rename docs/guides/mysql/backup/{ => stash}/auto-backup/images/sample-mysql.png (100%) rename docs/guides/mysql/backup/{ => stash}/auto-backup/index.md (97%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/backup/multi-retention-policy.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/backup/passing-args.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/backup/resource-limit.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/backup/specific-user.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/repository.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/restore/passing-args.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/restore/resource-limit.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/restore/specific-snapshot.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/restore/specific-user.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/examples/sample-mysql.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/customization/index.md (98%) rename docs/guides/mysql/backup/{ => stash}/overview/images/backup_overview.svg (100%) rename docs/guides/mysql/backup/{ => stash}/overview/images/restore_overview.svg (100%) rename docs/guides/mysql/backup/{ => stash}/overview/index.md (94%) rename docs/guides/mysql/backup/{ => stash}/standalone/examples/backupconfiguration.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/standalone/examples/repository.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/standalone/examples/restored-mysql.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/standalone/examples/restoresession.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/standalone/examples/sample-mysql.yaml (100%) rename docs/guides/mysql/backup/{ => stash}/standalone/images/sample-mysql-backup.png (100%) rename docs/guides/mysql/backup/{ => stash}/standalone/index.md (97%) diff --git a/docs/guides/mysql/README.md b/docs/guides/mysql/README.md index 8e3ce1fa6..ad11191d1 100644 --- a/docs/guides/mysql/README.md +++ b/docs/guides/mysql/README.md @@ -45,7 +45,7 @@ aliases: ## User Guide - [Quickstart MySQL](/docs/guides/mysql/quickstart/index.md) with KubeDB Operator. -- [Backup & Restore](/docs/guides/mysql/backup/overview/index.md) MySQL databases using Stash. +- [Backup & Restore](/docs/guides/mysql/backup/stash/overview/index.md) MySQL databases using Stash. - Initialize [MySQL with Script](/docs/guides/mysql/initialization/index.md). - Monitor your MySQL database with KubeDB using [out-of-the-box Prometheus operator](/docs/guides/mysql/monitoring/prometheus-operator/index.md). - Monitor your MySQL database with KubeDB using [out-of-the-box builtin-Prometheus](/docs/guides/mysql/monitoring/builtin-prometheus/index.md). diff --git a/docs/guides/mysql/backup/kubestash/_index.md b/docs/guides/mysql/backup/kubestash/_index.md new file mode 100644 index 000000000..a5d2844a6 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/_index.md @@ -0,0 +1,10 @@ +--- +title: Backup & Restore MySQL | KubeStash +menu: + docs_{{ .version }}: + identifier: guides-mysql-backup-stashv2 + name: KubeStash (aka Stash 2.0) + parent: guides-mysql-backup + weight: 50 +menu_name: docs_{{ .version }} +--- \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/application-level/examples/backupconfiguration.yaml b/docs/guides/mysql/backup/kubestash/application-level/examples/backupconfiguration.yaml new file mode 100644 index 000000000..4d9e1fbae --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/application-level/examples/backupconfiguration.yaml @@ -0,0 +1,37 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: manifest-backup + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/application-level/examples/backupstorage.yaml b/docs/guides/mysql/backup/kubestash/application-level/examples/backupstorage.yaml new file mode 100644 index 000000000..0461b2676 --- /dev/null +++ b/docs/guides/mysql/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: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/application-level/examples/restoresession.yaml b/docs/guides/mysql/backup/kubestash/application-level/examples/restoresession.yaml new file mode 100644 index 000000000..fa1fe6e95 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/application-level/examples/restoresession.yaml @@ -0,0 +1,21 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-mysql + namespace: demo +spec: + manifestOptions: + restoreNamespace: dev + mySQL: + db: true + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup-restore + - name: manifest-restore \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/application-level/examples/retentionpolicy.yaml b/docs/guides/mysql/backup/kubestash/application-level/examples/retentionpolicy.yaml new file mode 100644 index 000000000..459156286 --- /dev/null +++ b/docs/guides/mysql/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/mysql/backup/kubestash/application-level/examples/sample-mysql.yaml b/docs/guides/mysql/backup/kubestash/application-level/examples/sample-mysql.yaml new file mode 100644 index 000000000..89aa071fe --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/application-level/examples/sample-mysql.yaml @@ -0,0 +1,18 @@ +apiVersion: kubedb.com/v1 +kind: MySQL +metadata: + name: sample-mysql + namespace: demo +spec: + version: "8.2.0" + replicas: 3 + topology: + mode: GroupReplication + storageType: Durable + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/application-level/index.md b/docs/guides/mysql/backup/kubestash/application-level/index.md new file mode 100644 index 000000000..95d10be83 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/application-level/index.md @@ -0,0 +1,759 @@ +--- +title: Application Level Backup & Restore MySQL | KubeStash +description: Application Level Backup and Restore using KubeStash +menu: + docs_{{ .version }}: + identifier: guides-application-level-backup-stashv2 + name: Application Level Backup + parent: guides-mysql-backup-stashv2 + weight: 40 +menu_name: docs_{{ .version }} +section_menu_id: guides +--- + +# Application Level Backup and Restore MySQL database using KubeStash + +KubeStash offers application-level backup and restore functionality for `MySQL` databases. It captures both manifest and logical data backups of any `MySQL` database in a single snapshot. During the restore process, KubeStash first applies the `MySQL` 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 `MySQL` 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 MySQL databases, please check the following guide [here](/docs/guides/mysql/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/mysql/backup/kubestash/application-level/examples](docs/guides/workloads/mysql/backup/kubestash/application-level/examples) directory of [kubedb/docs](https://github.com/kubedb/docs) repository. + +## Backup MySQL + +KubeStash supports backups for `MySQL` instances across different configurations, including Standalone, Group Replication, and InnoDB Cluster setups. In this demonstration, we'll focus on a `MySQL` database using Group Replication. The backup and restore process is similar for Standalone and InnoDB Cluster configurations as well. + +This section will demonstrate how to take application-level backup of a `MySQL` database. Here, we are going to deploy a `MySQL` 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 `MySQL` database. + +### Deploy Sample MySQL Database + +Let's deploy a sample `MySQL` database and insert some data into it. + +**Create MySQL CR:** + +Below is the YAML of a sample `MySQL` CR that we are going to create for this tutorial: + +```yaml +apiVersion: kubedb.com/v1 +kind: MySQL +metadata: + name: sample-mysql + namespace: demo +spec: + version: "8.2.0" + replicas: 3 + topology: + mode: GroupReplication + storageType: Durable + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + deletionPolicy: WipeOut +``` + +Here, +- `.spec.topology` specifies about the clustering configuration of MySQL. +- `.Spec.topology.mode` specifies the mode of MySQL Cluster. During the demonstration we consider to use `GroupReplication`. + +Create the above `MySQL` CR, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/kubestash/application-level/examples/sample-mysql.yaml +mysql.kubedb.com/sample-mysql created +``` + +KubeDB will deploy a MySQL 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 secret -n demo -l=app.kubernetes.io/instance=sample-mysql +NAME VERSION STATUS AGE +sample-mysql 8.2.0 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 +NAME TYPE DATA AGE +sample-mysql-auth Opaque 2 4m58s + +$ kubectl get service -n demo -l=app.kubernetes.io/instance=sample-mysql +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +sample-mysql ClusterIP 10.101.2.138 3306/TCP 5m33s +sample-mysql-pods ClusterIP None 3306/TCP 5m33s +``` + +Here, we have to use service `sample-mysql` and secret `sample-mysql-auth` 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-mysql 9m24s +``` + +Let's check the YAML of the above `AppBinding`, + +```bash +$ kubectl get appbindings -n demo sample-mysql -o yaml +``` + +```yaml +apiVersion: appcatalog.appscode.com/v1alpha1 +kind: AppBinding +metadata: + labels: + app.kubernetes.io/component: database + app.kubernetes.io/instance: sample-mysql + app.kubernetes.io/managed-by: kubedb.com + app.kubernetes.io/name: mysqls.kubedb.com + name: sample-mysql + namespace: demo + ownerReferences: + - apiVersion: kubedb.com/v1 + blockOwnerDeletion: true + controller: true + kind: MySQL + name: sample-mysql + uid: edde3e8b-7775-4f91-85a9-4ba4b96315f7 + resourceVersion: "5126" + uid: 86c9a149-f8ab-44c4-947f-5f9b402aad6c +spec: + appRef: + apiGroup: kubedb.com + kind: MySQL + name: sample-mysql + namespace: demo + clientConfig: + service: + name: sample-mysql + path: / + port: 3306 + scheme: tcp + url: tcp(sample-mysql.demo.svc:3306)/ + ... + ... + secret: + name: sample-mysql-auth + type: kubedb.com/mysql + version: 8.2.0 +``` + +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.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 database 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-mysql" +NAME READY STATUS RESTARTS AGE +sample-mysql-0 2/2 Running 0 33m +sample-mysql-1 2/2 Running 0 33m +sample-mysql-2 2/2 Running 0 33m +``` + +And copy the username and password of the `root` user to access into `mysql` shell. + +```bash +$ kubectl get secret -n demo sample-mysql-auth -o jsonpath='{.data.username}'| base64 -d +root⏎ + +$ kubectl get secret -n demo sample-mysql-auth -o jsonpath='{.data.password}'| base64 -d +DZfmUZd14fNEEOU4⏎ +``` + +Now, Lets exec into the Pod to enter into `mysql` shell and create a database and a table, + +```bash +$ kubectl exec -it -n demo sample-mysql-0 -- mysql --user=root --password=DZfmUZd14fNEEOU4 +Defaulted container "mysql" out of: mysql, mysql-init (init) +mysql: [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 977 +Server version: 8.2.0 MySQL Community Server - GPL + +Copyright (c) 2000, 2023, 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. + +mysql> CREATE DATABASE playground; +Query OK, 1 row affected (0.01 sec) + +mysql> SHOW DATABASES; ++--------------------+ +| Database | ++--------------------+ +| information_schema | +| mysql | +| performance_schema | +| playground | +| sys | ++--------------------+ +5 rows in set (0.00 sec) + +mysql> 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 (0.01 sec) + +mysql> SHOW TABLES IN playground; ++----------------------+ +| Tables_in_playground | ++----------------------+ +| equipment | ++----------------------+ +1 row in set (0.01 sec) + +mysql> INSERT INTO playground.equipment (type, quant, color) VALUES ("slide", 2, "blue"); +Query OK, 1 row affected (0.01 sec) + +mysql> SELECT * FROM playground.equipment; ++----+-------+-------+-------+ +| id | type | quant | color | ++----+-------+-------+-------+ +| 1 | slide | 2 | blue | ++----+-------+-------+-------+ +1 row in set (0.00 sec) + +mysql> 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: WipeOut +``` + +Let's create the BackupStorage we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/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/mysql/backup/kubestash/application-level/examples/retentionpolicy.yaml +retentionpolicy.storage.kubestash.com/demo-retention created +``` + +### Backup + +We have to create a `BackupConfiguration` targeting respective `sample-mysql` MySQL 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-mysql` database that we have deployed earlier, + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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-mysql` MySQL database that we created earlier. +- `.spec.sessions[*].addon.tasks[*].name[*]` specifies that both the `manifest-backup` and `logical-backup` will be taken together. + +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/mysql/backup/kubestash/application-level/examples/backupconfiguration.yaml +backupconfiguration.core.kubestash.com/sample-mysql-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-mysql-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-mysql-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/mysql` 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-mysql-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-mysql-backup-frequent-backup-1724065200 BackupConfiguration sample-mysql-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-mysql-backup` has been updated by the following command, + +```bash +$ kubectl get repository -n demo sample-mysql-backup +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +sample-mysql-backup 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-mysql-repo-sample-mysql-backup-frequent-backup-1725359100 gcs-demo-repo 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-mysql-repo-sample-mysql-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: + kubedb.com/db-version: 8.2.0 + kubestash.com/app-ref-kind: MySQL + kubestash.com/app-ref-name: sample-mysql + kubestash.com/app-ref-namespace: demo + kubestash.com/repo-name: gcs-mysql-repo + name: gcs-mysql-repo-sample-mysql-backup-frequent-backup-1725359100 + namespace: demo + ownerReferences: + - apiVersion: storage.kubestash.com/v1alpha1 + blockOwnerDeletion: true + controller: true + kind: Repository + name: gcs-mysql-repo + uid: 1f5ba355-7f99-4b99-8bbf-9f9d4f31c52a + resourceVersion: "213010" + uid: 18cabb10-e594-4655-8763-3daa0872508e +spec: + appRef: + apiGroup: kubedb.com + kind: MySQL + name: sample-mysql + namespace: demo + backupSession: sample-mysql-backup-frequent-backup-1725359100 + deletionPolicy: Delete + repository: gcs-mysql-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 MySQL databases. Therefore, the component name for `logical backup` is set as `dump`. +> KubeStash set component name as `manifest` for the `manifest backup` of MySQL databases. + +Now, if we navigate to the GCS bucket, we will see the backed up data stored in the `demo/mysql/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-mysql + namespace: demo +spec: + manifestOptions: + restoreNamespace: dev + mySQL: + db: true + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup-restore + - name: manifest-restore +``` + +Here, + +- `.spec.manifestOptions.mySQL.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/mysql/backup/kubestash/application-level/examples/restoresession.yaml +restoresession.core.kubestash.com/sample-mysql-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 MySQL Manifest: + +In this section, we will verify whether the desired `MySQL` database manifest has been successfully applied to the cluster. + +```bash +$ kubectl get mysqls.kubedb.com -n dev +NAME VERSION STATUS AGE +sample-mysql 8.2.0 Ready 39m +``` + +The output confirms that the `MySQL` 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 my -n dev sample-mysql +NAME VERSION STATUS AGE +sample-mysql 8.2.0 Ready 4m +``` + +Now, find out the database `Pod` by the following command, + +```bash +$ kubectl get pods -n dev --selector="app.kubernetes.io/instance=sample-mysql" +NAME READY STATUS RESTARTS AGE +sample-mysql-0 2/2 Running 0 2m +sample-mysql-1 2/2 Running 0 2m +sample-mysql-2 2/2 Running 0 2m +``` + +And then copy the username and password of the `root` user to access into `mysql` shell. + +```bash +$ kubectl get secret -n dev sample-mysql-auth -o jsonpath='{.data.username}'| base64 -d +root + +$ kubectl get secret -n dev sample-mysql-auth -o jsonpath='{.data.password}'| base64 -d +QMm1hi0T*7QFz_yh +``` + +```bash +$ kubectl exec -it -n dev sample-mysql-0 -- mysql --user=root --password='QMm1hi0T*7QFz_yh' +Defaulted container "mysql" out of: mysql, mysql-coordinator, mysql-init (init) +mysql: [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 243 +Server version: 8.2.0 MySQL Community Server - GPL + +Copyright (c) 2000, 2023, 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. + +mysql> SHOW DATABASES; ++--------------------+ +| Database | ++--------------------+ +| information_schema | +| mysql | +| performance_schema | +| playground | +| sys | ++--------------------+ +5 rows in set (0.00 sec) + +mysql> SHOW TABLES IN playground; ++----------------------+ +| Tables_in_playground | ++----------------------+ +| equipment | ++----------------------+ +1 row in set (0.00 sec) + +mysql> SELECT * FROM playground.equipment; ++----+-------+-------+-------+ +| id | type | quant | color | ++----+-------+-------+-------+ +| 1 | slide | 2 | blue | ++----+-------+-------+-------+ +1 row in set (0.00 sec) + +mysql> 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-mysql-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-mysql +kubectl delete my -n demo sample-mysql +kubectl delete my -n dev sample-mysql +``` \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/auto-backup/examples/backupstorage.yaml b/docs/guides/mysql/backup/kubestash/auto-backup/examples/backupstorage.yaml new file mode 100644 index 000000000..246626b9b --- /dev/null +++ b/docs/guides/mysql/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: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml b/docs/guides/mysql/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml new file mode 100644 index 000000000..ba21426d0 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml @@ -0,0 +1,41 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupBlueprint +metadata: + name: mysql-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: mysql-addon + tasks: + - name: logical-backup + params: + databases: ${targetedDatabases} \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml b/docs/guides/mysql/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml new file mode 100644 index 000000000..9e9f1f76e --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml @@ -0,0 +1,37 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupBlueprint +metadata: + name: mysql-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: mysql-addon + tasks: + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/auto-backup/examples/retentionpolicy.yaml b/docs/guides/mysql/backup/kubestash/auto-backup/examples/retentionpolicy.yaml new file mode 100644 index 000000000..459156286 --- /dev/null +++ b/docs/guides/mysql/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/mysql/backup/kubestash/auto-backup/examples/sample-mysql-2.yaml b/docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql-2.yaml new file mode 100644 index 000000000..3d59b9a1a --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql-2.yaml @@ -0,0 +1,25 @@ +apiVersion: kubedb.com/v1alpha2 +kind: MySQL +metadata: + name: sample-mysql-2 + namespace: demo + annotations: + blueprint.kubestash.com/name: mysql-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-mysql-2 + variables.kubestash.com/targetedDatabases: mysql +spec: + version: "8.2.0" + replicas: 1 + storageType: Durable + storage: + storageClassName: "standard" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + terminationPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql.yaml b/docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql.yaml new file mode 100644 index 000000000..8ca2d92ea --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql.yaml @@ -0,0 +1,20 @@ +apiVersion: kubedb.com/v1alpha2 +kind: MySQL +metadata: + name: sample-mysql + namespace: demo + annotations: + blueprint.kubestash.com/name: mysql-default-backup-blueprint + blueprint.kubestash.com/namespace: demo +spec: + version: "8.2.0" + replicas: 1 + storageType: Durable + storage: + storageClassName: "standard" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + terminationPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/auto-backup/index.md b/docs/guides/mysql/backup/kubestash/auto-backup/index.md new file mode 100644 index 000000000..f87a55135 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/auto-backup/index.md @@ -0,0 +1,735 @@ +--- +title: MySQL Auto-Backup | KubeStash +description: Backup MySQL using KubeStash Auto-Backup +menu: + docs_{{ .version }}: + identifier: guides-mysql-backup-auto-backup-stashv2 + name: Auto-Backup + parent: guides-mysql-backup-stashv2 + weight: 30 +menu_name: docs_{{ .version }} +section_menu_id: guides +--- + +# Backup MySQL using KubeStash Auto-Backup + +KubeStash can automatically be configured to backup any `MySQL` databases in your cluster. KubeStash enables cluster administrators to deploy backup `blueprints` ahead of time so database owners can easily backup any `MySQL` database with a few annotations. + +In this tutorial, we are going to show how you can configure a backup blueprint for `MySQL` 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 MySQL databases, please check the following guide [here](/docs/guides/mysql/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: WipeOut +``` + +Let's create the BackupStorage we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/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/mysql/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 `MySQL` 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: mysql-default-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: "*/5 * * * *" + jobTemplate: + backoffLimit: 1 + repositories: + - name: default-blueprint + backend: gcs-backend + directory: /default-blueprint + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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/mysql/backup/kubestash/auto-backup/examples/default-backupblueprint.yaml +backupblueprint.core.kubestash.com/mysql-default-backup-blueprint created +``` + +Now, we are ready to backup our `MySQL` 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 `MySQL` CR in demo namespace. Below is the YAML of the MySQL object that we are going to create, + +```yaml +apiVersion: kubedb.com/v1alpha2 +kind: MySQL +metadata: + name: sample-mysql + namespace: demo + annotations: + blueprint.kubestash.com/name: mysql-default-backup-blueprint + blueprint.kubestash.com/namespace: demo +spec: + version: "8.2.0" + replicas: 1 + storageType: Durable + storage: + storageClassName: "standard" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + terminationPolicy: WipeOut +``` + +Here, + +- `.spec.annotations.blueprint.kubestash.com/name: mysql-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 `MySQL` we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql.yaml +mysql.kubedb.com/sample-mysql created +``` + +**Verify BackupConfiguration** + +If everything goes well, KubeStash should create a `BackupConfiguration` for our MySQL 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-mysql Ready 2m50m +``` + +Now, let’s check the YAML of the `BackupConfiguration`. + +```bash +$ kubectl get backupconfiguration -n demo appbinding-sample-mysql -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: mysql-default-backup-blueprint + kubestash.com/invoker-namespace: demo + name: appbinding-sample-mysql + 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: mysql-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: MySQL + name: sample-mysql + 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-mysql-frequent-backup-1724236500 BackupConfiguration appbinding-sample-mysql 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-sampleysql-frequent-backup-1724236500 default-blueprint 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 default-blueprint-appbinding-sampleysql-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: + kubestash.com/app-ref-kind: MySQL + kubestash.com/app-ref-name: sample-mysql + kubestash.com/app-ref-namespace: demo + kubestash.com/repo-name: default-blueprint + name: default-blueprint-appbinding-sampleysql-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: MySQL + name: sample-mysql + namespace: demo + backupSession: appbinding-sample-mysql-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 MySQL 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 `MySQL` 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: mysql-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: mysql-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/mysql/backup/kubestash/auto-backup/examples/customize-backupblueprint.yaml +backupblueprint.core.kubestash.com/mysql-customize-backup-blueprint created +``` + +Now, we are ready to backup our `MySQL` 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 `MySQL` CR in demo namespace. Below is the YAML of the MySQL object that we are going to create, + +```yaml +apiVersion: kubedb.com/v1alpha2 +kind: MySQL +metadata: + name: sample-mysql-2 + namespace: demo + annotations: + blueprint.kubestash.com/name: mysql-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-mysql-2 + variables.kubestash.com/targetedDatabases: mysql +spec: + version: "8.2.0" + replicas: 1 + storageType: Durable + storage: + storageClassName: "standard" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + terminationPolicy: 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 `mysql-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`, `targetName`, and `targetedDatabases`. These annotations will be used to create a `BackupConfiguration` for this `MySQL` database. + +Let's create the `MySQL` we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/kubestash/auto-backup/examples/sample-mysql-2.yaml +mysql.kubedb.com/sample-mysql-2 created +``` + +**Verify BackupConfiguration** + +If everything goes well, KubeStash should create a `BackupConfiguration` for our MySQL 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-mysql-2 Ready 2m50m +``` + +Now, let’s check the YAML of the `BackupConfiguration`. + +```bash +$ kubectl get backupconfiguration -n demo appbinding-sample-mysql-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: mysql-customize-backup-blueprint + kubestash.com/invoker-namespace: demo + name: appbinding-sample-mysql-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: mysql-addon + tasks: + - name: logical-backup + params: + databases: mysql + name: frequent-backup + repositories: + - backend: gcs-backend + directory: demo/sample-mysql-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: MySQL + name: sample-mysql-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-mysql-2-frequent-backup-1725007200 BackupConfiguration appbinding-sample-mysql-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-sql-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: +> - `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-sql-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: + kubestash.com/app-ref-kind: MySQL + kubestash.com/app-ref-name: sample-mysql + kubestash.com/app-ref-namespace: demo + kubestash.com/repo-name: customize-blueprint + name: customize-blueprint-appbinding-sql-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: MySQL + name: sample-mysql-2 + namespace: demo + backupSession: appbinding-sample-mysql-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 MySQL 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 mysql-default-backup-blueprint +kubectl delete backupblueprints.core.kubestash.com -n demo mysql-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-mysql +kubectl delete my -n demo sample-mysql-2 +``` \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/backup/multiple-repository.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/backup/multiple-repository.yaml new file mode 100644 index 000000000..c86e30c40 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/backup/multiple-repository.yaml @@ -0,0 +1,42 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + - name: gcs-mysql-repo-2 + backend: gcs-backend + directory: /mysql-copy + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/backup/passing-args.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/backup/passing-args.yaml new file mode 100644 index 000000000..5a537a522 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/backup/passing-args.yaml @@ -0,0 +1,38 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup + params: + args: --set-gtid-purged=OFF \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/backup/passing-databases.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/backup/passing-databases.yaml new file mode 100644 index 000000000..4483696ee --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/backup/passing-databases.yaml @@ -0,0 +1,38 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup + params: + databases: db1,db2,db3 \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/backup/resources-limit.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/backup/resources-limit.yaml new file mode 100644 index 000000000..5b247de5d --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/backup/resources-limit.yaml @@ -0,0 +1,46 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + jobTemplate: + spec: + resources: + requests: + cpu: "200m" + memory: "1Gi" + limits: + cpu: "200m" + memory: "1Gi" + tasks: + - name: logical-backup + diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/backup/specific-user.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/backup/specific-user.yaml new file mode 100644 index 000000000..07cf18c8e --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/backup/specific-user.yaml @@ -0,0 +1,41 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + jobTemplate: + spec: + securityContext: + runAsUser: 0 + runAsGroup: 0 + tasks: + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/common/backupstorage.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/common/backupstorage.yaml new file mode 100644 index 000000000..0461b2676 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/common/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: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/common/retentionpolicy.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/common/retentionpolicy.yaml new file mode 100644 index 000000000..459156286 --- /dev/null +++ b/docs/guides/mysql/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/mysql/backup/kubestash/customization/examples/common/sample-mysql.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/common/sample-mysql.yaml new file mode 100644 index 000000000..89aa071fe --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/common/sample-mysql.yaml @@ -0,0 +1,18 @@ +apiVersion: kubedb.com/v1 +kind: MySQL +metadata: + name: sample-mysql + namespace: demo +spec: + version: "8.2.0" + replicas: 3 + topology: + mode: GroupReplication + storageType: Durable + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/restore/passing-args.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/restore/passing-args.yaml new file mode 100644 index 000000000..044a22fde --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/restore/passing-args.yaml @@ -0,0 +1,23 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup-restore + params: + args: --one-database=testdb \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/restore/resources-limit.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/restore/resources-limit.yaml new file mode 100644 index 000000000..d4d292432 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/restore/resources-limit.yaml @@ -0,0 +1,30 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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/mysql/backup/kubestash/customization/examples/restore/specific-snapshot.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/restore/specific-snapshot.yaml new file mode 100644 index 000000000..861911e5e --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/restore/specific-snapshot.yaml @@ -0,0 +1,21 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: gcs-mysql-repo-sample-mysql-backup-frequent-backup-1725257849 + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup-restore diff --git a/docs/guides/mysql/backup/kubestash/customization/examples/restore/specific-user.yaml b/docs/guides/mysql/backup/kubestash/customization/examples/restore/specific-user.yaml new file mode 100644 index 000000000..1c3944573 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/examples/restore/specific-user.yaml @@ -0,0 +1,26 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + jobTemplate: + spec: + securityContext: + runAsUser: 0 + runAsGroup: 0 + tasks: + - name: logical-backup-restore diff --git a/docs/guides/mysql/backup/kubestash/customization/index.md b/docs/guides/mysql/backup/kubestash/customization/index.md new file mode 100644 index 000000000..a76080216 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/customization/index.md @@ -0,0 +1,437 @@ +--- +title: MySQL Backup Customization | KubeStash +description: Customizing MySQL Backup and Restore process with KubeStash +menu: + docs_{{ .version }}: + identifier: guides-mysql-backup-customization-stashv2 + name: Customizing Backup & Restore Process + parent: guides-mysql-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 MySQL addon uses [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-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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 `myaql-addon` add `--alll-databases` options during backup. If you want to backup all databases keep the `databases` params empty. + +### Passing arguments to the backup process + +KubeStash MySQL 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-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup + params: + args: --set-gtid-purged=OFF +``` + + +### Using multiple repositories + +You can configure multiple repositories for the same backend. For example, if you want to back up the `/mysql` directory using the `gcs-mysql-repo` repository, you can also back up another directory, such as `/mysql-copy`, by using a different repository, like `gcs-mysql-repo-2`. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + - name: gcs-mysql-repo-2 + backend: gcs-backend + directory: /mysql-copy + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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 `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. + +This example will restore data from database `testdb` only. + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup + 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-mysql-repo +NAME REPOSITORY SESSION SNAPSHOT-TIME DELETION-POLICY PHASE AGE +gcs-mysql-repo-sample-mysql-backup-frequent-backup-1725257849 gcs-mysql-repo frequent-backup 2024-09-02T06:18:01Z Delete Succeeded 15m +gcs-mysql-repo-sample-mysql-backup-frequent-backup-1725258000 gcs-mysql-repo frequent-backup 2024-09-02T06:20:00Z Delete Succeeded 13m +gcs-mysql-repo-sample-mysql-backup-frequent-backup-1725258300 gcs-mysql-repo frequent-backup 2024-09-02T06:25:00Z Delete Succeeded 8m34s +gcs-mysql-repo-sample-mysql-backup-frequent-backup-1725258600 gcs-mysql-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-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup-restore + params: + args: --one-database=testdb +``` + + +### 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-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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/mysql/backup/kubestash/logical/examples/backupconfiguration.yaml b/docs/guides/mysql/backup/kubestash/logical/examples/backupconfiguration.yaml new file mode 100644 index 000000000..0ca97ba74 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/logical/examples/backupconfiguration.yaml @@ -0,0 +1,36 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/logical/examples/backupstorage.yaml b/docs/guides/mysql/backup/kubestash/logical/examples/backupstorage.yaml new file mode 100644 index 000000000..0461b2676 --- /dev/null +++ b/docs/guides/mysql/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: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/logical/examples/restored-mysql.yaml b/docs/guides/mysql/backup/kubestash/logical/examples/restored-mysql.yaml new file mode 100644 index 000000000..e1131b2f2 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/logical/examples/restored-mysql.yaml @@ -0,0 +1,20 @@ +apiVersion: kubedb.com/v1 +kind: MySQL +metadata: + name: restored-mysql + namespace: demo +spec: + init: + waitForInitialRestore: true + version: "8.2.0" + replicas: 3 + topology: + mode: GroupReplication + storageType: Durable + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/logical/examples/restoresession.yaml b/docs/guides/mysql/backup/kubestash/logical/examples/restoresession.yaml new file mode 100644 index 000000000..2438d4533 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/logical/examples/restoresession.yaml @@ -0,0 +1,21 @@ +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup-restore diff --git a/docs/guides/mysql/backup/kubestash/logical/examples/retentionpolicy.yaml b/docs/guides/mysql/backup/kubestash/logical/examples/retentionpolicy.yaml new file mode 100644 index 000000000..459156286 --- /dev/null +++ b/docs/guides/mysql/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/mysql/backup/kubestash/logical/examples/sample-mysql.yaml b/docs/guides/mysql/backup/kubestash/logical/examples/sample-mysql.yaml new file mode 100644 index 000000000..89aa071fe --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/logical/examples/sample-mysql.yaml @@ -0,0 +1,18 @@ +apiVersion: kubedb.com/v1 +kind: MySQL +metadata: + name: sample-mysql + namespace: demo +spec: + version: "8.2.0" + replicas: 3 + topology: + mode: GroupReplication + storageType: Durable + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + deletionPolicy: WipeOut \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/logical/index.md b/docs/guides/mysql/backup/kubestash/logical/index.md new file mode 100644 index 000000000..4301e84a3 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/logical/index.md @@ -0,0 +1,753 @@ +--- +title: Backup & Restore MySQL | KubeStash +description: Backup MySQL database using KubeStash +menu: + docs_{{ .version }}: + identifier: guides-mysql-logical-backup-stashv2 + name: Logical Backup + parent: guides-mysql-backup-stashv2 + weight: 20 +menu_name: docs_{{ .version }} +section_menu_id: guides +--- + +# Backup and Restore MySQL database using KubeStash + +KubeStash allows you to backup and restore `MySQL` databases. It supports backups for `MySQL` instances running in Standalone, Group Replication, and InnoDB cluster configurations. KubeStash makes managing your `MySQL` backups and restorations more straightforward and efficient. + +This guide will give you how you can take backup and restore your `MySQL` 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 MySQL databases, please check the following guide [here](/docs/guides/mysql/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/mysql/backup/kubestash/logical/examples](docs/guides/workloads/mysql/backup/kubestash/logical/examples) directory of [kubedb/docs](https://github.com/kubedb/docs) repository. + + +## Backup MySQL +KubeStash supports backups for `MySQL` instances across different configurations, including Standalone, Group Replication, and InnoDB Cluster setups. In this demonstration, we'll focus on a `MySQL` database using Group Replication. The backup and restore process is similar for Standalone and InnoDB Cluster configurations as well. + +This section will demonstrate how to backup a `MySQL` database. Here, we are going to deploy a `MySQL` 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 `MySQL` database. + +### Deploy Sample MySQL Database + +Let's deploy a sample `MySQL` database and insert some data into it. + +**Create MySQL CR:** + +Below is the YAML of a sample `MySQL` CRD that we are going to create for this tutorial: + +```yaml +apiVersion: kubedb.com/v1 +kind: MySQL +metadata: + name: sample-mysql + namespace: demo +spec: + version: "8.2.0" + replicas: 3 + topology: + mode: GroupReplication + storageType: Durable + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + deletionPolicy: WipeOut +``` + +Here, +- `.spec.topology` specifies about the clustering configuration of MySQL. +- `.Spec.topology.mode` specifies the mode of MySQL Cluster. During the demonstration we consider to use `GroupReplication`. + +Create the above `MySQL` CR, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/kubestash/logical/examples/sample-mysql.yaml +mysql.kubedb.com/sample-mysql created +``` + +KubeDB will deploy a MySQL 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 secret -n demo -l=app.kubernetes.io/instance=sample-mysql +NAME VERSION STATUS AGE +sample-mysql 8.2.0 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 +NAME TYPE DATA AGE +sample-mysql-auth Opaque 2 4m58s + +$ kubectl get service -n demo -l=app.kubernetes.io/instance=sample-mysql +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +sample-mysql ClusterIP 10.101.2.138 3306/TCP 5m33s +sample-mysql-pods ClusterIP None 3306/TCP 5m33s +``` + +Here, we have to use service `sample-mysql` and secret `sample-mysql-auth` 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-mysql 9m24s +``` + +Let's check the YAML of the above `AppBinding`, + +```bash +$ kubectl get appbindings -n demo sample-mysql -o yaml +``` + +```yaml +apiVersion: appcatalog.appscode.com/v1alpha1 +kind: AppBinding +metadata: + labels: + app.kubernetes.io/component: database + app.kubernetes.io/instance: sample-mysql + app.kubernetes.io/managed-by: kubedb.com + app.kubernetes.io/name: mysqls.kubedb.com + name: sample-mysql + namespace: demo + ownerReferences: + - apiVersion: kubedb.com/v1 + blockOwnerDeletion: true + controller: true + kind: MySQL + name: sample-mysql + uid: edde3e8b-7775-4f91-85a9-4ba4b96315f7 + resourceVersion: "5126" + uid: 86c9a149-f8ab-44c4-947f-5f9b402aad6c +spec: + appRef: + apiGroup: kubedb.com + kind: MySQL + name: sample-mysql + namespace: demo + clientConfig: + service: + name: sample-mysql + path: / + port: 3306 + scheme: tcp + url: tcp(sample-mysql.demo.svc:3306)/ + ... + ... + secret: + name: sample-mysql-auth + type: kubedb.com/mysql + version: 8.2.0 +``` + +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.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 database 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-mysql" +NAME READY STATUS RESTARTS AGE +sample-mysql-0 1/1 Running 0 33m +``` + +And copy the username and password of the `root` user to access into `mysql` shell. + +```bash +$ kubectl get secret -n demo sample-mysql-auth -o jsonpath='{.data.username}'| base64 -d +root⏎ + +$ kubectl get secret -n demo sample-mysql-auth -o jsonpath='{.data.password}'| base64 -d +DZfmUZd14fNEEOU4⏎ +``` + +Now, Lets exec into the Pod to enter into `mysql` shell and create a database and a table, + +```bash +$ kubectl exec -it -n demo sample-mysql-0 -- mysql --user=root --password=DZfmUZd14fNEEOU4 +Defaulted container "mysql" out of: mysql, mysql-init (init) +mysql: [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 977 +Server version: 8.2.0 MySQL Community Server - GPL + +Copyright (c) 2000, 2023, 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. + +mysql> CREATE DATABASE playground; +Query OK, 1 row affected (0.01 sec) + +mysql> SHOW DATABASES; ++--------------------+ +| Database | ++--------------------+ +| information_schema | +| mysql | +| performance_schema | +| playground | +| sys | ++--------------------+ +5 rows in set (0.00 sec) + +mysql> 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 (0.01 sec) + +mysql> SHOW TABLES IN playground; ++----------------------+ +| Tables_in_playground | ++----------------------+ +| equipment | ++----------------------+ +1 row in set (0.01 sec) + +mysql> INSERT INTO playground.equipment (type, quant, color) VALUES ("slide", 2, "blue"); +Query OK, 1 row affected (0.01 sec) + +mysql> SELECT * FROM playground.equipment; ++----+-------+-------+-------+ +| id | type | quant | color | ++----+-------+-------+-------+ +| 1 | slide | 2 | blue | ++----+-------+-------+-------+ +1 row in set (0.00 sec) + +mysql> 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: WipeOut +``` + +Let's create the BackupStorage we have shown above, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/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/mysql/backup/kubestash/logical/examples/retentionpolicy.yaml +retentionpolicy.storage.kubestash.com/demo-retention created +``` + +### Backup + +We have to create a `BackupConfiguration` targeting respective `sample-mysql` MySQL 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 `sample-mysql` database that we have deployed earlier, + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: BackupConfiguration +metadata: + name: sample-mysql-backup + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: sample-mysql + 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-mysql-repo + backend: gcs-backend + directory: /mysql + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-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 `sample-mysql` MySQL 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/mysql/backup/kubestash/logical/examples/backupconfiguration.yaml +backupconfiguration.core.kubestash.com/sample-mysql-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-mysql-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-mysql-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/mysql` 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-mysql-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-mysql-backup-frequent-backup-1724065200 BackupConfiguration sample-mysql-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-mysql-backup` has been updated by the following command, + +```bash +$ kubectl get repository -n demo sample-mysql-backup +NAME INTEGRITY SNAPSHOT-COUNT SIZE PHASE LAST-SUCCESSFUL-BACKUP AGE +sample-mysql-backup 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-mysql-repo-sample-mysql-backup-frequent-backup-1724065200 gcs-demo-repo 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-mysql-repo-sample-mysql-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: MySQL + kubestash.com/app-ref-name: sample-mysql + kubestash.com/app-ref-namespace: demo + kubestash.com/repo-name: gcs-mysql-repo + name: gcs-mysql-repo-sample-mysql-backup-frequent-backup-1724065200 + namespace: demo + ownerReferences: + - apiVersion: storage.kubestash.com/v1alpha1 + blockOwnerDeletion: true + controller: true + kind: Repository + name: gcs-mysql-repo + uid: 036a2605-0dcc-43bd-a921-363d5c3e8cf0 + resourceVersion: "33742" + uid: d7f14919-4c31-4b46-84e9-0a75f303ad92 +spec: + appRef: + apiGroup: kubedb.com + kind: MySQL + name: sample-mysql + namespace: demo + backupSession: sample-mysql-backup-frequent-backup-1724065200 + deletionPolicy: Delete + repository: gcs-mysql-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 MySQL 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/mysql/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 `sample-mysql` 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 `MySQL` CRD we are going deploy to initialize from backup, + +```yaml +apiVersion: kubedb.com/v1 +kind: MySQL +metadata: + name: restored-mysql + namespace: demo +spec: + init: + waitForInitialRestore: true + version: "8.2.0" + replicas: 3 + topology: + mode: GroupReplication + storageType: Durable + storage: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi + deletionPolicy: WipeOut +``` + +Let's create the above database, + +```bash +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/kubestash/logical/examples/restored-mysql.yaml +mysql.kubedb.com/restored-mysql created +``` + +If you check the database status, you will see it is stuck in **`Provisioning`** state. + +```bash +$ kubectl get my -n demo restored-mysql +NAME VERSION STATUS AGE +restored-mysql 8.2.0 Provisioning 61s +``` + +#### Create RestoreSession: + +Now, we need to create a RestoreSession CRD pointing to targeted `MySQL` 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 MySQL object named `restored-mysql`. + + +```yaml +apiVersion: core.kubestash.com/v1alpha1 +kind: RestoreSession +metadata: + name: restore-sample-mysql + namespace: demo +spec: + target: + apiGroup: kubedb.com + kind: MySQL + namespace: demo + name: restored-mysql + dataSource: + repository: gcs-mysql-repo + snapshot: latest + encryptionSecret: + name: encrypt-secret + namespace: demo + addon: + name: mysql-addon + tasks: + - name: logical-backup-restore +``` + +Here, + +- `.spec.target` refers to the newly created `restored-mysql` MySQL 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/mysql/backup/kubestash/logical/examples/restoresession.yaml +restoresession.core.kubestash.com/sample-mysql-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 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 my -n demo restored-mysql +NAME VERSION STATUS AGE +restored-mysql 8.2.0 Ready 34m +``` + +Now, find out the database `Pod` by the following command, + +```bash +$ kubectl get pods -n demo --selector="app.kubernetes.io/instance=restored-mysql" +NAME READY STATUS RESTARTS AGE +restored-mysql-0 1/1 Running 0 39m +``` + +And then copy the user name and password of the `root` user to access into `mysql` shell. + +```bash +$ kubectl get secret -n demo restored-mysql-auth -o jsonpath='{.data.username}'| base64 -d +root + +$ kubectl get secret -n demo restored-mysql-auth -o jsonpath='{.data.password}'| base64 -d +QMm1hi0T*7QFz_yh +``` + +Now, let's exec into the Pod to enter into `mysql` shell and create a database and a table, + +```bash +$ kubectl exec -it -n demo restored-mysql-0 -- mysql --user=root --password='QMm1hi0T*7QFz_yh' +Defaulted container "mysql" out of: mysql, mysql-coordinator, mysql-init (init) +mysql: [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 243 +Server version: 8.2.0 MySQL Community Server - GPL + +Copyright (c) 2000, 2023, 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. + +mysql> SHOW DATABASES; ++--------------------+ +| Database | ++--------------------+ +| information_schema | +| mysql | +| performance_schema | +| playground | +| sys | ++--------------------+ +5 rows in set (0.00 sec) + +mysql> SHOW TABLES IN playground; ++----------------------+ +| Tables_in_playground | ++----------------------+ +| equipment | ++----------------------+ +1 row in set (0.00 sec) + +mysql> SELECT * FROM playground.equipment; ++----+-------+-------+-------+ +| id | type | quant | color | ++----+-------+-------+-------+ +| 1 | slide | 2 | blue | ++----+-------+-------+-------+ +1 row in set (0.00 sec) + +mysql> 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-mysql-backup +kubectl delete restoresessions.core.kubestash.com -n demo restore-sample-mysql +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 restored-mysql +kubectl delete my -n demo sample-mysql +``` \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/overview/images/backup_overview.svg b/docs/guides/mysql/backup/kubestash/overview/images/backup_overview.svg new file mode 100644 index 000000000..628550b3b --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/overview/images/backup_overview.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/overview/images/kubedb_plus_kubestash.svg b/docs/guides/mysql/backup/kubestash/overview/images/kubedb_plus_kubestash.svg new file mode 100644 index 000000000..380d92d96 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/overview/images/kubedb_plus_kubestash.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/guides/mysql/backup/kubestash/overview/images/restore_overview.svg b/docs/guides/mysql/backup/kubestash/overview/images/restore_overview.svg new file mode 100644 index 000000000..7f20b5ee9 --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/overview/images/restore_overview.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/guides/mysql/backup/kubestash/overview/index.md b/docs/guides/mysql/backup/kubestash/overview/index.md new file mode 100644 index 000000000..c0a50ea7f --- /dev/null +++ b/docs/guides/mysql/backup/kubestash/overview/index.md @@ -0,0 +1,98 @@ +--- +title: Backup & Restore MySQL Overview +menu: + docs_{{ .version }}: + identifier: guides-mysql-backup-kubestash-overview-stashv2 + name: Overview + parent: guides-mysql-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." >}} + +# MySQL 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 `MySQL` database. Open the image in a new tab to see the enlarged version. + +
+  MySQL Backup Overview +
Fig: MySQL 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, she 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 into the target storage. + +4. Then, she creates a `BackupConfiguration` custom resource that specifies the targeted the KubeDB managed `MySQL` database, the `Addon` info with a specified task, etc. It also provides information about one or more repositories, each indicating a path and a `BackupStorage` for storing the backed-up data. + +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. Then, it creates a `CronJob` for each session with the schedule specified in `BackupConfiguration` to trigger backup periodically. + +9. KubeStash operator triggers an instant backup as soon as the `BackupConfiguration` is ready. After that, backups are triggered by the `CronJob` according to the specified schedule. + +10. KubeStash operator watches 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 `MySQL` database. + +14. The backup `Job` reads necessary information (e.g. auth secret, port) to connect with the database from the `AppBinding` crd. It also reads backend information and access credentials from BackupStorage crd, Storage Secret and Repository path respectively. + +15. Then, the `Job` dumps the targeted `MySQL` 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 `MySQL` database. + +## How Restore Process Works + +The following diagram shows how KubeStash restores backed up data into a `MySQL` database. Open the image in a new tab to see the enlarged version. + +
+  Database Restore Overview +
Fig: MySQL Restore Process Overview
+
+ +The restore process consists of the following steps: + +1. At first, a user creates a `MySQL` database where the data will be restored or the user can use the same `MySQL` database. + +2. Then, she creates a `RestoreSession` custom resource that specifies the target `MySQL` database where the backed-up data will be restored. the `Repository` object that points to a `BackupStorage` that holds backend information, and the target `Snapshot`, which will be restored. It also specifies the `Addon` info with task to use to restore. + +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` crd. It also reads backend information and access credentials from `Repository` crd 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[dump]` field of the `RestoreSession` with restore information of the target database. + +## Next Steps + +- Backup a standalone `MySQL` database using KubeStash by following the guides from [here](/docs/guides/mysql/backup/kubestash/standalonedalone/index.md). diff --git a/docs/guides/mysql/backup/stash/_index.md b/docs/guides/mysql/backup/stash/_index.md new file mode 100644 index 000000000..013615086 --- /dev/null +++ b/docs/guides/mysql/backup/stash/_index.md @@ -0,0 +1,10 @@ +--- +title: Backup & Restore MySQL +menu: + docs_{{ .version }}: + identifier: guides-mysql-backup-stashv1 + name: Stash + parent: guides-mysql-backup + weight: 40 +menu_name: docs_{{ .version }} +--- \ No newline at end of file diff --git a/docs/guides/mysql/backup/auto-backup/examples/backupblueprint.yaml b/docs/guides/mysql/backup/stash/auto-backup/examples/backupblueprint.yaml similarity index 100% rename from docs/guides/mysql/backup/auto-backup/examples/backupblueprint.yaml rename to docs/guides/mysql/backup/stash/auto-backup/examples/backupblueprint.yaml diff --git a/docs/guides/mysql/backup/auto-backup/examples/sample-mysql-2.yaml b/docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql-2.yaml similarity index 100% rename from docs/guides/mysql/backup/auto-backup/examples/sample-mysql-2.yaml rename to docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql-2.yaml diff --git a/docs/guides/mysql/backup/auto-backup/examples/sample-mysql-3.yaml b/docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql-3.yaml similarity index 100% rename from docs/guides/mysql/backup/auto-backup/examples/sample-mysql-3.yaml rename to docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql-3.yaml diff --git a/docs/guides/mysql/backup/auto-backup/examples/sample-mysql.yaml b/docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql.yaml similarity index 100% rename from docs/guides/mysql/backup/auto-backup/examples/sample-mysql.yaml rename to docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql.yaml diff --git a/docs/guides/mysql/backup/auto-backup/images/sample-mysql-2.png b/docs/guides/mysql/backup/stash/auto-backup/images/sample-mysql-2.png similarity index 100% rename from docs/guides/mysql/backup/auto-backup/images/sample-mysql-2.png rename to docs/guides/mysql/backup/stash/auto-backup/images/sample-mysql-2.png diff --git a/docs/guides/mysql/backup/auto-backup/images/sample-mysql-3.png b/docs/guides/mysql/backup/stash/auto-backup/images/sample-mysql-3.png similarity index 100% rename from docs/guides/mysql/backup/auto-backup/images/sample-mysql-3.png rename to docs/guides/mysql/backup/stash/auto-backup/images/sample-mysql-3.png diff --git a/docs/guides/mysql/backup/auto-backup/images/sample-mysql.png b/docs/guides/mysql/backup/stash/auto-backup/images/sample-mysql.png similarity index 100% rename from docs/guides/mysql/backup/auto-backup/images/sample-mysql.png rename to docs/guides/mysql/backup/stash/auto-backup/images/sample-mysql.png diff --git a/docs/guides/mysql/backup/auto-backup/index.md b/docs/guides/mysql/backup/stash/auto-backup/index.md similarity index 97% rename from docs/guides/mysql/backup/auto-backup/index.md rename to docs/guides/mysql/backup/stash/auto-backup/index.md index 45962d044..452caad39 100644 --- a/docs/guides/mysql/backup/auto-backup/index.md +++ b/docs/guides/mysql/backup/stash/auto-backup/index.md @@ -3,9 +3,9 @@ title: MySQL Auto-Backup | Stash description: Backup MySQL using Stash Auto-Backup menu: docs_{{ .version }}: - identifier: guides-mysql-backup-auto-backup + identifier: guides-mysql-backup-auto-backup-stashv1 name: Auto-Backup - parent: guides-mysql-backup + parent: guides-mysql-backup-stashv1 weight: 30 menu_name: docs_{{ .version }} section_menu_id: guides @@ -22,7 +22,7 @@ In this tutorial, we are going to show how you can configure a backup blueprint - At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster. - Install Stash in your cluster following the steps [here](https://stash.run/docs/latest/setup/install/stash/). - Install KubeDB in your cluster following the steps [here](/docs/setup/README.md). -- If you are not familiar with how Stash backup and restore MySQL databases, please check the following guide [here](/docs/guides/mysql/backup/overview/index.md). +- If you are not familiar with how Stash backup and restore MySQL databases, please check the following guide [here](/docs/guides/mysql/backup/stash/overview/index.md). - If you are not familiar with how auto-backup works in Stash, please check the following guide [here](https://stash.run/docs/latest/guides/auto-backup/overview/). - If you are not familiar with the available auto-backup options for databases in Stash, please check the following guide [here](https://stash.run/docs/latest/guides/auto-backup/database/). @@ -97,7 +97,7 @@ Notice the `prefix` field of `backend` section. We have used some variables in f Let's create the `BackupBlueprint` we have shown above, ```bash -❯ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/auto-backup/examples/backupblueprint.yaml +❯ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/auto-backup/examples/backupblueprint.yaml backupblueprint.stash.appscode.com/mysql-backup-template created ``` @@ -153,7 +153,7 @@ Notice the `annotations` section. We are pointing to the `BackupBlueprint` that Let's create the above MySQL CRO, ```bash -❯ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/auto-backup/examples/sample-mysql.yaml +❯ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql.yaml mysql.kubedb.com/sample-mysql created ``` @@ -287,7 +287,7 @@ app-sample-mysql-1643879707 BackupConfiguration app-sample-mysql Running Once the backup has been completed successfully, you should see the backed up data has been stored in the bucket at the directory pointed by the `prefix` field of the `Repository`.
- Backup data in GCS Bucket + Backup data in GCS Bucket
Fig: Backup data in GCS Bucket
@@ -339,7 +339,7 @@ Notice the `annotations` section. This time, we have passed a schedule via `stas Let's create the above MySQL CRO, ```bash -❯ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/auto-backup/examples/sample-mysql-2.yaml +❯ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql-2.yaml mysql.kubedb.com/sample-mysql-2 created ``` @@ -476,7 +476,7 @@ demo-2 app-sample-mysql-2-1643880964 BackupConfiguration app-sample-mys Once the backup has been completed successfully, you should see that Stash has created a new directory as pointed by the `prefix` field of the new `Repository` and stored the backed up data there.
- Backup data in GCS Bucket + Backup data in GCS Bucket
Fig: Backup data in GCS Bucket
@@ -528,7 +528,7 @@ Notice the `annotations` section. This time, we have passed an argument via `par Let's create the above MySQL CRO, ```bash -❯ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/auto-backup/examples/sample-mysql-3.yaml +❯ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/auto-backup/examples/sample-mysql-3.yaml mysql.kubedb.com/sample-mysql-3 created ``` @@ -666,7 +666,7 @@ demo-3 app-sample-mysql-3-1643883304 BackupConfiguration app-sample-mys Once the backup has been completed successfully, you should see that Stash has created a new directory as pointed by the `prefix` field of the new `Repository` and stored the backed up data there.
- Backup data in GCS Bucket + Backup data in GCS Bucket
Fig: Backup data in GCS Bucket
@@ -675,7 +675,7 @@ Once the backup has been completed successfully, you should see that Stash has c To cleanup the resources crated by this tutorial, run the following commands, ```bash -❯ kubectl delete -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/auto-backup/examples/ +❯ kubectl delete -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/auto-backup/examples/ backupblueprint.stash.appscode.com "mysql-backup-template" deleted mysql.kubedb.com "sample-mysql-2" deleted mysql.kubedb.com "sample-mysql-3" deleted diff --git a/docs/guides/mysql/backup/customization/examples/backup/multi-retention-policy.yaml b/docs/guides/mysql/backup/stash/customization/examples/backup/multi-retention-policy.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/backup/multi-retention-policy.yaml rename to docs/guides/mysql/backup/stash/customization/examples/backup/multi-retention-policy.yaml diff --git a/docs/guides/mysql/backup/customization/examples/backup/passing-args.yaml b/docs/guides/mysql/backup/stash/customization/examples/backup/passing-args.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/backup/passing-args.yaml rename to docs/guides/mysql/backup/stash/customization/examples/backup/passing-args.yaml diff --git a/docs/guides/mysql/backup/customization/examples/backup/resource-limit.yaml b/docs/guides/mysql/backup/stash/customization/examples/backup/resource-limit.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/backup/resource-limit.yaml rename to docs/guides/mysql/backup/stash/customization/examples/backup/resource-limit.yaml diff --git a/docs/guides/mysql/backup/customization/examples/backup/specific-user.yaml b/docs/guides/mysql/backup/stash/customization/examples/backup/specific-user.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/backup/specific-user.yaml rename to docs/guides/mysql/backup/stash/customization/examples/backup/specific-user.yaml diff --git a/docs/guides/mysql/backup/customization/examples/repository.yaml b/docs/guides/mysql/backup/stash/customization/examples/repository.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/repository.yaml rename to docs/guides/mysql/backup/stash/customization/examples/repository.yaml diff --git a/docs/guides/mysql/backup/customization/examples/restore/passing-args.yaml b/docs/guides/mysql/backup/stash/customization/examples/restore/passing-args.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/restore/passing-args.yaml rename to docs/guides/mysql/backup/stash/customization/examples/restore/passing-args.yaml diff --git a/docs/guides/mysql/backup/customization/examples/restore/resource-limit.yaml b/docs/guides/mysql/backup/stash/customization/examples/restore/resource-limit.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/restore/resource-limit.yaml rename to docs/guides/mysql/backup/stash/customization/examples/restore/resource-limit.yaml diff --git a/docs/guides/mysql/backup/customization/examples/restore/specific-snapshot.yaml b/docs/guides/mysql/backup/stash/customization/examples/restore/specific-snapshot.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/restore/specific-snapshot.yaml rename to docs/guides/mysql/backup/stash/customization/examples/restore/specific-snapshot.yaml diff --git a/docs/guides/mysql/backup/customization/examples/restore/specific-user.yaml b/docs/guides/mysql/backup/stash/customization/examples/restore/specific-user.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/restore/specific-user.yaml rename to docs/guides/mysql/backup/stash/customization/examples/restore/specific-user.yaml diff --git a/docs/guides/mysql/backup/customization/examples/sample-mysql.yaml b/docs/guides/mysql/backup/stash/customization/examples/sample-mysql.yaml similarity index 100% rename from docs/guides/mysql/backup/customization/examples/sample-mysql.yaml rename to docs/guides/mysql/backup/stash/customization/examples/sample-mysql.yaml diff --git a/docs/guides/mysql/backup/customization/index.md b/docs/guides/mysql/backup/stash/customization/index.md similarity index 98% rename from docs/guides/mysql/backup/customization/index.md rename to docs/guides/mysql/backup/stash/customization/index.md index 227d7105d..6ca5302d0 100644 --- a/docs/guides/mysql/backup/customization/index.md +++ b/docs/guides/mysql/backup/stash/customization/index.md @@ -3,9 +3,9 @@ title: MySQL Backup Customization | Stash description: Customizing MySQL Backup and Restore process with Stash menu: docs_{{ .version }}: - identifier: guides-mysql-backup-customization + identifier: guides-mysql-backup-customization-stashv1 name: Customizing Backup & Restore Process - parent: guides-mysql-backup + parent: guides-mysql-backup-stashv1 weight: 40 menu_name: docs_{{ .version }} section_menu_id: guides diff --git a/docs/guides/mysql/backup/overview/images/backup_overview.svg b/docs/guides/mysql/backup/stash/overview/images/backup_overview.svg similarity index 100% rename from docs/guides/mysql/backup/overview/images/backup_overview.svg rename to docs/guides/mysql/backup/stash/overview/images/backup_overview.svg diff --git a/docs/guides/mysql/backup/overview/images/restore_overview.svg b/docs/guides/mysql/backup/stash/overview/images/restore_overview.svg similarity index 100% rename from docs/guides/mysql/backup/overview/images/restore_overview.svg rename to docs/guides/mysql/backup/stash/overview/images/restore_overview.svg diff --git a/docs/guides/mysql/backup/overview/index.md b/docs/guides/mysql/backup/stash/overview/index.md similarity index 94% rename from docs/guides/mysql/backup/overview/index.md rename to docs/guides/mysql/backup/stash/overview/index.md index 0a7834d05..f1180c2d3 100644 --- a/docs/guides/mysql/backup/overview/index.md +++ b/docs/guides/mysql/backup/stash/overview/index.md @@ -2,9 +2,9 @@ title: Backup & Restore MySQL Overview menu: docs_{{ .version }}: - identifier: guides-mysql-backup-overview + identifier: guides-mysql-backup-overview-stashv1 name: Overview - parent: guides-mysql-backup + parent: guides-mysql-backup-stashv1 weight: 10 menu_name: docs_{{ .version }} section_menu_id: guides @@ -28,7 +28,7 @@ KubeDB uses [Stash](https://stash.run) to backup and restore databases. Stash by The following diagram shows how Stash takes backup of a MySQL database. Open the image in a new tab to see the enlarged version.
-  MySQL Backup Overview +  MySQL Backup Overview
Fig: MySQL Backup Overview
@@ -63,7 +63,7 @@ The backup process consists of the following steps: The following diagram shows how Stash restores backed up data into a MySQL database. Open the image in a new tab to see the enlarged version.
-  Database Restore Overview +  Database Restore Overview
Fig: MySQL Restore Process Overview
@@ -85,4 +85,4 @@ The restore process consists of the following steps: ## Next Steps -- Backup a standalone MySQL server using Stash by following the guides from [here](/docs/guides/mysql/backup/standalone/index.md). +- Backup a standalone MySQL server using Stash by following the guides from [here](/docs/guides/mysql/backup/stash/standalonedalone/index.md). diff --git a/docs/guides/mysql/backup/standalone/examples/backupconfiguration.yaml b/docs/guides/mysql/backup/stash/standalone/examples/backupconfiguration.yaml similarity index 100% rename from docs/guides/mysql/backup/standalone/examples/backupconfiguration.yaml rename to docs/guides/mysql/backup/stash/standalone/examples/backupconfiguration.yaml diff --git a/docs/guides/mysql/backup/standalone/examples/repository.yaml b/docs/guides/mysql/backup/stash/standalone/examples/repository.yaml similarity index 100% rename from docs/guides/mysql/backup/standalone/examples/repository.yaml rename to docs/guides/mysql/backup/stash/standalone/examples/repository.yaml diff --git a/docs/guides/mysql/backup/standalone/examples/restored-mysql.yaml b/docs/guides/mysql/backup/stash/standalone/examples/restored-mysql.yaml similarity index 100% rename from docs/guides/mysql/backup/standalone/examples/restored-mysql.yaml rename to docs/guides/mysql/backup/stash/standalone/examples/restored-mysql.yaml diff --git a/docs/guides/mysql/backup/standalone/examples/restoresession.yaml b/docs/guides/mysql/backup/stash/standalone/examples/restoresession.yaml similarity index 100% rename from docs/guides/mysql/backup/standalone/examples/restoresession.yaml rename to docs/guides/mysql/backup/stash/standalone/examples/restoresession.yaml diff --git a/docs/guides/mysql/backup/standalone/examples/sample-mysql.yaml b/docs/guides/mysql/backup/stash/standalone/examples/sample-mysql.yaml similarity index 100% rename from docs/guides/mysql/backup/standalone/examples/sample-mysql.yaml rename to docs/guides/mysql/backup/stash/standalone/examples/sample-mysql.yaml diff --git a/docs/guides/mysql/backup/standalone/images/sample-mysql-backup.png b/docs/guides/mysql/backup/stash/standalone/images/sample-mysql-backup.png similarity index 100% rename from docs/guides/mysql/backup/standalone/images/sample-mysql-backup.png rename to docs/guides/mysql/backup/stash/standalone/images/sample-mysql-backup.png diff --git a/docs/guides/mysql/backup/standalone/index.md b/docs/guides/mysql/backup/stash/standalone/index.md similarity index 97% rename from docs/guides/mysql/backup/standalone/index.md rename to docs/guides/mysql/backup/stash/standalone/index.md index 1a1fc084c..36815cf25 100644 --- a/docs/guides/mysql/backup/standalone/index.md +++ b/docs/guides/mysql/backup/stash/standalone/index.md @@ -3,9 +3,9 @@ title: Backup & Restore MySQL | Stash description: Backup standalone MySQL database using Stash menu: docs_{{ .version }}: - identifier: guides-mysql-backup-standalone + identifier: guides-mysql-backup-standalone-stashv1 name: Standalone MySQL - parent: guides-mysql-backup + parent: guides-mysql-backup-stashv1 weight: 20 menu_name: docs_{{ .version }} section_menu_id: guides @@ -21,7 +21,7 @@ Stash 0.9.0+ supports backup and restoration of MySQL databases. This guide will - Install KubeDB in your cluster following the steps [here](/docs/setup/README.md). - Install Stash in your cluster following the steps [here](https://stash.run/docs/latest/setup/install/stash/). - Install Stash `kubectl` plugin following the steps [here](https://stash.run/docs/latest/setup/install/kubectl-plugin/). -- If you are not familiar with how Stash backup and restore MySQL databases, please check the following guide [here](/docs/guides/mysql/backup/overview/index.md). +- If you are not familiar with how Stash backup and restore MySQL databases, please check the following guide [here](/docs/guides/mysql/backup/stash/overview/index.md). You have to be familiar with following custom resources: @@ -72,7 +72,7 @@ spec: Create the above `MySQL` CRD, ```bash -$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/standalone/examples/sample-mysql.yaml +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/standalone/examples/sample-mysql.yaml mysql.kubedb.com/sample-mysql created ``` @@ -295,7 +295,7 @@ spec: Let's create the `Repository` we have shown above, ```bash -$ kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/standalone/examples/repository.yaml +$ kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/standalone/examples/repository.yaml repository.stash.appscode.com/gcs-repo created ``` @@ -338,7 +338,7 @@ Here, Let's create the `BackupConfiguration` CRD we have shown above, ```bash -$ kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/standalone/examples/backupconfiguration.yaml +$ kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/standalone/examples/backupconfiguration.yaml backupconfiguration.stash.appscode.com/sample-mysql-backup created ``` @@ -394,7 +394,7 @@ gcs-repo true 6.815 MiB 1 3m39s 30m Now, if we navigate to the GCS bucket, we will see the backed up data has been stored in `demo/mysql/sample-mysql` directory as specified by `.spec.backend.gcs.prefix` field of Repository CRD.
-  Backup data in GCS Bucket +  Backup data in GCS Bucket
Fig: Backup data in GCS Bucket
@@ -462,7 +462,7 @@ spec: Let's create the above database, ```bash -$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/standalone/examples/restored-mysql.yaml +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/standalone/examples/restored-mysql.yaml mysql.kubedb.com/restored-mysql created ``` @@ -515,7 +515,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/mysql/backup/standalone/examples/restoresession.yaml +$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mysql/backup/stash/standalone/examples/restoresession.yaml restoresession.stash.appscode.com/sample-mysql-restore created ``` diff --git a/docs/guides/mysql/pitr/archiver.md b/docs/guides/mysql/pitr/archiver.md index ec4d31888..00ad0fae6 100644 --- a/docs/guides/mysql/pitr/archiver.md +++ b/docs/guides/mysql/pitr/archiver.md @@ -446,7 +446,7 @@ $ kubectl delete ns demo ## Next Steps -- Learn about [backup and restore](/docs/guides/mysql/backup/overview/index.md) MySQL database using Stash. +- Learn about [backup and restore](/docs/guides/mysql/backup/stash/overview/index.md) MySQL database using Stash. - Learn about initializing [MySQL with Script](/docs/guides/mysql/initialization/script_source.md). - Learn about [custom MySQLVersions](/docs/guides/mysql/custom-versions/setup.md). - Want to setup MySQL cluster? Check how to [configure Highly Available MySQL Cluster](/docs/guides/mysql/clustering/ha_cluster.md)