本頁說明如何取消將資料匯入 Cloud SQL 執行個體,以及從 Cloud SQL 執行個體匯出資料。這些資料會儲存在 SQL 傾印檔案或 CSV 檔案中。
事前準備
取消匯入或匯出作業
您可以使用 gcloud
或 REST API 指令取消匯入或匯出作業。
gcloud sql operations cancel
指令取消作業。
gcloud sql operations canceloperation-ID
使用任何要求資料之前,請先替換以下項目:
- project-ID:專案 ID。
- operation-ID:匯入或匯出作業的 ID。詳情請參閱「事前準備」一文。
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/v1/projects/project-ID /operations/operation-ID /cancel
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://sqladmin.googleapis.com/v1/projects/project-ID /operations/operation-ID /cancel"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-ID /operations/operation-ID /cancel" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{}
使用任何要求資料之前,請先替換以下項目:
- project-ID:專案 ID。
- operation-ID:匯入或匯出作業的 ID。詳情請參閱「事前準備」一文。
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/v1beta4/projects/project-ID /operations/operation-ID /cancel
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://sqladmin.googleapis.com/v1beta4/projects/project-ID /operations/operation-ID /cancel"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1beta4/projects/project-ID /operations/operation-ID /cancel" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{}
查看取消狀態
您可以使用 gcloud
或 REST API 指令,查看已取消匯入或匯出作業的狀態。
gcloud sql operations describe
指令檢查已取消作業的狀態。
gcloud sql operations describeoperation-ID
使用任何要求資料之前,請先替換以下項目:
- project-ID:專案 ID。
- operation-ID:匯入或匯出作業的 ID。詳情請參閱「事前準備」一文。
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/project-ID /operations/operation-ID
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/project-ID /operations/operation-ID "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-ID /operations/operation-ID " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-ID ", "status": "DONE", "user": "user@example.com", "insertTime": "2022-11-08T22:12:58.199Z", "startTime": "2022-11-08T22:13:04.798Z", "endTime": "2022-11-08T22:13:45.862Z", "error": { "kind": "sql#operationErrors", "errors": [ { "kind": "sql#operationError", "code": "CANCEL_SUCCESSFUL", "message": "Operation successfully cancelled" } ] }, "operationType": "EXPORT", "exportContext": { "uri": "gs://replica-bucket/source-database.sql", "kind": "sql#exportContext", "sqlExportOptions": { "schemaOnly": false, "mysqlExportOptions": { "masterData": 0 } }, "fileType": "SQL" }, "name": "operation-ID ", "targetId": "cloud-sql-instance-display-name ", "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-ID /operations/operation-ID ", "targetProject": "project-ID ", "instanceUid": "cloud-sql-instance-ID " }
使用任何要求資料之前,請先替換以下項目:
- project-ID:專案 ID。
- operation-ID:匯入或匯出作業的 ID。詳情請參閱「事前準備」一文。
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1beta4/projects/project-ID /operations/operation-ID
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1beta4/projects/project-ID /operations/operation-ID "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1beta4/projects/project-ID /operations/operation-ID " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1beta4/projects/project-ID ", "status": "DONE", "user": "user@example.com", "insertTime": "2022-11-08T22:12:58.199Z", "startTime": "2022-11-08T22:13:04.798Z", "endTime": "2022-11-08T22:13:45.862Z", "error": { "kind": "sql#operationErrors", "errors": [ { "kind": "sql#operationError", "code": "CANCEL_SUCCESSFUL", "message": "Operation successfully cancelled" } ] }, "operationType": "EXPORT", "exportContext": { "uri": "gs://replica-bucket/source-database.sql", "kind": "sql#exportContext", "sqlExportOptions": { "schemaOnly": false, "mysqlExportOptions": { "masterData": 0 } }, "fileType": "SQL" }, "name": "operation-ID ", "targetId": "cloud-sql-instance-display-name ", "selfLink": "https://sqladmin.googleapis.com/v1beta4/projects/project-ID /operations/operation-ID ", "targetProject": "project-ID ", "instanceUid": "cloud-sql-instance-ID " }
疑難排解
問題 | 疑難排解 |
---|---|
錯誤訊息:You can't cancel operation [operation-ID] because
this operation isn't in progress. |
您嘗試取消的匯入或匯出作業已完成、失敗或取消。如果作業正在執行,可以取消作業。 |
錯誤訊息:You can't cancel operation [operation-ID] because
Cloud SQL doesn't support the cancellation of an [operation-type]
operation. |
Cloud SQL 不支援取消作業,因為作業的作業類型不是 |
錯誤訊息:The [operation-type] operation isn't cancelled. Wait
and retry in a few seconds. |
Cloud SQL 目前無法取消匯入或匯出作業。 請稍後再試。如果問題仍未解決,請與Google Cloud 支援團隊聯絡。 |
後續步驟
- 進一步瞭解匯入及匯出資料的最佳做法。
- 瞭解如何使用 SQL 傾印檔案將資料匯出及匯入 Cloud SQL 執行個體。
- 瞭解如何檢查匯入與匯出作業的狀態。
- 匯入及匯出作業的已知問題。