Skip to content

Commit

Permalink
Resolved review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Anisur Rahman <[email protected]>
  • Loading branch information
anisurrahman75 committed Sep 30, 2024
1 parent 7f9c118 commit c00c28f
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 275 deletions.
2 changes: 1 addition & 1 deletion docs/guides/mssqlserver/backup/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Backup & Restore MSSQLServer
title: Backup & Restore Microsoft SQL Server
menu:
docs_{{ .version }}:
identifier: guides-mssqlserver-backup
Expand Down
20 changes: 0 additions & 20 deletions docs/guides/mssqlserver/backup/application-level/examples/ca.crt

This file was deleted.

28 changes: 0 additions & 28 deletions docs/guides/mssqlserver/backup/application-level/examples/ca.key

This file was deleted.

50 changes: 25 additions & 25 deletions docs/guides/mssqlserver/backup/application-level/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Application Level Backup & Restore MSSQLServer | KubeStash
title: Application Level Backup & Restore Microsoft SQL Server | KubeStash
description: Application Level Backup and Restore using KubeStash
menu:
docs_{{ .version }}:
Expand All @@ -12,19 +12,19 @@ section_menu_id: guides
---


# Application Level Backup and Restore MSSQLServer database using KubeStash
# Application Level Backup and Restore Microsoft SQL Server database using KubeStash

KubeStash offers application-level backup and restore functionality for `MSSQLServer` databases. It captures both manifest and data backups of any `MSSQLServer` database in a single snapshot. During the restore process, KubeStash first applies the `MSSQLServer` manifest to the cluster and then restores the data into it.
KubeStash offers application-level backup and restore functionality for `Microsoft SQL Server` databases. It captures both manifest and data backups of any `Microsoft SQL Server` database in a single snapshot. During the restore process, KubeStash first applies the `Microsoft SQL Server` manifest to the cluster and then restores the data into it.

This guide will give you an overview how you can take application-level backup and restore your `MSSQLServer` databases using `Kubestash`.
This guide will give you an overview how you can take application-level backup and restore your `Microsoft SQL Server` 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 `MSSQLServer` databases, please check the following guide [here](/docs/guides/mssqlserver/backup/overview/index.md).
- If you are not familiar with how KubeStash backup and restore `Microsoft SQL Server` databases, please check the following guide [here](/docs/guides/mssqlserver/backup/overview/index.md).

You should be familiar with the following `KubeStash` concepts:

Expand All @@ -46,19 +46,19 @@ namespace/demo created
> **Note:** YAML files used in this tutorial are stored in [docs/guides/mssqlserver/backup/application-level/examples](https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mssqlserver/backup/application-level/examples) directory of [kubedb/docs](https://github.com/kubedb/docs) repository.

## Backup MSSQLServer
## Backup Microsoft SQL Server

KubeStash supports backups for `MSSQLServer` instances across different configurations, including Standalone and Availability Group setups. In this demonstration, we'll focus on a `MSSQLServer` database using Standalone configuration. The backup and restore process is similar for Availability Group configuration.
KubeStash supports backups for `Microsoft SQL Server` instances across different configurations, including Standalone and Availability Group setups. In this demonstration, we'll focus on a `Microsoft SQL Server` database using Standalone configuration. The backup and restore process is similar for Availability Group configuration.

This section will demonstrate how to backup a `MSSQLServer` database. Here, we are going to deploy a `MSSQLServer` 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 `MSSQLServer` database.
This section will demonstrate how to backup a `Microsoft SQL Server` database. Here, we are going to deploy a `Microsoft SQL Server` 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 `Microsoft SQL Server` database.

### Deploy Sample MSSQLServer Database
### Deploy Sample Microsoft SQL Server Database

By default, a KubeDB-managed MSSQLServer instance does not run with TLS enabled. However, the .spec.tls field is mandatory and will be used during backup and restore operations.
By default, a KubeDB-managed `Microsoft SQL Server` instance does not run with TLS enabled. However, the `.spec.tls` field is mandatory and will be used during backup and restore operations.

**Create Issuer/ClusterIssuer:**

Now, we are going to create an example `Issuer` that will be used throughout the duration of this tutorial. Alternatively, you can follow this [cert-manager](https://cert-manager.io/docs/configuration/ca/) tutorial to create your own `Issuer`.
Now, we are going to create an example `Issuer` CR that will be used throughout the duration of this tutorial. Alternatively, you can follow this [cert-manager](https://cert-manager.io/docs/configuration/ca/) tutorial to create your own `Issuer`.

By following the below steps, we are going to create our desired issuer,

Expand Down Expand Up @@ -131,7 +131,7 @@ $ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >
mssqlserver.kubedb.com/sample-mssqlserver created
```

KubeDB will deploy a `MSSQLServer` database according to the above specification. It will also create the necessary `Secrets` and `Services` to access the database.
KubeDB will deploy a `Microsoft SQL Server` 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,

Expand Down Expand Up @@ -251,7 +251,7 @@ kkvAFfl8sIxRO2i3⏎
Now, Lets exec into the `Pod` to enter into `mssqlserver` shell and create a database and a table,

```bash
$ kubectl exec -it -n demo sample-mssqlserver-0 -- /opt/mssql-tools/bin/sqlcmd -S sample-mssqlserver -U sa -P "kkvAFfl8sIxRO2i3"
$ kubectl exec -it -n demo sample-mssqlserver-0 -c mssql -- /opt/mssql-tools/bin/sqlcmd -S sample-mssqlserver -U sa -P "kkvAFfl8sIxRO2i3"
# list available databases
1> SELECT name from sys.databases;
2> GO
Expand Down Expand Up @@ -391,7 +391,7 @@ retentionpolicy.storage.kubestash.com/demo-retention created

### Backup

We have to create a `BackupConfiguration` targeting respective `sample-mssqlserver` MSSQLServer database. Then, KubeStash will create a `CronJob` for each session to take periodic backup of that database.
We have to create a `BackupConfiguration` targeting respective `sample-mssqlserver` Microsoft SQL Server database. Then, KubeStash will create a `CronJob` for each session to take periodic backup of that database.

Below is the YAML for `BackupConfiguration` CR to backup the `sample-mssqlserver` database that we have deployed earlier,

Expand Down Expand Up @@ -437,10 +437,10 @@ spec:
```

- `.spec.sessions[*].schedule` specifies that we want to backup the database at `5 minutes` interval.
- `.spec.target` refers to the targeted `sample-mssqlserver` MSSQLServer database that we created earlier.
- `.spec.target` refers to the targeted `sample-mssqlserver` Microsoft SQL Server database that we created earlier.
- `.spec.sessions[*].addon.tasks[*].name[*]` specifies that both the `manifest-backup` and `logical-backup` tasks will be executed.

> KubeStash utilizes [Wal-G](https://wal-g.readthedocs.io/SQLServer/) to perform logical backups of `MSSQLServer` databases. Since Wal-G operates with `root` user privileges, it’s necessary to configure our backup job to run as a `root` user by specifying `runAsUser: 0` in the `spec.sessions[*].addon.jobTemplate.spec.securityContext` section.
> KubeStash utilizes [Wal-G](https://wal-g.readthedocs.io/SQLServer/) to perform logical backups of `Microsoft SQL Server` databases. Since Wal-G operates with `root` user privileges, it’s necessary to configure our backup job to run as a `root` user by specifying `runAsUser: 0` in the `spec.sessions[*].addon.jobTemplate.spec.securityContext` section.

```bash
$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mssqlserver/application-level/examples/backupconfiguration.yaml
Expand Down Expand Up @@ -493,7 +493,7 @@ We can see from the above output that the backup session has succeeded. Now, we

**Verify Backup:**

Once a backup is complete, KubeStash will update the respective `Repository` CR to reflect the backup. Check that the repository `sample-mssqlserver-backup` has been updated by the following command,
Once a backup is complete, KubeStash will update the respective `Repository` CR to reflect the backup. Check that the repository `gcs-mssqlserver-repo` has been updated by the following command,

```bash
$ kubectl get repository -n demo gcs-mssqlserver-repo
Expand Down Expand Up @@ -608,7 +608,7 @@ namespace/dev created

**Create Issuer/ClusterIssuer:**

Now, we are going to create another example `Issuer` that will be used throughout the restore of this tutorial. Alternatively, you can follow this [cert-manager](https://cert-manager.io/docs/configuration/ca/) tutorial to create your own `Issuer`.
Now, we are going to create another example `Issuer` CR that will be used throughout the restore of this tutorial. Alternatively, you can follow this [cert-manager](https://cert-manager.io/docs/configuration/ca/) tutorial to create your own `Issuer`.

By following the below steps, we are going to create our desired issuer,

Expand All @@ -625,7 +625,7 @@ $ kubectl create secret tls mssqlserver-ca --cert=ca.crt --key=ca.key --namespa
secret/mssqlserver-ca created
```

Now, we are going to create an `Issuer` using the `mssqlserver-ca` secret that contains the ca-certificate we have just created. Below is the YAML of the `Issuer` cr that we are going to create,
Now, we are going to create an `Issuer` CR using the `mssqlserver-ca` secret that contains the ca-certificate we have just created. Below is the YAML of the `Issuer` cr that we are going to create,

```yaml
apiVersion: cert-manager.io/v1
Expand Down Expand Up @@ -692,11 +692,11 @@ Here,
- `.spec.dataSource.snapshot` specifies to restore from latest `Snapshot`.
- `.spec.addon.tasks[*]` specifies that both the `manifest-restore` and `logical-backup-restore` tasks.

> KubeStash utilizes [Wal-G](https://wal-g.readthedocs.io/SQLServer/) to perform logical restores of `MSSQLServer` databases. Since Wal-G operates with `root` user privileges, it’s necessary to configure our restore job to run as a `root` user by specifying `runAsUser: 0` in the `.spe.addon.jobTemplate.spec.securityContext` section.
> KubeStash utilizes [Wal-G](https://wal-g.readthedocs.io/SQLServer/) to perform logical restores of `Restore Microsoft SQL Server` databases. Since Wal-G operates with `root` user privileges, it’s necessary to configure our restore job to run as a `root` user by specifying `runAsUser: 0` in the `.spe.addon.jobTemplate.spec.securityContext` section.

> Note: Set the RestoreSession namespace and `.spe.manifestOptions.msSQLServer.restoreNamespace` to the same value, as kubeStash internally creates a proxy server. Currently, only the same namespace is supported.

Let's create the RestoreSession CRD object we have shown above,
Let's create the RestoreSession CR object we have shown above,

```bash
$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/guides/mssqlserver/backup/application-level/examples/restoresession.yaml
Expand Down Expand Up @@ -747,8 +747,7 @@ Ag9qi8zQiFew0xHo⏎
Now, Lets exec into the `Pod` to enter into `mssqlserver` shell and verify restored data,

```bash
$ kubectl exec -it -n dev sample-mssqlserver-0 -- /opt/mssql-tools/bin/sqlcmd -S sample-mssqlserver -U sa -P "Ag9qi8zQiFew0xHo"
Defaulted container "mssql" out of: mssql, mssql-init (init)
$ kubectl exec -it -n dev sample-mssqlserver-0 -c mssql -- /opt/mssql-tools/bin/sqlcmd -S sample-mssqlserver -U sa -P "Ag9qi8zQiFew0xHo"
1> SELECT name from sys.databases;
2> GO
name
Expand Down Expand Up @@ -783,15 +782,16 @@ id type quant color
(3 rows affected)
> exit
```
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.

Based on the output above, we can confirm that the `playground` database and the `equipment` table, which were previously created in the original database, have now been successfully restored.

## Cleanup

To cleanup the Kubernetes resources created by this tutorial, run:

```bash
kubectl delete backupconfigurations.core.kubestash.com -n demo sample-mssqlserver-backup
kubectl delete restoresessions.core.kubestash.com -n restore-sample-mssqlserver
kubectl delete restoresessions.core.kubestash.com -n dev restore-sample-mssqlserver
kubectl delete retentionpolicies.storage.kubestash.com -n demo demo-retention
kubectl delete backupstorage -n demo gcs-storage
kubectl delete secret -n demo gcs-secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ spec:
allowedNamespaces:
from: All
default: true
# deletionPolicy: Delete
deletionPolicy: WipeOut
deletionPolicy: Delete
20 changes: 0 additions & 20 deletions docs/guides/mssqlserver/backup/auto-backup/examples/ca.crt

This file was deleted.

28 changes: 0 additions & 28 deletions docs/guides/mssqlserver/backup/auto-backup/examples/ca.key

This file was deleted.

Loading

0 comments on commit c00c28f

Please sign in to comment.