本页面介绍了如何针对 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 实例导出和导入数据。
- 了解如何检查导入和导出操作的状态。
- 导入和导出的已知问题。