Part 7: Cloud SQL Backups & Exports: Designing Practical Data Protection

AuthorEmmanuel Secretaria

Published Aug 14, 2025

Walk through export workflows, prerequisites, and operational caveats for reliable Cloud SQL backups to GCS.

Share

Scope inspiration:

gcp_sql_export.sh, gcp_sql_running_primaries.sh, gcp_sql_grant_instances_gcs_object_creator.sh.

This series follows the repo’s GCP inventory flow so every step builds a repeatable, audit-friendly picture of your environment. Part 7 takes the storage inventory further into backup safety and export automation.


What this script does (walkthrough)

gcp_sql_export.sh
is an end-to-end export helper that targets only viable Cloud SQL instances and writes backups into GCS.

  1. Require a target GCS bucket and validate it exists.
  2. Resolve export targets by listing running, non-replica instances (or using explicit instance arguments).
  3. Grant Storage Object Creator on the bucket to the instance service accounts so exports succeed.
  4. Enumerate databases per instance, skipping system schemas that cannot be exported.
  5. Export each database to a timestamped path under
    gs://<bucket>/backups/sql/
    .

Operational caveats and gotchas

  • Exports fail on replicas; the script intentionally targets non-replicas to avoid recovery conflicts.
  • Only running instances can export; stopped instances will error.
  • Large or busy databases can time out. The script recommends
    --async
    or
    --offload
    for heavy workloads if needed.
  • The script skips system schemas like
    information_schema
    ,
    sys
    , and
    performance_schema
    to avoid known export failures.

Example command usage

# Export all running primary instances to a bucket
gcp/gcp_sql_export.sh my-backup-bucket
# Export specific instances only
gcp/gcp_sql_export.sh my-backup-bucket prod-sql-1 prod-sql-2