管理最终备份
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面介绍了如何管理 Cloud SQL 实例的最终备份。在删除实例之前,您可以对实例进行最终备份。然后,您可以将最终备份恢复到新实例或现有实例。这样一来,您就可以重新创建您不小心删除的任何实例,或者将这些实例用于任何灾难恢复场景。
和与实例关联的自动备份和按需备份不同,您可以在删除实例之前进行最终备份。Cloud SQL 会在实例生命周期结束后继续存储此备份。
您可以使用现有的 gcloud CLI 命令来列出、说明、更新和删除最终备份。如果您使用的是自定义角色,请向这些角色添加以下权限:
cloudsql.backupRuns.list
cloudsql.backupRuns.get
cloudsql.backupRuns.update
cloudsql.backupRuns.delete
如需详细了解这些权限,请参阅所需权限。此外,如需详细了解备份的工作原理,请参阅 Cloud SQL 备份简介。
所需权限
Google Cloud 控制台
如需管理 Google Cloud 项目中的最终备份,您需要拥有以下权限:
任务 |
所需权限 |
列出最终备份 |
cloudsql.backupRuns.list |
描述最终备份 |
cloudsql.backupRuns.get |
更新最终备份 |
cloudsql.backupRuns.update |
删除最终备份 |
cloudsql.backupRuns.delete |
如需管理 Google Cloud 项目中的最终备份,您需要拥有以下权限:
操作 |
命令 |
所需权限 |
列出最终备份 |
gcloud sql backups list |
cloudsql.backupRuns.list |
描述最终备份 |
gcloud sql backups describe |
cloudsql.backupRuns.get |
更新最终备份 |
gcloud sql backups patch |
cloudsql.backupRuns.update |
删除最终备份 |
gcloud sql backups delete |
cloudsql.backupRuns.delete |
REST
如需管理 Google Cloud 项目中的最终备份,您需要拥有以下权限:
操作 |
方法 |
所需权限 |
列出最终备份 |
backups.list |
cloudsql.backupRuns.list |
描述最终备份 |
backups.describe |
cloudsql.backupRuns.get |
更新最终备份 |
backups.patch |
cloudsql.backupRuns.update |
删除最终备份 |
backups.delete |
cloudsql.backupRuns.delete |
查看最终备份列表
您可以使用 Google Cloud 控制台、gcloud CLI 或 Cloud SQL API 查看最终备份列表和备份详情。
Google Cloud 控制台不会在备份历史记录中显示被跳过或失败的备份。如需查看这些类型的备份,请使用 gcloud
或 Cloud SQL API。
控制台
在 Google Cloud 控制台中,前往 Cloud SQL 备份页面。
前往 Cloud SQL 备份
本页面列出了与 Google Cloud 项目关联的所有备份,包括最终备份。
如需查看最终备份的详细信息,请点击相应备份。系统随即会显示最终备份对话框。此对话框会显示以下信息:
- 用于创建最终备份的实例删除的日期和时间
- 已删除实例的名称和版本
- 日期和时间戳,表示 Cloud SQL 保留最终备份的时间
- 最终备份的说明
gcloud
如需获取与 Google Cloud 项目关联的所有最终备份的列表,请使用 gcloud sql backups list
命令:
gcloud sql backups list \
--filter="type=FINAL"
如需查看有关最终备份的详细信息,请使用 gcloud sql backups describe
命令:
gcloud sql backups describe \
BACKUP_NAME
您可以从运行 gcloud sql backups list
命令的输出中获取 BACKUP_NAME。BACKUP_NAME 采用以下格式:projects/PROJECT_ID/backups/BACKUP_ID
。
REST v1
获取最终备份列表
使用此示例可获取与 Google Cloud 项目关联的所有最终备份的列表。如需查看此调用的完整参数列表,请参阅 backupRuns.list 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL"
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/backups?filter=type=FINAL" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"status": "SUCCESSFUL",
"backupInterval": {
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
}
"type": "FINAL",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",
"location": "us"
"description": "final backup",
"backupKind": "SNAPSHOT",
"dataDiskSizeGB": "10",
"expiryTime": "2020-01-30T11:26:18.663Z",
"backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",
"satisfies_pzs": false,
"satisfies_pzi": false
}
查看最终备份的详细信息
使用此示例可查看最终备份的详细信息。如需查看此调用的完整参数列表,请参阅 backupRuns.get 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_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/backups/BACKUP_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/backups/BACKUP_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"status": "SUCCESSFUL",
"backupInterval": {
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
}
"type": "FINAL",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",
"location": "us"
"description": "final backup",
"backupKind": "SNAPSHOT",
"dataDiskSizeGB": "10",
"expiryTime": "2020-01-30T11:26:18.663Z",
"backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",
"satisfies_pzs": false,
"satisfies_pzi": false
}
REST v1beta4
获取最终备份列表
使用此示例可获取与 Google Cloud 项目关联的所有最终备份的列表。如需查看此调用的完整参数列表,请参阅 backupRuns.list 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"status": "SUCCESSFUL",
"backupInterval": {
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
}
"type": "FINAL",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",
"location": "us"
"description": "final backup",
"backupKind": "SNAPSHOT",
"dataDiskSizeGB": "10",
"expiryTime": "2020-01-30T11:26:18.663Z",
"backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",
"satisfies_pzs": false,
"satisfies_pzi": false
}
查看最终备份的详细信息
使用此示例可查看最终备份的详细信息。如需查看此调用的完整参数列表,请参阅 backupRuns.get 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"status": "SUCCESSFUL",
"backupInterval": {
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
}
"type": "FINAL",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",
"location": "us"
"description": "final backup",
"backupKind": "SNAPSHOT",
"dataDiskSizeGB": "10",
"expiryTime": "2020-01-30T11:26:18.663Z",
"backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",
"satisfies_pzs": false,
"satisfies_pzi": false
}
更新最终备份
您可以使用 Google Cloud 控制台、gcloud CLI 或 Cloud SQL API 更新实例的 Cloud SQL 保留最终备份的时间和备份说明。
控制台
在 Google Cloud 控制台中,前往 Cloud SQL 备份页面。
前往 Cloud SQL 备份
本页面列出了与 Google Cloud 项目关联的所有备份,包括最终备份。
- 如需更新最终备份,请点击相应备份。系统随即会显示最终备份对话框。
- 如需更新 Cloud SQL 保留最终备份的时间长度,请完成以下操作:
- 点击备份保留期限字段旁边的修改保留期限图标。
- 点击保留备份数据至字段旁边的选择日期图标。
- 在日历中,选择新日期,以指明 Cloud SQL 保留最终备份的时间。
- 点击更新。您会返回到 Cloud SQL 备份页面。
- 如需更新最终备份的说明,请完成以下操作:
- 点击最终备份。
- 点击说明字段旁边的修改说明图标。
- 在描述此备份字段中,输入最终备份的更新说明。
- 点击更新。您会返回到 Cloud SQL 备份页面。
gcloud
如需获取与 Google Cloud 项目关联的所有最终备份的列表,请使用 gcloud sql backups list
命令:
gcloud sql backups list \
--filter="type=FINAL"
如需更新最终备份的说明和保留期限,请使用 gcloud sql backups patch
命令:
gcloud sql backups patch \
BACKUP_NAME \
--description=DESCRIPTION /
--expiry-time=DATE-AND-TIME-STAMP | --ttl-days=NUMBER-OF-DAYS
您可以从运行 gcloud sql backups list
命令的输出中获取 BACKUP_NAME。BACKUP_NAME 采用以下格式:projects/PROJECT_ID/backups/BACKUP_ID
。
对于 --expiry-time
和 --ttl-days
标志,请遵循以下准则:
- 对于
--expiry-time
标志,请指定 Cloud SQL 自动删除最终备份的日期和时间戳。
- 对于
--ttl-days
标志,请指定最终备份的保留期限(1 到 365 天)。这称为存留时间 (TTL)。保留期限从当前日期和时间开始计算,Cloud SQL 允许的保留期限上限为 1 年(或 365 天)。
REST v1
获取最终备份列表
使用此示例可获取与 Google Cloud 项目关联的所有最终备份的列表。如需查看此调用的完整参数列表,请参阅 backupRuns.list 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL"
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/backups?filter=type=FINAL" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"status": "SUCCESSFUL",
"backupInterval": {
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
}
"type": "FINAL",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",
"location": "us"
"description": "final backup",
"backupKind": "SNAPSHOT",
"dataDiskSizeGB": "10",
"expiryTime": "2020-01-30T11:26:18.663Z",
"backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",
"satisfies_pzs": false,
"satisfies_pzi": false
}
更新保留期限
您可以通过以下任一方式更新最终备份的保留期限:
- 保留天数:修改 Cloud SQL 保留备份的天数。
- 到期时间:提供 Cloud SQL 自动删除备份的更新日期和时间戳。
更新保留天数
使用此示例更新 Cloud SQL 保留最终备份的天数。如需查看此调用的完整参数列表,请参阅 backupRuns.update 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
- TTL_DAYS:最终备份的保留期限(1 到 365 天)。这称为存留时间 (TTL)。保留期限从当前日期和时间开始计算,Cloud SQL 允许的保留期限上限为 1 年(或 365 天)。
HTTP 方法和网址:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days
请求 JSON 正文:
{
"backup": {
expiration: {
"ttl_days": TTL_DAYS,
}
},
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",
"status": "DONE",
"user": "user@example.com",
"insertTime": "2024-02-15T00:10:22.078Z",
"operationType": "UPDATE_BACKUP",
"name": "OPERATION_ID",
"targetId": "BACKUP_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
更新到期时间
使用此示例为 Cloud SQL 删除备份的时间提供更新的日期和时间戳。如需查看此调用的完整参数列表,请参阅 backupRuns.update 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
- DATE_AND_TIME_STAMP:Cloud SQL 自动删除最终备份的时间戳。
HTTP 方法和网址:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time
请求 JSON 正文:
{
"backup": {
expiration: {
"expiry_time": DATE_AND_TIME_STAMP,
}
},
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",
"status": "DONE",
"user": "user@example.com",
"insertTime": "2024-02-15T00:10:22.078Z",
"operationType": "UPDATE_BACKUP",
"name": "OPERATION_ID",
"targetId": "BACKUP_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
更新说明
使用此示例更新最终备份的说明。如需查看此调用的完整参数列表,请参阅 backupRuns.update 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
- DESCRIPTION:最终备份的更新说明。
HTTP 方法和网址:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description
请求 JSON 正文:
{
"backup": {
"description": DESCRIPTION,
},
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",
"status": "DONE",
"user": "user@example.com",
"insertTime": "2024-02-15T00:10:22.078Z",
"operationType": "UPDATE_BACKUP",
"name": "OPERATION_ID",
"targetId": "BACKUP_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
REST v1beta4
获取最终备份列表
使用此示例可获取与 Google Cloud 项目关联的所有最终备份的列表。如需查看此调用的完整参数列表,请参阅 backupRuns.list 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"status": "SUCCESSFUL",
"backupInterval": {
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
}
"type": "FINAL",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",
"location": "us"
"description": "final backup",
"backupKind": "SNAPSHOT",
"dataDiskSizeGB": "10",
"expiryTime": "2020-01-30T11:26:18.663Z",
"backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",
"satisfies_pzs": false,
"satisfies_pzi": false
}
更新保留期限
您可以通过以下任一方式更新最终备份的保留期限:
- 保留天数:修改 Cloud SQL 保留备份的天数
- 到期时间:提供 Cloud SQL 自动删除备份的更新日期和时间戳。
更新保留天数
使用此示例更新 Cloud SQL 保留最终备份的天数。如需查看此调用的完整参数列表,请参阅 backupRuns.update 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
- TTL_DAYS:最终备份的保留期限(1 到 365 天)。这称为存留时间 (TTL)。保留期限从当前日期和时间开始计算,Cloud SQL 允许的保留期限上限为 1 年(或 365 天)。
HTTP 方法和网址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days
请求 JSON 正文:
{
"backup": {
expiration: {
"ttl_days": TTL_DAYS,
}
},
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",
"status": "DONE",
"user": "user@example.com",
"insertTime": "2024-02-15T00:10:22.078Z",
"operationType": "UPDATE_BACKUP",
"name": "OPERATION_ID",
"targetId": "BACKUP_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
更新到期时间
使用此示例为 Cloud SQL 删除备份的时间提供更新的日期和时间戳。如需查看此调用的完整参数列表,请参阅 backupRuns.update 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
- DATE_AND_TIME_STAMP:Cloud SQL 自动删除最终备份的时间戳。
HTTP 方法和网址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time
请求 JSON 正文:
{
"backup": {
expiration: {
"expiry_time": DATE_AND_TIME_STAMP,
}
},
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",
"status": "DONE",
"user": "user@example.com",
"insertTime": "2024-02-15T00:10:22.078Z",
"operationType": "UPDATE_BACKUP",
"name": "OPERATION_ID",
"targetId": "BACKUP_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
更新说明
使用此示例更新最终备份的说明。如需查看此调用的完整参数列表,请参阅 backupRuns.update 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
- DESCRIPTION:最终备份的更新说明。
HTTP 方法和网址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description
请求 JSON 正文:
{
"backup": {
"description": DESCRIPTION,
},
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",
"status": "DONE",
"user": "user@example.com",
"insertTime": "2024-02-15T00:10:22.078Z",
"operationType": "UPDATE_BACKUP",
"name": "OPERATION_ID",
"targetId": "BACKUP_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
删除最终备份
您可以使用 Google Cloud 控制台、gcloud CLI 或 Cloud SQL API 删除最终备份。
删除某个备份可能并不会释放与该备份大小相同的空间。 因为这是增量式备份,删除较旧的备份也许会将其中的部分内容转移到较新的备份中,从而使较新备份保持完整性。
控制台
在 Google Cloud 控制台中,前往 Cloud SQL 备份页面。
前往 Cloud SQL 备份
本页面列出了与 Google Cloud 项目关联的所有备份,包括最终备份。
- 对于要删除的最终备份,请点击“更多操作”图标
,然后选择删除。
- 在删除最终备份?窗口中,输入您用于创建最终备份的实例的名称,然后点击删除。
gcloud
如需获取与 Google Cloud 项目关联的所有最终备份的列表,请使用 gcloud sql backups list
命令:
gcloud sql backups list \
--filter="type=FINAL"
如需删除最终备份,请使用 gcloud sql backups delete
命令:
gcloud sql backups delete \
BACKUP_NAME
您可以从运行 gcloud sql backups list
命令的输出中获取 BACKUP_NAME。BACKUP_NAME 采用以下格式:projects/PROJECT_ID/backups/BACKUP_ID
。
REST v1
获取最终备份列表
使用此示例可获取与 Google Cloud 项目关联的所有最终备份的列表。如需查看此调用的完整参数列表,请参阅 backupRuns.list 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL"
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/backups?filter=type=FINAL" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"status": "SUCCESSFUL",
"backupInterval": {
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
}
"type": "FINAL",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",
"location": "us"
"description": "final backup",
"backupKind": "SNAPSHOT",
"dataDiskSizeGB": "10",
"expiryTime": "2020-01-30T11:26:18.663Z",
"backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",
"satisfies_pzs": false,
"satisfies_pzi": false
}
删除最终备份
使用此示例删除最终备份。如需查看此调用的完整参数列表,请参阅 backupRuns.delete 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE_BACKUP",
"name": "OPERATION_ID",
"targetId": "BACKUP_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
REST v1beta4
获取最终备份列表
使用此示例可获取与 Google Cloud 项目关联的所有最终备份的列表。如需查看此调用的完整参数列表,请参阅 backupRuns.list 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"status": "SUCCESSFUL",
"backupInterval": {
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
}
"type": "FINAL",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",
"location": "us"
"description": "final backup",
"backupKind": "SNAPSHOT",
"dataDiskSizeGB": "10",
"expiryTime": "2020-01-30T11:26:18.663Z",
"backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",
"satisfies_pzs": false,
"satisfies_pzi": false
}
删除最终备份
使用此示例删除最终备份。如需查看此调用的完整参数列表,请参阅 backupRuns.delete 页面。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID。
- BACKUP_ID:备份 ID。您可以从运行上一个调用的输出中获取此 ID。
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE_BACKUP",
"name": "OPERATION_ID",
"targetId": "BACKUP_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-02。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-04-02。"],[],[]]