How to Backup Cloud SQL on Google Cloud Platform
To backup Cloud SQL on GCP, enable
automated backups in your instance settings or create on-demand backups using the gcloud CLI or Cloud Console. Automated backups run daily and keep your data safe, while on-demand backups let you save your database state anytime.Syntax
There are two main ways to backup Cloud SQL:
- Automated backups: Enabled in instance settings, run daily.
- On-demand backups: Created manually using commands or console.
Example gcloud command to create an on-demand backup:
gcloud sql backups create --instance=INSTANCE_NAME
Replace INSTANCE_NAME with your Cloud SQL instance ID.
bash
gcloud sql backups create --instance=INSTANCE_NAME
Output
Created backup [backup-id] for instance [INSTANCE_NAME].
Example
This example shows how to create an on-demand backup for a Cloud SQL instance named my-instance using the gcloud CLI.
bash
gcloud sql backups create --instance=my-instance
Output
Created backup [1234567890] for instance [my-instance].
Common Pitfalls
- Not enabling automated backups can risk data loss if manual backups are forgotten.
- Trying to create a backup while a previous backup is running causes errors.
- Forgetting to specify the correct instance name in commands leads to failures.
- Relying only on on-demand backups without scheduling can miss critical backup windows.
bash
## Wrong: Missing instance name gcloud sql backups create ## Right: Specify instance name gcloud sql backups create --instance=my-instance
Quick Reference
| Action | Command / Setting |
|---|---|
| Enable automated backups | Cloud Console > SQL > Instance > Backups > Enable automated backups |
| Create on-demand backup | gcloud sql backups create --instance=INSTANCE_NAME |
| List backups | gcloud sql backups list --instance=INSTANCE_NAME |
| Restore backup | gcloud sql backups restore BACKUP_ID --instance=INSTANCE_NAME |
Key Takeaways
Enable automated backups in Cloud SQL instance settings to protect data daily.
Use gcloud CLI to create on-demand backups anytime for extra safety.
Always specify the correct instance name when running backup commands.
Avoid running multiple backups simultaneously to prevent errors.
Check backup status regularly to ensure backups complete successfully.