還原執行個體
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁面說明如何從備份還原執行個體。
如需還原作業的相關資訊、最佳做法和相關規定,請參閱「還原執行個體總覽 」。
從隨選或自動備份還原
您可以在下列情況下使用隨選或自動備份:
還原至同一專案中的其他執行個體
還原至備份所在的相同執行個體
還原至其他專案或區域中的不同執行個體
如果您已啟用時間點復原 (PITR) ,則可根據執行個體的記錄保留設定,將執行個體復原至特定時間點。
注意: 只有同一個專案和區域的新執行個體支援即時還原功能。
從備份還原執行個體時,備份和目標執行個體必須位於相同的
時區 。
還原至其他執行個體
從備份還原資料至不同的執行個體時,目標執行個體中的資料會更新為當初建立備份時的來源執行個體狀態。詳情請參閱有關執行還原的一般提示 和還原至不同執行個體的提示與需求 。
如果您需要專案的備份清單,但因服務中斷而無法在執行個體總覽頁面中查看,可以使用 backupRuns.list
API 搭配萬用字元 (-
)。萬用字元選項會擷取專案中所有執行個體的所有備份清單。詳情請參閱「在服務中斷期間查看備份資料 」。
警告 :還原程序會覆寫執行個體中的所有現有資料,包括先前的時間點復原 (PITR) 記錄。保留執行個體先前的隨選和自動備份。
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如果目標執行個體有任何唯讀備用資源,請使用更多動作選單 刪除這些項目。
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中,選取「Backups」(備份) 。
找出要用來還原的備份,然後按一下「還原」 。
在「Restore an instance from a backup」 頁面中,確認您在「Review backup details」 中選取了正確的備份。
在「Choose restore destination」(選擇還原目的地) 中,選取「Overwrite an existing instance」(覆寫現有執行個體) 。
在「要覆寫的執行個體」 選單中,選取要用於還原作業的執行個體。所選執行個體及其所有資料都會遭到覆寫。
如要確認所選項目,請在「Destination instance ID」 欄位中輸入要覆寫的執行個體名稱。
如要開始還原程序,請按一下「還原」 。
如要查看還原作業的狀態,請前往執行個體的「Operations」 頁面。
還原作業完成後,請重建您在此程序中刪除的所有副本。
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
值。注意: 請選取狀態為 SUCCESSFUL
的備份。
如要從備份還原目標執行個體,請使用 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": "[email protected] ",
"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": "[email protected] ",
"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": "[email protected] ",
"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": "[email protected] ",
"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 "
}
還原作業完成後,請重新建立您在此程序中刪除的所有副本。
還原至相同執行個體
從備份還原至相同執行個體時,該執行個體的資料也會回到當初建立備份時的狀態。如需瞭解還原執行個體,請參閱執行還原的一般提示 。
警告 :還原程序會覆寫執行個體中的所有現有資料,包括先前的時間點復原 (PITR) 記錄。保留執行個體先前的隨選和自動備份。
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如果目標執行個體有任何唯讀備用資源,請使用更多動作選單 刪除這些項目。
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中,選取「Backups」(備份) 。
找出要使用的備份,然後按一下「還原」 。
在「Restore an instance from a backup」 頁面中,確認您在「Review backup details」 中選取了正確的備份。
在「Choose restore destination」(選擇還原目的地) 中,選取「Overwrite the source instance」(覆寫來源執行個體) 。檢查來源執行個體的名稱是否已在括號中指定。
如要確認所選項目,請在「Destination instance ID」 欄位中輸入執行個體名稱。
如要開始還原程序,請按一下「還原」 。
如要查看還原作業的狀態,請前往執行個體的「Operations」 頁面。
還原作業完成後,請重建您在此程序中刪除的所有副本。
REST v1
如要取得要使用的備份 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": "[email protected] ",
"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 /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": "[email protected] ",
"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
角色中。
警告 :還原程序會覆寫執行個體中的所有現有資料,包括先前的時間點復原 (PITR) 記錄。保留執行個體先前的隨選和自動備份。
如要將資料還原至其他專案中的執行個體,請按照下列步驟操作:
gcloud
列出執行個體的備份。
gcloud sql backups list --instance INSTANCE_NAME
將 INSTANCE_NAME 替換為執行個體名稱。
找出要使用的備份,並記錄其 ID
值。注意: 請選取標示為 SUCCESSFUL
的備份。
將資料還原至其他專案中的執行個體。
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": "[email protected] ",
"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": "[email protected] ",
"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 專案相關聯的所有備份 (包括最終備份)。
按一下最終備份,其中包含要還原至新執行個體的資料。
在「最終備份」 對話方塊中,按一下「還原」 。
在「Restore an instance from a backup」 頁面中,確認您在「Review backup details」 中選取了正確的備份。
在「選擇還原目的地」 中,選取「還原至新執行個體」 。
從「Region」 選單中,選取新執行個體的地區。
在「Instance ID」 欄位中,輸入新執行個體的 ID。
如要開始還原程序,請按一下「還原」 。
如要查看還原作業的狀態,請前往執行個體的「Operations」 頁面。
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
注意: restore_instance_settings: {}
程式碼行可讓 Cloud SQL 將資料從備份還原至新執行個體。
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": "[email protected] ",
"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
注意: restore_instance_settings: {}
程式碼行可讓 Cloud SQL 將資料從備份還原至新執行個體。
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": "[email protected] ",
"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。
警告 :還原程序會覆寫執行個體中的所有現有資料,包括先前的時間點復原 (PITR) 記錄。保留執行個體先前的隨選和自動備份。
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如果目標執行個體有任何唯讀備用資源,請使用更多動作選單 刪除這些項目。
前往 Google Cloud 控制台的「Cloud SQL 備份」 頁面。
前往 Cloud SQL 備份
這個頁面會列出與 Google Cloud 專案相關聯的所有備份 (包括最終備份)。
按一下最終備份,其中包含要還原至其他執行個體的資料。
在「最終備份」 對話方塊中,按一下「還原」 。
在「Restore an instance from a backup」 頁面中,確認您在「Review backup details」 中選取了正確的備份。
在「Choose restore destination」(選擇還原目的地) 中,選取「Overwrite an existing instance」(覆寫現有執行個體) 。
在「要覆寫的執行個體」 選單中,選取要用於還原作業的執行個體。所選執行個體及其所有資料都會遭到覆寫。
注意: 您只能選取與用於建立最終備份 (來源執行個體) 的執行個體相同資料庫類型的執行個體。此外,所選執行個體的版本必須與來源執行個體相同或更新。
如要確認您的選項,請在「Destination instance ID」 欄位中輸入要覆寫的執行個體名稱。
如要開始還原程序,請按一下「還原」 。
如要查看還原作業的狀態,請前往執行個體的「Operations」 頁面。
還原作業完成後,請重建您在此程序中刪除的所有副本。
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
值。注意: 請選取狀態為 SUCCESSFUL
的備份。
如要從備份還原目標執行個體,請使用 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": "[email protected] ",
"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": "[email protected] ",
"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": "[email protected] ",
"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": "[email protected] ",
"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.instances.create
權限,以及來源執行個體的 cloudsql.backupRuns.get
權限。這些權限包含在 Cloud SQL Admin
角色中。
警告 :還原程序會覆寫執行個體中的所有現有資料,包括先前的時間點復原 (PITR) 記錄。保留執行個體先前的隨選和自動備份。
如要將資料還原至其他專案中的執行個體,請按照下列步驟操作:
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": "[email protected] ",
"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": "[email protected] ",
"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": "[email protected] ",
"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": "[email protected] ",
"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
從保留的備份還原
您可以在下列情況下使用保留備份 :
將保留的備份還原至新的執行個體
將保留的備份還原至現有執行個體
還原至其他專案或區域的新執行個體或現有執行個體
由於您使用的是已刪除的執行個體保留備份來還原執行個體,因此也可以使用備份來建立具有已刪除執行個體設定的執行個體,並復原資料。
注意: 從保留備份建立的執行個體,其 IP 位址與保留備份的來源執行個體不同。如需還原執行個體的相關資訊,請參閱「執行還原作業的一般提示 」一文。 將保留的備份還原至新的執行個體
從保留備份建立新執行個體時,Cloud SQL 會使用保留備份所在執行個體的設定。
如要將資料從保留的備份還原至新執行個體,您必須具備 cloudsql.instances.create
權限。
主控台
前往 Google Cloud 控制台的「Cloud SQL 備份」 頁面。
前往 Cloud SQL 備份
按一下已刪除的執行個體名稱,該執行個體包含您要還原的備份。
找出要還原的備份名稱,然後按一下「還原」 。
在「Restore an instance from a backup」 頁面中,確認您在「Review backup details」 中選取了正確的備份。
在「選擇還原目的地」 中,選取「還原至新執行個體」 。
從「Region」 選單中,選取新執行個體的地區。
在「Instance ID」(執行個體 ID) 欄位中,輸入新執行個體的 ID。
按一下「還原」 。
Cloud SQL 會將備份還原至新的執行個體。如要查看還原作業的狀態,請前往執行個體的「Operations」(作業) 頁面。
gcloud
使用 gcloud sql backups list
找出要儲存至新執行個體的備份。
gcloud sql backups list
--project=PROJECT_ID
更改下列內容:
PROJECT_ID
: Google Cloud 專案的 ID。
找出要使用的備份,並記錄其 BACKUP_NAME
值。
如要還原至新的執行個體,請使用 gcloud sql backups restore
指令:
gcloud sql backups restore BACKUP_NAME
--restore-instance=TARGET_INSTANCE_NAME
更改下列內容:
REST v1 從指定的保留備份還原新的執行個體
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID :專案 ID
TARGET_INSTANCE_ID :目標執行個體 ID
BACKUP_ID :備份 ID
注意: restore_instance_settings: {}
程式碼行可讓 Cloud SQL 將資料從備份還原至新執行個體。
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": "[email protected] ",
"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 從指定的保留備份還原新的執行個體
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID :專案 ID
TARGET_INSTANCE_ID :目標執行個體 ID
BACKUP_ID :備份 ID
注意: restore_instance_settings: {}
程式碼行可讓 Cloud SQL 將資料從備份還原至新執行個體。
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": "[email protected] ",
"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 "
}
將保留的備份還原至現有執行個體
從保留備份還原資料至現有執行個體時,目標執行個體中的資料會更新為當初建立備份時的來源執行個體狀態。
警告 :還原程序會覆寫執行個體中的所有現有資料,包括先前的時間點復原 (PITR) 記錄。保留執行個體先前的隨選和自動備份。
主控台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如果目標執行個體有任何唯讀備用資源,請使用更多動作選單 刪除這些項目。您必須先刪除所有備用資源,才能將保留的備份還原至現有執行個體。
前往 Google Cloud 控制台的「Cloud SQL 備份」 頁面。
前往 Cloud SQL 備份
按一下已刪除的執行個體名稱,該執行個體包含您要還原的備份。
找出要還原的備份名稱,然後按一下「還原」 。
在「Restore an instance from a backup」 頁面中,確認您在「Review backup details」 中選取了正確的備份。
在「Choose restore destination」(選擇還原目的地) 中,選取「Overwrite an existing instance」(覆寫現有執行個體) 。
在「要覆寫的執行個體」 選單中,選取要用於還原作業的執行個體。所選執行個體及其所有資料都會遭到覆寫。
如要確認您的選項,請在「Destination instance ID」 欄位中輸入要覆寫的執行個體名稱。
按一下「還原」 。
Cloud SQL 會將備份還原至新的執行個體。如要查看還原作業的狀態,請前往執行個體的「Operations」(作業) 頁面。
還原作業完成後,您可以建立任何副本。
gcloud
使用 gcloud sql instances describe
指令判斷目標執行個體是否有任何唯讀備用資源:
gcloud sql instance describe TARGET_INSTANCE_NAME
更改下列內容:
TARGET_INSTANCE_NAME
:您要將備份還原至的目標執行個體名稱。
使用 gcloud sql instances delete
指令刪除目標執行個體的所有副本:
gcloud sql instance delete REPLICA_NAME
更改下列內容:
REPLICA_NAME
:要刪除的目標執行個體副本名稱。
您必須先刪除所有複本,才能還原至現有執行個體。
使用 gcloud sql backups list
找出要儲存至新執行個體的備份。
gcloud sql backups list
--project=PROJECT_ID
更改下列內容:
PROJECT_ID
: Google Cloud 專案的 ID。
找出要使用的備份,並記錄其 BACKUP_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/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/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": "[email protected] ",
"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。
使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /backups
如要傳送要求,請展開以下其中一個選項:
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"
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" | 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": "[email protected] ",
"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": "[email protected] ",
"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。
使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /backups
如要傳送要求,請展開以下其中一個選項:
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"
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" | 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": "[email protected] ",
"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 "
}
還原至其他專案中的執行個體
如要使用其他專案中的保留備份還原執行個體,您必須具備下列權限:
您只能使用 gcloud CLI 或 Cloud SQL API 將資料還原至其他專案。
gcloud
使用 gcloud sql backups list
找出要儲存至新執行個體的備份。
gcloud sql backups list
--project=PROJECT_ID
更改下列內容:
PROJECT_ID
: Google Cloud 專案的 ID。
找出要使用的備份,並記錄其 BACKUP_NAME
值。
如要還原至新的執行個體,請使用 gcloud sql backups restore
指令:
gcloud sql backups restore BACKUP_ID
--restore-instance=TARGET_INSTANCE_NAME
更改下列內容:
REST v1 如要取得保留備份的 backupID
,請執行下列指令:
使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /backups
如要傳送要求,請展開以下其中一個選項:
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"
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" | 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": "[email protected] ",
"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 如要取得保留備份的 backupID
,請執行下列指令:
使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /backups
如要傳送要求,請展開以下其中一個選項:
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"
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" | 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": "[email protected] ",
"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 "
}
還原至其他區域的執行個體
如要使用不同區域的保留備份還原執行個體,您必須具備下列權限:
您只能使用 gcloud CLI 或 Cloud SQL API 將資料還原至其他區域。目標區域必須符合該區域的機構政策 。
gcloud
使用 gcloud sql backups list
找出要儲存至新執行個體的備份。
gcloud sql backups list
--project=PROJECT_ID
更改下列內容:
PROJECT_ID
: Google Cloud 專案的 ID。
找出要使用的備份,並記錄其 NAME
值。
如要還原至新的執行個體,請使用 gcloud sql backups restore
指令:
gcloud sql backups restore BACKUP_ID
-- restore - instance = TARGET_INSTANCE_NAME
-- region = TARGET_REGION
更改下列內容:
REST v1 如要取得保留備份的 backupID
,請執行下列指令:
使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /backups
如要傳送要求,請展開以下其中一個選項:
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"
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" | 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": "[email protected] ",
"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 如要取得保留備份的 backupID
,請執行下列指令:
使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /backups
如要傳送要求,請展開以下其中一個選項:
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"
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" | 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": "[email protected] ",
"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 "
}
執行時間點復原
如要執行時間點復原,請參閱「時間點復原 」。
後續步驟