This is a sample for restore of Cloud SQL instance.
- Restore database from backup
- Execute sql statements (by using cloud functions)
- Create a backup of the database
- Prepare an initial backup of cloud sql instance
❯ gcloud sql backups list --project <project_name> --instance sample-instance-v1-for-backup
ID WINDOW_START_TIME ERROR STATUS INSTANCE
1654919319590 2022-06-11T03:48:39.590+00:00 - SUCCESSFUL sample-instance-v1-for-backup
- Setup infra
Note Specify cloud sql instance id (
sample-instance-v1-for-backup
) and backup id (1654919319590
) ininfra/workflows/restore_db.yaml
cd infra
terraform apply -var project="<gcp_project_id>"
-
Run a job of cloud scheduler (
sample-scheduler-job
) -
Confirm the result
Note Check the instance name that is created with random suffix by using cloud logging.
❯ gcloud sql backups list --project <project_name> --instance sample-instance-v1-1654996390
ID WINDOW_START_TIME ERROR STATUS INSTANCE
1654996758862 2022-06-12T01:19:18.862+00:00 - SUCCESSFUL sample-instance-v1-1654996390