恢复实例
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面介绍了如何从备份恢复实例以及执行实例的时间点恢复。
如需了解恢复操作或时间点恢复的相关信息、最佳做法和要求,请参阅实例恢复概览。
从按需备份或自动备份恢复
您可以在以下情况下使用按需备份或自动备份:
- 恢复到同一项目中的不同实例
- 恢复到在其中进行备份的同一实例
- 恢复到其他项目或区域中的不同实例
如果您已启用时间点恢复 (PITR),则可以根据实例的日志保留设置,将实例恢复到特定时间点。
恢复到不同实例
当您将数据从备份恢复到不同实例时,您可以将目标实例上的数据更新为进行备份时来源实例的状态。如需了解详情,请参阅关于执行恢复操作的一般提示以及关于恢复到不同实例的提示和要求。
如果您需要项目的备份列表,但因发生服务中断而无法在实例概览页面上查看这些备份,则可以将 backupRuns.list
API 与通配符 (-
) 结合使用。通配符选项用于检索项目中所有实例的所有备份列表。如需了解详情,请参阅在服务中断期间查看备份。
控制台
-
在 Google Cloud 控制台中,转到 Cloud SQL 实例页面。
转到“Cloud SQL 实例”
-
如果目标实例具有任何读取副本,请使用“更多操作”菜单
删除这些副本。
-
如需打开实例的概览页面,请点击实例名称。
- 从 SQL 导航菜单中选择备份。
- 找到您要从中恢复数据的备份,然后点击恢复。
- 在使用备份恢复实例页面中,确认在查看备份详情中选择了正确的备份。
- 在选择恢复目标位置中,选择覆盖现有实例。
- 从要覆盖的实例菜单中,选择您要用于恢复的实例。您选择的实例及其所有数据都会被覆盖。
- 要确认您的选择,请在目标实例 ID 字段中输入要覆盖的实例的名称。
- 如需开始恢复过程,请点击恢复。
- 如需检查恢复操作的状态,请前往实例的操作页面。
- 恢复操作完成后,重新创建您在此过程中删除的任何副本。
gcloud
-
如需确定目标实例是否具有任何读取副本,请使用
gcloud sql instances describe
命令:
gcloud sql instances describe TARGET_INSTANCE_NAME
请记下 replicaNames
列中列出的任何实例。
- 如需删除所有副本,请使用
gcloud sql instances delete
命令:
gcloud sql instances delete REPLICA_NAME
对每个副本重复此操作。
-
如需列出来源实例的备份,请使用
gcloud sql backups list
命令:
gcloud sql backups list \
--instance SOURCE_INSTANCE_NAME
-
找到您要使用的备份,并记录其
ID
值。
- 如需从备份恢复目标实例,请使用
gcloud sql backups restore
命令:
gcloud sql backups restore BACKUP_ID \
--restore-instance=TARGET_INSTANCE_NAME \
--backup-instance=SOURCE_INSTANCE_NAME
-
恢复操作完成后,重新创建您在此过程中删除的任何副本。
REST v1
-
如需确定实例是否具有任何读取副本以及获取这些副本的 ID,请列出目标实例的所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames"
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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"replicaNames": [
"REPLICA_NAME"
]
}
-
删除所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- REPLICA_ID:副本 ID
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE_BACKUP",
"name": "OPERATION_ID",
"targetId": "REPLICA_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
对每个副本重复此操作。
- 如需获取您要使用的备份的 ID,请列出来源实例的备份。
在使用任何请求数据之前,请先进行以下替换:
- project-id:项目 ID
- instance-id:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns"
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/instances/instance-id/backupRuns" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#backupRun",
"status": "SUCCESSFUL",
"enqueuedTime": "2020-01-21T11:25:33.818Z",
"id": "backup-id",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"windowStartTime": "2020-01-21T10:00:00.479Z",
"instance": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns/backup-id",
"location": "us"
}
-或-
如果实例位于发生服务中断的区域,请列出项目中的所有备份
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID,或
-
(对于项目中所有备份的列表)
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/-/backupRuns
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/-/backupRuns"
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/instances/-/backupRuns" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#backupRun",
"status": "SUCCESSFUL",
"enqueuedTime": "2020-01-21T11:25:33.818Z",
"id": "BACKUP_ID",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"windowStartTime": "2020-01-21T10:00:00.479Z",
"instance": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_ID",
"location": "us"
"backupKind": "SNAPSHOT"
}
找到您需要恢复的实例的备份。
-
使用备份恢复目标实例。
在使用任何请求数据之前,请先进行以下替换:
- project-id:项目 ID
- target-instance-id:目标实例 ID
- source-instance-id:源实例 ID
- backup-id:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/target-instance-id/restoreBackup
请求 JSON 正文:
{
"restoreBackupContext":
{
"backupRunId": backup-id,
"instanceId": "source-instance-id"
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/target-instance-id/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/target-instance-id/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "operation-id",
"targetId": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}
-
恢复操作完成后,重新创建您在此过程中删除的任何副本。
REST v1beta4
- 如需确定实例是否具有任何读取副本以及获取这些副本的 ID,请列出目标实例的所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames
如需发送您的请求,请展开以下选项之一:
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/instances/INSTANCE_ID?fields=replicaNames"
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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"replicaNames": [
"REPLICA_NAME"
]
}
-
删除所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- REPLICA_ID:副本 ID
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE_BACKUP",
"name": "OPERATION_ID",
"targetId": "REPLICA_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
对每个副本重复此操作。
- 如需获取您要使用的备份的 ID,请列出来源实例的备份。
在使用任何请求数据之前,请先进行以下替换:
- project-id:项目 ID
- instance-id:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns
如需发送您的请求,请展开以下选项之一:
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/instances/instance-id/backupRuns"
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/instances/instance-id/backupRuns" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#backupRun",
"status": "SUCCESSFUL",
"enqueuedTime": "2020-01-21T11:25:33.818Z",
"id": "backup-id",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"windowStartTime": "2020-01-21T10:00:00.479Z",
"instance": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns/backup-id",
"location": "us"
}
-
使用备份恢复目标实例。
在使用任何请求数据之前,请先进行以下替换:
- project-id:项目 ID
- target-instance-id:目标实例 ID
- source-instance-id:源实例 ID
- backup-id:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/target-instance-id/restoreBackup
请求 JSON 正文:
{
"restoreBackupContext":
{
"backupRunId": backup-id,
"instanceId": "source-instance-id"
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/target-instance-id/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/target-instance-id/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "operation-id",
"targetId": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}
-
恢复操作完成后,重新创建您在此过程中删除的任何副本。
恢复到同一实例
当您将数据从备份恢复到同一实例时,您可以将该实例上的数据恢复到进行备份时的状态。如需详细了解如何恢复实例,请参阅关于执行恢复操作的一般提示。
控制台
-
在 Google Cloud 控制台中,转到 Cloud SQL 实例页面。
转到“Cloud SQL 实例”
-
如果目标实例具有任何读取副本,请使用“更多操作”菜单
删除这些副本。
-
如需打开实例的概览页面,请点击实例名称。
- 从 SQL 导航菜单中选择备份。
- 找到您要使用的备份,然后点击恢复。
- 在使用备份恢复实例页面中,确认在查看备份详情中选择了正确的备份。
- 在选择恢复目标位置中,选择覆盖源实例。
检查括号中是否指定了源实例的名称。
- 要确认您的选择,请在目标实例 ID 字段中输入实例名称。
- 如需开始恢复过程,请点击恢复。
- 如需检查恢复操作的状态,请前往实例的操作页面。
- 恢复操作完成后,重新创建您在此过程中删除的任何副本。
REST v1
-
如需确定实例是否有任何读取副本以及获取这些副本的 ID,请列出该实例的所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames"
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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"replicaNames": [
"REPLICA_NAME"
]
}
-
删除所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- REPLICA_ID:副本 ID
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE_BACKUP",
"name": "OPERATION_ID",
"targetId": "REPLICA_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
对每个副本重复此操作。
- 如需获取您要使用的备份的 ID,请列出实例的备份。
在使用任何请求数据之前,请先进行以下替换:
- project-id:项目 ID
- instance-id:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns"
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/instances/instance-id/backupRuns" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#backupRun",
"status": "SUCCESSFUL",
"enqueuedTime": "2020-01-21T11:25:33.818Z",
"id": "backup-id",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"windowStartTime": "2020-01-21T10:00:00.479Z",
"instance": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns/backup-id",
"location": "us"
}
-
从指定的备份恢复实例。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
- BACKUP_ID:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
"restoreBackupContext":
{
"backupRunId": "BACKUP_ID",
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
-
恢复操作完成后,重新创建您在此过程中删除的任何副本。
REST v1beta4
-
如需确定实例是否有任何读取副本以及获取这些副本的 ID,请列出该实例的所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames
如需发送您的请求,请展开以下选项之一:
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/instances/INSTANCE_ID?fields=replicaNames"
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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"replicaNames": [
"REPLICA_NAME"
]
}
-
删除所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- REPLICA_ID:副本 ID
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE_BACKUP",
"name": "OPERATION_ID",
"targetId": "REPLICA_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
对每个副本重复此操作。
-
如需获取您要使用的备份的 ID,请列出实例的备份。
在使用任何请求数据之前,请先进行以下替换:
- project-id:项目 ID
- instance-id:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns
如需发送您的请求,请展开以下选项之一:
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/instances/instance-id/backupRuns"
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/instances/instance-id/backupRuns" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#backupRun",
"status": "SUCCESSFUL",
"enqueuedTime": "2020-01-21T11:25:33.818Z",
"id": "backup-id",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"windowStartTime": "2020-01-21T10:00:00.479Z",
"instance": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns/backup-id",
"location": "us"
}
-
从指定的备份恢复实例。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
- BACKUP_RUN_ID:Cloud SQL 从备份恢复实例的日期和时间戳
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
"restoreBackupContext":
{
"backupRunId": "BACKUP_RUN_ID",
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
-
恢复操作完成后,重新创建您在此过程中删除的任何副本。
恢复到其他项目中的实例
您可以使用 project
参数将数据恢复到与最初用于创建备份的实例不属于同一项目的实例。使用 project
参数时,请在项目中以及对要将数据恢复到的实例调用 restoreBackup
。当您使用备份恢复到不同实例时,会将目标实例上的数据更新为之前创建备份时源实例所处的状态。
权限
恢复到其他项目的用户必须具有目标项目的 cloudsql.instances.restoreBackup
权限和来源实例的 cloudsql.backupRuns.get
权限。Cloud SQL Admin
角色可提供这些权限。
如需将数据恢复到其他项目中的实例,请按如下所述操作:
gcloud
-
列出实例的备份。
gcloud sql backups list --instance INSTANCE_NAME
将 INSTANCE_NAME 替换为实例名称。
-
找到您要使用的备份,并记录它的
ID
值。
-
将数据恢复到其他项目中的实例。
gcloud sql backups restore BACKUP_ID \
--restore-instance=TARGET_INSTANCE_NAME \
--backup-instance=SOURCE_INSTANCE_NAME \
--backup-project=SOURCE_INSTANCE_PROJECT
进行以下替换:
- BACKUP_ID:备份的 ID。您之前在此过程中获得了此 ID。
- TARGET_INSTANCE_NAME:您要将数据恢复到的目标项目中的实例。
- SOURCE_INSTANCE_NAME:来源项目中包含您要恢复到目标项目中实例的数据的实例。
- SOURCE_INSTANCE_PROJECT:包含来源实例的项目。
REST v1
如需获取 backupId
,请运行以下命令。
在使用任何请求数据之前,请先进行以下替换:
- project-id:项目 ID
- instance-id:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns"
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/instances/instance-id/backupRuns" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#backupRun",
"status": "SUCCESSFUL",
"enqueuedTime": "2020-01-21T11:25:33.818Z",
"id": "backup-id",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"windowStartTime": "2020-01-21T10:00:00.479Z",
"instance": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns/backup-id",
"location": "us"
}
将备份恢复到其他项目中的实例:
在使用任何请求数据之前,请先进行以下替换:
- source-project-id:源项目 ID
- target-project-id:目标项目 ID
- target-instance-id:目标实例 ID
- source-instance-id:源实例 ID
- backup-id:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/target-project-id/instances/target-instance-id/restoreBackup
请求 JSON 正文:
{
"restoreBackupContext":
{
"backupRunId": backup-id,
"project": "source-project-id",
"instanceId": "source-instance-id"
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/target-project-id/instances/target-instance-id/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/target-project-id/instances/target-instance-id/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/target-project-id/instances/target-instance-id",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_VOLUME",
"name": "operation-id",
"targetId": "target-instance-id",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/target-project-id/operations/operation-id",
"targetProject": "target-project-id"
}
如需详细了解 project
属性,请参阅 restoreBackup
REST v1beta4
如需获取 backupId
,请运行以下命令。
在使用任何请求数据之前,请先进行以下替换:
- project-id:项目 ID
- instance-id:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns
如需发送您的请求,请展开以下选项之一:
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/instances/instance-id/backupRuns"
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/instances/instance-id/backupRuns" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#backupRun",
"status": "SUCCESSFUL",
"enqueuedTime": "2020-01-21T11:25:33.818Z",
"id": "backup-id",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"windowStartTime": "2020-01-21T10:00:00.479Z",
"instance": "instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns/backup-id",
"location": "us"
}
将备份恢复到其他项目中的实例:
在使用任何请求数据之前,请先进行以下替换:
- source-project-id:源项目 ID
- target-project-id:目标项目 ID
- target-instance-id:目标实例 ID
- source-instance-id:源实例 ID
- backup-id:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/target-project-id/instances/target-instance-id/restoreBackup
请求 JSON 正文:
{
"restoreBackupContext":
{
"backupRunId": backup-id,
"project": "source-project-id",
"instanceId": "source-instance-id"
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/target-project-id/instances/target-instance-id/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/target-project-id/instances/target-instance-id/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/target-project-id/instances/target-instance-id",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_VOLUME",
"name": "operation-id",
"targetId": "target-instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/target-project-id/operations/operation-id",
"targetProject": "target-project-id"
}
如需详细了解 project
属性,请参阅 restoreBackup
从最终备份恢复
您可以在以下情况下使用最终备份:
- 将最终备份恢复到新实例
- 恢复到其他项目或区域中的新实例
由于您是使用已删除实例的最终备份来恢复实例,因此您还可以使用该备份创建具有已删除实例配置的实例并恢复数据。
恢复到新实例
当您从最终备份创建实例时,Cloud SQL 会使用在其中进行最终备份的实例的配置设置。创建实例后,Cloud SQL 会将数据恢复到进行最终备份时的状态。
控制台
在 Google Cloud 控制台中,前往 Cloud SQL 备份页面。
前往“Cloud SQL 备份”
此页面列出了与 Google Cloud 项目关联的所有备份,包括最终备份。
- 点击包含您要恢复到新实例的数据的最终备份。
- 在最终备份对话框中,点击恢复。
- 在使用备份恢复实例页面中,确认在查看备份详情中选择了正确的备份。
- 在选择恢复目标位置中,选择恢复到新实例。
- 从区域菜单中,选择新实例的区域。
- 在实例 ID 字段中,输入新实例的 ID。
- 如需开始恢复过程,请点击恢复。
- 如需检查恢复操作的状态,请前往实例的操作页面。
gcloud
-
如需列出来源实例的最终备份,请使用
gcloud sql backups list
命令:
gcloud sql backups list \
--filter='type:FINAL instance: SOURCE_INSTANCE_NAME'
-
找到您要使用的备份,并记录其
NAME
值。
- 如需从指定的最终备份恢复新实例,请使用
gcloud sql backups restore
命令:
gcloud sql backups restore BACKUP_NAME \
--restore-instance=TARGET_INSTANCE_NAME
REST v1
- 如需获取您要使用的备份的 ID,请列出来源实例的最终备份。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_ID'" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"state": "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": "This is a 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
}
-
从指定的最终备份恢复新实例。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- TARGET_INSTANCE_ID:目标实例 ID
- BACKUP_ID:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
backup: projects/PROJECT_ID/backups/BACKUP_ID
restore_instance_settings: {}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
REST v1beta4
- 如需获取您要使用的备份的 ID,请列出来源实例的最终备份。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_ID'" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"state": "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": "This is a 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
}
-
从指定的最终备份恢复新实例。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- TARGET_INSTANCE_ID:目标实例 ID
- BACKUP_ID:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
backup: projects/PROJECT_ID/backups/BACKUP_ID
restore_instance_settings: {}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
恢复到现有实例
当您将数据从最终备份恢复到现有实例时,您可以将目标实例上的数据更新为进行备份时来源实例的状态。如需了解详情,请参阅关于执行恢复操作的一般提示以及关于恢复到不同实例的提示和要求。
如果您需要项目的备份列表,但因发生服务中断而无法在实例概览页面上查看这些备份,则可以使用 backupRuns.list
API。
控制台
-
在 Google Cloud 控制台中,转到 Cloud SQL 实例页面。
转到“Cloud SQL 实例”
-
如果目标实例具有任何读取副本,请使用“更多操作”菜单
删除这些副本。
在 Google Cloud 控制台中,前往 Cloud SQL 备份页面。
前往“Cloud SQL 备份”
此页面列出了与 Google Cloud 项目关联的所有备份,包括最终备份。
- 点击包含您要恢复到其他实例的数据的最终备份。
- 在最终备份对话框中,点击恢复。
- 在使用备份恢复实例页面中,确认在查看备份详情中选择了正确的备份。
- 在选择恢复目标位置中,选择覆盖现有实例。
从要覆盖的实例菜单中,选择您要用于恢复的实例。您选择的实例及其所有数据都会被覆盖。
- 如需确认您的选择,请在目标实例 ID 字段中输入要覆盖的实例的名称。
- 如需开始恢复过程,请点击恢复。
- 如需检查恢复操作的状态,请前往实例的操作页面。
- 恢复操作完成后,重新创建您在此过程中删除的任何副本。
gcloud
-
如需确定目标实例是否具有任何读取副本,请使用
gcloud sql instances describe
命令:
gcloud sql instances describe TARGET_INSTANCE_NAME
请记下 replicaNames
列中列出的任何实例。
- 如需删除所有副本,请使用
gcloud sql instances delete
命令:
gcloud sql instances delete REPLICA_NAME
对每个副本重复此操作。
-
如需列出来源实例的最终备份,请使用
gcloud sql backups list
命令:
gcloud sql backups list \
--filter='type:FINAL instance: SOURCE_INSTANCE_NAME'
-
找到您要使用的备份,并记录其
NAME
值。
- 如需从备份中恢复目标实例,请使用
gcloud sql backups restore
命令:
gcloud sql backups restore BACKUP_NAME \
--restore-instance=TARGET_INSTANCE_NAME
-
恢复操作完成后,重新创建您在此过程中删除的任何副本。
REST v1
-
如需确定实例是否具有任何读取副本以及获取这些副本的 ID,请列出目标实例的所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames"
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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"replicaNames": [
"REPLICA_NAME"
]
}
-
删除所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- REPLICA_ID:副本 ID
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE_BACKUP",
"name": "OPERATION_ID",
"targetId": "REPLICA_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
对每个副本重复此操作。
- 如需获取您要使用的最终备份的 ID,请列出来源实例的备份。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_ID'" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"state": "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": "This is a 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
}
找到您需要恢复的实例的备份。
-
使用备份恢复目标实例。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- TARGET_INSTANCE_ID:目标实例 ID
- BACKUP_ID:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
backup: projects/PROJECT_ID/backups/BACKUP_ID
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
-
恢复操作完成后,重新创建您在此过程中删除的任何副本。
REST v1beta4
- 如需确定实例是否具有任何读取副本以及获取这些副本的 ID,请列出目标实例的所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID?fields=replicaNames
如需发送您的请求,请展开以下选项之一:
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/instances/INSTANCE_ID?fields=replicaNames"
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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"replicaNames": [
"REPLICA_NAME"
]
}
-
删除所有副本。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- REPLICA_ID:副本 ID
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE_BACKUP",
"name": "OPERATION_ID",
"targetId": "REPLICA_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
对每个副本重复此操作。
- 如需获取您要使用的备份的 ID,请列出来源实例的备份。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_ID'" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"state": "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": "This is a 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
}
找到您需要恢复的实例的备份。
-
使用备份恢复目标实例。
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- TARGET_INSTANCE_ID:目标实例 ID
- BACKUP_ID:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
backup: projects/PROJECT_ID/backups/BACKUP_ID
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
-
恢复操作完成后,重新创建您在此过程中删除的任何副本。
恢复到其他项目中的实例
将数据恢复到其他项目中的实例的用户必须具有目标项目的 cloudsql.instances.restoreBackup
权限和来源实例的 cloudsql.backupRuns.get
权限。Cloud SQL Admin
角色可提供这些权限。
如需将数据恢复到其他项目中的实例,请按如下所述操作:
REST v1
如需获取最终备份的 backupId
,请运行以下命令:
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_ID'" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"state": "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": "This is a 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
}
将备份恢复到其他项目中的实例:
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- TARGET_INSTANCE_ID:目标实例 ID
- BACKUP_ID:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
backup: projects/PROJECT_ID/backups/BACKUP_ID
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
如需详细了解 project
属性,请参阅 restoreBackup
REST v1beta4
如需获取最终备份的 backupId
,请运行以下命令:
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_ID'" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"state": "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": "This is a 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
}
将备份恢复到其他项目中的实例:
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- TARGET_INSTANCE_ID:目标实例 ID
- BACKUP_ID:备份 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
backup: projects/PROJECT_ID/backups/BACKUP_ID
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
如需详细了解 project
属性,请参阅 restoreBackup
恢复到其他区域中的新实例
将数据恢复到其他区域中的新实例的用户必须具有目标项目的 cloudsql.instances.restoreBackup
权限和来源实例的 cloudsql.backupRuns.get
权限。Cloud SQL Admin
角色可提供这些权限。
此外,如需在其他区域中创建实例,您必须符合该区域的组织政策条件。
如需将数据恢复到其他区域中的新实例,请执行以下操作:
gcloud
-
如需列出来源实例的最终备份,请使用
gcloud sql backups list
命令:
gcloud sql backups list \
--filter='type:FINAL instance: SOURCE_INSTANCE_NAME'
-
找到您要使用的备份,并记录其
NAME
值。
- 如需使用最终备份将数据恢复到其他区域中的新实例,请使用
gcloud sql backups restore
命令:
gcloud sql backups restore BACKUP_NAME \
--restore-instance=TARGET_INSTANCE_NAME \
--region=TARGET_REGION
REST v1
如需获取最终备份的 backupId
,请运行以下命令:
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_ID'" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"state": "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": "This is a 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
}
将备份恢复到其他区域中的新实例:
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- TARGET_INSTANCE_ID:目标实例 ID
- BACKUP_ID:备份 ID
- REGION:目标实例所在的区域(例如
us-central1
)
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
backup: projects/PROJECT_ID/backups/BACKUP_ID
restore_instance_settings: {
region: REGION
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
如需详细了解 project
属性,请参阅 restoreBackup
REST v1beta4
如需获取最终备份的 backupId
,请运行以下命令:
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- INSTANCE_ID:实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_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?filter='type:FINAL AND instance:INSTANCE_ID'" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"name": "projects/PROJECT_ID/backups/BACKUP_ID",
"kind": "sql#backup",
"state": "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": "This is a 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
}
将备份恢复到其他区域中的新实例:
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:项目 ID
- TARGET_INSTANCE_ID:目标实例 ID
- BACKUP_ID:备份 ID
- REGION:目标实例所在的区域(例如
us-central1
)
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup
请求 JSON 正文:
{
backup: projects/PROJECT_ID/backups/BACKUP_ID
restore_instance_settings: {
region: REGION
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "RESTORE_BACKUP",
"name": "OPERATION_ID",
"targetId": "TARGET_INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
如需详细了解 project
属性,请参阅 restoreBackup
执行时间点恢复
如需执行时间点恢复,请参阅时间点恢复。
标识恢复时间点
在执行时间点恢复之前,必须已标识二进制日志文件名和时间点,该时间点与您要将实例恢复到的时间点相对应。
如需完成此任务,请参阅确定恢复位置。
后续步骤