Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudSQL - Old backups are never deleted #519

Closed
Silvest89 opened this issue Oct 2, 2023 · 5 comments · Fixed by #566
Closed

CloudSQL - Old backups are never deleted #519

Silvest89 opened this issue Oct 2, 2023 · 5 comments · Fixed by #566
Labels
bug Something isn't working

Comments

@Silvest89
Copy link

Silvest89 commented Oct 2, 2023

TL;DR

We do multiple CloudSQL backups a day so that's how we came across this issue (using just a 7 day retention time). Old backups won't get deleted.

By default googleapis.sqladmin.v1.backupRuns.list returns only 20 items. So if for example doing daily backups and you have a retention time higher than 21, you will never get the backups old enough to be deleted :P

It would be nice to

      call: googleapis.sqladmin.v1.backupRuns.list
      args:
        maxResults: 100  (either configurable or a high enough value)
        project: ${project}
        instance: ${instanceName}

Expected behavior

Old backups should be deleted

Observed behavior

Backups higher than retentionTime are not visible in the list response

Terraform Configuration

.

Terraform Version

.

Additional information

No response

@Silvest89 Silvest89 added the bug Something isn't working label Oct 2, 2023
Copy link

github-actions bot commented Dec 1, 2023

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label Dec 1, 2023
@imrannayer imrannayer added upstream Work required on Terraform core or provider and removed Stale labels Dec 6, 2023
@imrannayer
Copy link
Collaborator

@Silvest89 can you plz create an issue for the API team. This is not something we can fix it in module.

@imrannayer imrannayer removed the bug Something isn't working label Dec 6, 2023
@tjespers
Copy link
Contributor

@imrannayer
We can fix this within the module, the problem lies in the API call used for listing the backups: googleapis.sqladmin.v1.backupRuns.list operation defined here:

call: googleapis.sqladmin.v1.backupRuns.list

This operation supports an argument that specifies the maximum amount of backups returned with it's default page size being 20 if left unset.

We worked around this now by using this exact backup.yaml template but simply passing in a maxResults large enough for us to accomodate our scenario (bi-hourly backups with a retention time of 7 days) setting maxResults: 100

2 possible ways of fixing this within the module are:

  • hardcoding maxResults to a more "sane" default, and documenting it in the README for other to know the limitation
  • leave it up to the enduser and max this an optional module variable for the enduser to have more control based on their schedule.

@imrannayer
Copy link
Collaborator

@tjespers option 2 sounds like a better option.

@imrannayer imrannayer added bug Something isn't working and removed upstream Work required on Terraform core or provider labels Jan 17, 2024
tjespers added a commit to tjespers/terraform-google-sql-db that referenced this issue Jan 19, 2024
This commit introduces a new module variable: backup_runs_list_max_results
this variable is used to control the maximum amount of results that are
returned by the googleapis.sqladmin.v1.backupRuns.list API call.
By defaul this call only returns 20 results leading to a situation
where no old backups will be deleted whenever the desired amount of
retained backups exceed this number.

Fixes: terraform-google-modules#519
tjespers added a commit to tjespers/terraform-google-sql-db that referenced this issue Jan 19, 2024
This commit introduces a new module variable: backup_runs_list_max_results
this variable is used to control the maximum amount of results that are
returned by the googleapis.sqladmin.v1.backupRuns.list API call.
By defaul this call only returns 20 results leading to a situation
where no old backups will be deleted whenever the desired amount of
retained backups exceed this number.

Fixes: terraform-google-modules#519
@tjespers
Copy link
Contributor

@imrannayer Sure thing! I've opened #566 as a bugfix for this.

tjespers added a commit to tjespers/terraform-google-sql-db that referenced this issue Jan 19, 2024
This commit introduces a new module variable: backup_runs_list_max_results
this variable is used to control the maximum amount of results that are
returned by the googleapis.sqladmin.v1.backupRuns.list API call.
By defaul this call only returns 20 results leading to a situation
where no old backups will be deleted whenever the desired amount of
retained backups exceed this number.

Fixes: terraform-google-modules#519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants