Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Backup the Cloud SQL database to GCS every 6 hours #875

Merged
merged 2 commits into from
Oct 21, 2020

Conversation

sethvargo
Copy link
Member

Fixes #864

Nuances

  • Cloud SQL doesn't seem to support per-instance IAM, so we have to grant at the project level (yuck, but it's only viewer)

  • I'm relying on bucket versioning instead of actually naming the exports with a datetime. This is mostly a design decision to avoid needing a middle service. Ideally Cloud Scheduler would support a template syntax, but it does not.

  • The backups aren't compressed (for the same reason as above), but our last backup was 2MB. I'm not really worried about large databases for this project.

  • Backup time is configurable via the cron notation.

Release Note

Automatically backup the Cloud SQL database to GCS every 6 hours

/assign @jeremyfaller @icco

@google-cla google-cla bot added the cla: yes Auto: added by CLA bot when all committers have signed a CLA. label Oct 21, 2020
Copy link
Contributor

@mikehelmick mikehelmick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion - we add GCS retention timeline on the bucket as well

Copy link
Contributor

@icco icco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: icco, mikehelmick, sethvargo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [icco,mikehelmick,sethvargo]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

@jeremyfaller jeremyfaller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I'll let @icco finish here.

name = "${var.project}-backups"
location = var.storage_location

force_destroy = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels safer to me to have this be false(the default).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tells terraform to delete the objects in the bucket before deleting the bucket. GCS doesn't let you delete a bucket with objects inside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I understood that. I felt it was kinda safer to require the bucket be empty.

@google-oss-robot google-oss-robot merged commit 648e6c1 into main Oct 21, 2020
@google-oss-robot google-oss-robot deleted the sethvargo/backup_cloudsql branch October 21, 2020 16:17
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Auto: added by CLA bot when all committers have signed a CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set up cron job to backup database
5 participants