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.
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.
- Require a target GCS bucket and validate it exists.
- Resolve export targets by listing running, non-replica instances (or using explicit instance arguments).
- Grant Storage Object Creator on the bucket to the instance service accounts so exports succeed.
- Enumerate databases per instance, skipping system schemas that cannot be exported.
- 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
or--async
for heavy workloads if needed.--offload - The script skips system schemas like
,information_schema
, andsys
to avoid known export failures.performance_schema
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