Automated Cloud SQL database backup exporter for Google Cloud Platform.
2.3K
Automated Cloud SQL database backup exporter for Google Cloud Platform. This application automatically discovers and exports Cloud SQL instances to Google Cloud Storage buckets based on instance labels and schedules.
Add this module to your existing Terraform configuration:
module "sql_exporter" {
source = "github.com/yourusername/gcp-sql-exporter//infra"
project_id = "your-gcp-project-id"
region = "us-central1"
backup_bucket_name = "your-backup-bucket-name"
docker_image = "yourdockerhub/gcp-sql-exporter:latest"
}
Or use a local path if you've cloned the repository:
module "sql_exporter" {
source = "./path/to/gcp-sql-exporter/infra"
project_id = "your-gcp-project-id"
region = "us-central1"
backup_bucket_name = "your-backup-bucket-name"
docker_image = "yourdockerhub/gcp-sql-exporter:latest"
}
Add labels to the instances you want to back up:
# Enable daily backups for an instance
gcloud sql instances patch my-production-db \
--update-labels=autosql-backup=true,autosql-schedule=daily
# Enable hourly backups for a critical database
gcloud sql instances patch my-critical-db \
--update-labels=autosql-backup=true,autosql-schedule=hourly
Required Labels:
| Label | Values | Description |
|---|---|---|
autosql-backup | true | Required - Enables automatic backups for this instance. Without this label set to true, the instance will be ignored. |
autosql-schedule | daily or hourly | Optional (default: daily) - How frequently to back up:• daily: Backs up once per day (allows 23-hour window)• hourly: Backs up every hour (allows 55-minute window) |
autosql-bucket | bucket name | Optional - Override the default backup bucket for this instance. Use just the bucket name without gs:// prefix. |
autosql-type | sql, bak, or csv | Optional (default: sql) - Export format:• sql: SQL dump with compression (.sql.gz)• bak: Binary backup (.bak) - SQL Server only• csv: CSV export (.csv) |
Once deployed, the system automatically:
autosql-backup=truehourly: Skips if a backup completed in the last 55 minutesdaily: Skips if a backup completed in the last 23 hoursgs://bucket/instance-name/YYYY-MM-DD-HHMMSS-instance-name.sql.gzExample Workflow:
Cloud Scheduler (every hour)
↓
Cloud Run Service
↓
Checks all instances with autosql-backup=true
↓
Filters by schedule (hourly vs daily)
↓
Checks for recent/running backups
↓
Triggers export to GCS bucket
Content type
Image
Digest
sha256:800e8b7fc…
Size
253.9 MB
Last updated
11 months ago
docker pull djas19/gcp-sql-exporter