Skip to content

Commit 6c4b0e3

Browse files
tjespersg-awmalik
andauthored
fix(backup): backups are not deleted when retained nr of backups >= 20 (#566)
Co-authored-by: Awais Malik <[email protected]>
1 parent c7ab6ec commit 6c4b0e3

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

modules/backup/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fetch workflows.googleapis.com/Workflow
5454
| Name | Description | Type | Default | Required |
5555
|------|-------------|------|---------|:--------:|
5656
| backup\_retention\_time | The number of days backups should be kept | `number` | `30` | no |
57+
| backup\_runs\_list\_max\_results | The max amount of backups to list when fetching internal backup runs for the instance. This number must be larger then the amount of backups you wish to keep. E.g. for a daily backup schedule and a backup\_retention\_time of 30 days, you'd need to set this to at least 31 for old backups to get deleted. | `number` | `31` | no |
5758
| backup\_schedule | The cron schedule to execute the internal backup | `string` | `"45 2 * * *"` | no |
5859
| compress\_export | Whether or not to compress the export when storing in the bucket; Only valid for MySQL and PostgreSQL | `bool` | `true` | no |
5960
| connector\_params\_timeout | The end-to-end duration the connector call is allowed to run for before throwing a timeout exception. The default value is 1800 and this should be the maximum for connector methods that are not long-running operations. Otherwise, for long-running operations, the maximum timeout for a connector call is 31536000 seconds (one year). | `number` | `1800` | no |

modules/backup/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ resource "google_workflows_workflow" "sql_backup" {
6565
project = var.project_id
6666
service_account = local.service_account
6767
source_contents = templatefile("${path.module}/templates/backup.yaml.tftpl", {
68-
project = var.project_id
69-
instanceName = var.sql_instance
70-
backupRetentionTime = var.backup_retention_time
68+
project = var.project_id
69+
instanceName = var.sql_instance
70+
backupRetentionTime = var.backup_retention_time
71+
backupRunsListMaxResults = var.backup_runs_list_max_results
7172
})
7273
}
7374

modules/backup/templates/backup.yaml.tftpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ main:
3636
args:
3737
project: ${project}
3838
instance: ${instanceName}
39+
maxResults: ${backupRunsListMaxResults}
3940
result: backupList
4041
- delete old backups:
4142
for:

modules/backup/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ variable "backup_retention_time" {
4242
default = 30
4343
}
4444

45+
variable "backup_runs_list_max_results" {
46+
description = "The max amount of backups to list when fetching internal backup runs for the instance. This number must be larger then the amount of backups you wish to keep. E.g. for a daily backup schedule and a backup_retention_time of 30 days, you'd need to set this to at least 31 for old backups to get deleted."
47+
type = number
48+
default = 31
49+
}
50+
4551
variable "scheduler_timezone" {
4652
description = "The Timezone in which the Scheduler Jobs are triggered"
4753
type = string

0 commit comments

Comments
 (0)