GCP
Restore from CloudSQL MSSQL backup data
misankim
2023. 5. 12. 23:58
Restore from CloudSQL MSSQL backup data
https://cloud.google.com/sql/docs/sqlserver/import-export/import-export-bak#import
# Grant GCS permissions to the CloudSQL service account
Check the service account for your CloudSQL instance
gcloud sql instances describe premisan-test-mssql --project my-project | grep serviceAccountEmailAddress
Add access to GCS bucket
gcloud projects add-iam-policy-binding my-project \
--member "serviceAccount:p123490712340-12345@gcp-sa-cloud-sql.iam.gserviceaccount.com" \
--role "roles/storage.admin"
# restore db from backup file
-> The database to be restored must be run without creating it
gcloud beta sql import bak premisan-test-mssql gs://premisan-test/TestDB_backup_2022_04_24_040001_3056774.bak \
--database=TestDB --project my-project
Command timeout occurs after a certain period of time
Importing data into Cloud SQL instance...failed.
ERROR: (gcloud.beta.sql.import.bak) Operation https://sqladmin.googleapis.com/sql/v1beta4/projects/my-project/operations/1234c7dc-1234-1234-1234-f58300001234 is taking longer than expected. You can continue waiting for the operation by running `gcloud beta sql operations wait --project my-project 1234c7dc-1234-1234-1234-f58300001234`
-> Keep waiting for the task to complete
gcloud beta sql operations wait --project my-project 1234c7dc-1234-1234-1234-f58300001234
Output
Waiting for [https://sqladmin.googleapis.com/sql/v1beta4/projects/my-project/operations/1234c7dc-1234-1234-1234-f58300001234]...done.
NAME TYPE START END ERROR STATUS
1234c7dc-1234-1234-1234-f58300001234 IMPORT 2022-04-28T12:29:55.633+00:00 2022-04-28T12:42:29.341+00:00 - DONE
Actual 80GB db data was restored with 10GB backup data
When disk space was insufficient during restoration, disk capacity was automatically increased and restored