Skip to content

Commit c5a8ef2

Browse files
Merge pull request #16 from amanmallsops/feature/backup-restore
Feature enhancement of backup and restore in self managed mysql
2 parents 437b290 + 68fed20 commit c5a8ef2

File tree

6 files changed

+11
-4
lines changed

6 files changed

+11
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module "mysql" {
9292
iam_role_arn_backup = module.aws.iam_role_arn_backup
9393
mysqldb_backup_enabled = true
9494
mysqldb_backup_config = {
95+
mysql_database_name = ""
9596
bucket_uri = "s3://bucket_name"
9697
s3_bucket_region = ""
9798
cron_for_full_backup = "*/5 * * * *"
@@ -165,7 +166,7 @@ No modules.
165166
| <a name="input_iam_role_arn_backup"></a> [iam\_role\_arn\_backup](#input\_iam\_role\_arn\_backup) | IAM role ARN for backup (AWS) | `string` | `""` | no |
166167
| <a name="input_iam_role_arn_restore"></a> [iam\_role\_arn\_restore](#input\_iam\_role\_arn\_restore) | IAM role ARN for restore (AWS) | `string` | `""` | no |
167168
| <a name="input_metric_exporter_pasword"></a> [metric\_exporter\_pasword](#input\_metric\_exporter\_pasword) | Metric exporter password for MongoDB | `string` | `""` | no |
168-
| <a name="input_mysqldb_backup_config"></a> [mysqldb\_backup\_config](#input\_mysqldb\_backup\_config) | configuration options for MySQL database backups. It includes properties such as the S3 bucket URI, the S3 bucket region, and the cron expression for full backups. | `any` | <pre>{<br> "bucket_uri": "",<br> "cron_for_full_backup": "",<br> "s3_bucket_region": ""<br>}</pre> | no |
169+
| <a name="input_mysqldb_backup_config"></a> [mysqldb\_backup\_config](#input\_mysqldb\_backup\_config) | configuration options for MySQL database backups. It includes properties such as the S3 bucket URI, the S3 bucket region, cron expression for full backups and the database name to take backup of particular database or if send empty it backup whole database | `any` | <pre>{<br> "bucket_uri": "",<br> "cron_for_full_backup": "",<br> "mysql_database_name": "",<br> "s3_bucket_region": ""<br>}</pre> | no |
169170
| <a name="input_mysqldb_backup_enabled"></a> [mysqldb\_backup\_enabled](#input\_mysqldb\_backup\_enabled) | Specifies whether to enable backups for MySQL database. | `bool` | `false` | no |
170171
| <a name="input_mysqldb_config"></a> [mysqldb\_config](#input\_mysqldb\_config) | Specify the configuration settings for MySQL, including the name, environment, storage options, replication settings, and custom YAML values. | `any` | <pre>{<br> "architecture": "",<br> "custom_database": "",<br> "custom_user_username": "",<br> "environment": "",<br> "name": "",<br> "primary_db_volume_size": "",<br> "secondary_db_replica_count": 1,<br> "secondary_db_volume_size": "",<br> "storage_class_name": "",<br> "store_password_to_secret_manager": true,<br> "values_yaml": ""<br>}</pre> | no |
171172
| <a name="input_mysqldb_custom_credentials_config"></a> [mysqldb\_custom\_credentials\_config](#input\_mysqldb\_custom\_credentials\_config) | Specify the configuration settings for MySQL to pass custom credentials during creation | `any` | <pre>{<br> "custom_user_password": "",<br> "custom_username": "",<br> "exporter_password": "",<br> "exporter_user": "",<br> "replication_password": "",<br> "replication_user": "",<br> "root_password": "",<br> "root_user": ""<br>}</pre> | no |

examples/complete/aws/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ module "mysql" {
6464
iam_role_arn_backup = module.aws.iam_role_arn_backup
6565
mysqldb_backup_enabled = true
6666
mysqldb_backup_config = {
67-
bucket_uri = "s3://bucket_name"
67+
mysql_database_name = ""
68+
bucket_uri = "s3://bucket_name/"
6869
s3_bucket_region = ""
6970
cron_for_full_backup = "*/5 * * * *"
7071
}

helm/values/backup/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ backup:
33
bucket_uri: ${bucket_uri}
44
aws_default_region: ${s3_bucket_region}
55
cron_for_full_backup: "${cron_for_full_backup}"
6+
database_name: "${mysql_database_name}"
67

78

89
annotations:

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ resource "helm_release" "mysqldb_backup" {
4545
values = [
4646
templatefile("${path.module}/helm/values/backup/values.yaml", {
4747
bucket_uri = var.mysqldb_backup_config.bucket_uri,
48+
mysql_database_name = var.bucket_provider_type == "s3" ? var.mysqldb_backup_config.mysql_database_name : "",
4849
s3_bucket_region = var.bucket_provider_type == "s3" ? var.mysqldb_backup_config.s3_bucket_region : "",
4950
cron_for_full_backup = var.mysqldb_backup_config.cron_for_full_backup,
5051
custom_user_username = "root",

modules/backup/templates/cronjob.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ spec:
2020
serviceAccountName: sa-mysql-backup
2121
containers:
2222
- name: backup-mysqldb
23-
image: squareops/mysqldb-backup:v4
23+
image: squareops/mysqldb-backup:v5
2424
imagePullPolicy: Always
2525
env:
2626
- name: MYSQL_HOST
2727
value: mysqldb-secondary-headless.{{ .Release.Namespace }}.svc.cluster.local
2828
- name: MYSQL_USER
2929
value: {{ .Values.auth.username }}
30+
- name: DATABASES
31+
value: {{ .Values.backup.database_name }}
3032
- name: MYSQL_PASSWORD
3133
valueFrom:
3234
secretKeyRef:

variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ variable "mysqldb_backup_config" {
6666
bucket_uri = ""
6767
s3_bucket_region = ""
6868
cron_for_full_backup = ""
69+
mysql_database_name = ""
6970
}
70-
description = "configuration options for MySQL database backups. It includes properties such as the S3 bucket URI, the S3 bucket region, and the cron expression for full backups."
71+
description = "configuration options for MySQL database backups. It includes properties such as the S3 bucket URI, the S3 bucket region, cron expression for full backups and the database name to take backup of particular database or if send empty it backup whole database "
7172
}
7273

7374
variable "mysqldb_exporter_enabled" {

0 commit comments

Comments
 (0)