提供意見
建立及管理隨選和自動備份
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁面說明如何為 Cloud SQL 執行個體排定自動備份時程與停用自動備份、建立及管理隨選備份,以及查看備份。
如想深入瞭解備份的運作方式,請參閱備份總覽 一文。
建立按照需求執行的備份
建立隨選備份:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Backups」 。
按一下「Create backup」(建立備份) 。
在「Create backup」(建立備份) 頁面上,視需要新增說明並點選「Create」(建立) 。
gcloud
建立備份:
gcloud sql backups create \
--async \
--instance= INSTANCE_NAME
您可以使用 --description
參數提供備份的說明。
如要在自訂位置建立備份,請按照下列步驟操作:
gcloud sql backups create \
--async \
--instance= INSTANCE_NAME \
--location= BACKUP_LOCATION
REST v1
使用任何要求資料之前,請先替換以下項目:
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /backupRuns
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /backupRuns"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /backupRuns" | 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": "BACKUP_VOLUME",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
REST v1beta4
使用任何要求資料之前,請先替換以下項目:
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /backupRuns
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /backupRuns"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /backupRuns" | 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": "BACKUP_VOLUME",
"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 導覽選單中選取「Backups」 。
按一下「設定」旁的「編輯」 。
選擇自動備份資料的時間範圍。
按一下 [儲存] 。
gcloud
編輯執行個體,指定備份開始時間:
gcloud sql instances patch INSTANCE_NAME --backup-start-time= HH:MM
backup-start-time
參數會以 24 小時制指定在 UTC±00 時區中,並指定 4 小時備份時間的開始。備份可於備份期間的任何時間開始。
確認變更:
gcloud sql instances describe INSTANCE_NAME
在 backupConfiguration
部分中,確認您看到 enabled: true
和指定的時間。
如要為資料庫建立備份,請使用 Terraform 資源 。
套用變更
如要在 Google Cloud 專案中套用 Terraform 設定,請完成下列各節中的步驟。
準備 Cloud Shell
啟動 Cloud Shell 。
設定要套用 Terraform 設定的預設 Google Cloud 專案。
您只需為每個專案執行這個指令一次,而且可以在任何目錄中執行。
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
如果您在 Terraform 設定檔中設定明確的值,系統就會覆寫環境變數。
準備目錄
每個 Terraform 設定檔都必須有自己的目錄 (也稱為根模組 )。
在 Cloud Shell 中建立目錄,並在該目錄中建立新檔案。檔案名稱必須包含 .tf
副檔名,例如 main.tf
。在本教學課程中,檔案稱為 main.tf
。
mkdir DIRECTORY && cd DIRECTORY && touch main.tf
如果您正在參考教學課程,可以複製各個章節或步驟中的程式碼範例。
將範例程式碼複製到新建立的 main.tf
中。
您可以視需要從 GitHub 複製程式碼。如果 Terraform 程式碼片段是端對端解決方案的一部分,建議您採用這種做法。
查看並修改要套用至環境的範例參數。
儲存變更。
初始化 Terraform。這項操作只需對每個目錄執行一次。
terraform init
如要使用最新版的 Google 供應器,請視需要加入 -upgrade
選項:
terraform init -upgrade
套用變更
檢查設定,並確認 Terraform 要建立或更新的資源是否符合您的預期:
terraform plan
視需要修正設定。
執行下列指令,並在提示中輸入 yes
,即可套用 Terraform 設定:
terraform apply
等待 Terraform 顯示「Apply complete!」(套用完成) 訊息。
開啟 Google Cloud 專案 即可查看結果。在 Google Cloud 控制台中,前往 UI 中的資源,確認 Terraform 已建立或更新這些資源。
注意: Terraform 範例通常會假設您已在 Google Cloud 專案中啟用必要的 API。
刪除變更
如要刪除變更,請按照下列步驟操作:
如要停用防刪除功能,請在 Terraform 設定檔中將 deletion_protection
引數設為 false
。
deletion_protection = "false"
執行下列指令,並在提示中輸入 yes
,即可套用更新的 Terraform 設定:
terraform apply
如要移除先前透過 Terraform 設定套用的資源,請執行下列指令,並在提示中輸入 yes
:
terraform destroy
REST v1
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID :包含執行個體的 Google Cloud 專案 ID 或專案編號
INSTANCE_NAME :您為高可用性設定的主執行個體或讀取備用資源執行個體的名稱
START_TIME :時間 (以小時和分鐘為單位)
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME
JSON 要求主體:
{
"settings":
{
"backupConfiguration":
{
"startTime": "START_TIME ",
"enabled": true,
"binaryLogEnabled": true
}
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME ",
"status": "PENDING",
"user": "[email protected] ",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_NAME ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
您可以同時啟用二進位檔記錄,方法是在 backupConfiguration
物件中將 pointInTimeEnabled
設為 true
。
REST v1beta4
您可以同時啟用二進位檔記錄,方法是在 backupConfiguration
物件中將 binaryLogEnabled
設為 true
。
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID :包含執行個體的 Google Cloud 專案 ID 或專案編號
INSTANCE_NAME :您為高可用性設定的主執行個體或讀取備用資源執行個體的名稱
START_TIME :時間 (以小時和分鐘為單位)
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID /instances/INSTANCE_NAME
JSON 要求主體:
{
"settings":
{
"backupConfiguration":
{
"startTime": "START_TIME ",
"enabled": true,
"binaryLogEnabled": true
}
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID /instances/INSTANCE_NAME "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID /instances/INSTANCE_NAME " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID /instances/INSTANCE_NAME ",
"status": "PENDING",
"user": "[email protected] ",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_NAME ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
注意: 如果在自動備份作業的排定開始時間,有即時備份作業正在進行,系統會將自動備份作業的時間重新排定為稍後時間。
設定自訂備份位置
只有在法規要求的情況下,才使用自訂備份位置。如果不需要,請使用預設的多地區備份位置。
您可以使用自訂位置來建立隨選備份和自動備份。如需有效位置值的完整清單,請參閱「執行個體位置 」。
注意: 如果您變更備份的儲存位置,現有的備份會保留在原始位置。
注意: 如果備份位於機構政策禁止的地區,備份作業就會失敗。無論機構政策或其他限制為何,只要執行個體與備份所在區域相同,備份作業一律會成功。
如要更新自訂位置的執行個體,請按照下列步驟操作:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中,選取「Backups」(備份) 。
按一下「設定」 旁的「編輯」 。
在「自動備份」 部分,展開「進階選項」 。
按一下「多區域 (預設)」 或「區域」 。
從「位置」 下拉式選單中選取位置。
按一下 [儲存] 。
REST v1
使用執行個體的
settings.backupConfiguration.location
參數做為備份位置。
使用任何要求資料之前,請先替換以下項目:
region :專案區域
backup-region :備份區域
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id
JSON 要求主體:
{
"region": "region "
"settings":
{
"backupConfiguration":
{
"location": "backup-region ",
"enabled": true,
}
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id " | 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": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
REST v1beta4
使用執行個體的
settings.backupConfiguration.location
參數做為備份位置。
使用任何要求資料之前,請先替換以下項目:
region :專案區域
backup-region :備份區域
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id
JSON 要求主體:
{
"region": "region "
"settings":
{
"backupConfiguration":
{
"location": "backup-region ",
"enabled": true,
}
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id " | 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": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
查看備份清單
如要查看備份清單和備份詳細資料,請使用下列選項。
Google Cloud 控制台不會在備份記錄中顯示略過或失敗的備份。如要查看略過的備份,請使用 gcloud
或 API。
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
從 SQL 導覽選單中選取「Backups」 ,即可查看最近的備份、建立時間和備份類型。
REST v1
您也可以使用
BackupRuns:list 頁面上的 APIs Explorer 傳送 REST API 要求。
使用任何要求資料之前,請先替換以下項目:
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"
}
REST v1beta4
您也可以使用
BackupRuns:list 頁面上的 APIs Explorer 傳送 REST API 要求。
使用任何要求資料之前,請先替換以下項目:
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"
}
在服務中斷期間查看備份清單
如果執行個體位於發生服務中斷的地區,您只能使用 backupRuns.list
API 的萬用字元 (-
) 查看該執行個體的備份。萬用字元會傳回專案中的所有備份。請參閱「還原為不同執行個體 」。
如果執行個體所在的地區發生停機,且已啟用客戶管理的加密金鑰 (CMEK),您就無法將該執行個體的備份還原到其他地區。這是因為在啟用 CMEK 後,Cloud SQL 會使用區域 Cloud KMS 金鑰 進行加密。如要還原 CMEK 執行個體的備份,Cloud SQL 必須能存取 CMEK 金鑰。在區域服務中斷時,您將無法存取該區域的 Cloud KMS 金鑰。
gcloud
列出專案中每個執行個體的備份:
gcloud sql backups list --instance -
指令會傳回類似以下的資訊:
{
"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"
}
找出所需執行個體的備份。如要還原這個備份,請參閱「還原為不同執行個體 」。
REST v1
列出專案中的所有備份:
使用任何要求資料之前,請先替換以下項目:
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"
}
找出所需執行個體的備份。如要還原這個備份,請參閱「還原為不同執行個體 」。
REST v1beta4
列出專案中的所有備份:
使用任何要求資料之前,請先替換以下項目:
project-id :專案 ID
instance-id :例項 ID,或 -
(專案中的所有備份清單)
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1beta4/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/v1beta4/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/v1beta4/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/v1beta4/projects/project-id /instances/instance-id /backupRuns/backup-id ",
"location": "us"
"backupKind": "SNAPSHOT"
}
找出所需執行個體的備份。如要還原這個備份,請參閱「還原為不同執行個體 」。
查看備份位置
如要查看執行個體使用的備份位置,請使用 backupRuns
:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Backups」 。
在備份清單中,「Location」 欄會列出位置類型 (多區域或區域),以及每個備份的特定多區域或區域。
gcloud
如需參考資訊,請參閱 gcloud sql instances describe 。
列出執行個體的備份:
gcloud sql backups list \
--instance INSTANCE_NAME
您可以使用標準清單參數篩選及控制結果。
如需完整清單,請參閱 gcloud sql backups list 指令參考頁面。
如要列出單一備份的詳細資料,請使用 backups list
指令輸出的 ID
。
gcloud sql backups describe BACKUP_ID \
--instance INSTANCE_NAME
REST v1
使用任何要求資料之前,請先替換以下項目:
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 回應:
REGION
是原始執行個體的所在地區。
BACKUP_LOCATION
是您要 Cloud SQL 儲存備份的位置。
REST v1beta4
使用任何要求資料之前,請先替換以下項目:
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 回應:
REGION
是原始執行個體的所在地區。
BACKUP_LOCATION
是您要 Cloud SQL 儲存備份的位置。
查看備份大小
您可以使用 gcloud CLI 或 API 查看 Cloud SQL 執行個體的備份大小。
gcloud
如要取得與 Google Cloud 專案相關聯的所有備份清單,請使用 gcloud sql backups list
指令:
gcloud sql backups list
注意 :您可以使用這個指令擷取備份相關資訊,包括 ID。您必須提供備份 ID,才能查看備份大小。
此外,您也可以使用標準清單參數篩選及控制執行此指令的結果。如需完整清單,請參閱 gcloud sql backups list 指令參考資料頁面。
如要查看備份的大小,請使用 gcloud sql backups describe
指令:
gcloud sql backups describe BACKUP_ID \
--instance= INSTANCE_NAME \
--project= PROJECT_ID
請將以下項目改為對應的值:
BACKUP_ID :備份的 ID。您可以從執行 gcloud sql backups list
指令的輸出內容取得這個 ID。
INSTANCE_NAME :執行個體的名稱。
PROJECT_ID :包含執行個體的 Google Cloud 專案 ID 或專案編號 。
在輸出結果中,maxChargeableBytes
參數會顯示備份的大小 (以位元組為單位)。
REST
取得備份清單
您可以使用這個範例,取得與 Google Cloud 專案相關聯的所有備份清單。如需此呼叫的完整參數清單,請參閱 backupRuns.list 頁面。
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID :包含執行個體的 Google Cloud 專案 ID 或專案編號
INSTANCE_NAME :執行個體名稱
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME /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_NAME /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_NAME /backupRuns" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"name": "projects/PROJECT_ID /instances/INSTANCE_NAME /backupRuns",
"kind": "sql#backupRun",
"enqueuedTime": "2024-04-24T22:16:02.208Z",
"id": "INSTANCE_ID ",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/instances/INSTANCE_NAME /backupRuns",
"location": "us",
"description": "get a list of backups",
"instance": "INSTANCE_NAME "
}
查看備份詳細資料
您可以使用這個範例查看備份的詳細資料,包括備份大小。如需此呼叫的完整參數清單,請參閱 backupRuns.get 頁面。
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID :包含執行個體的 Google Cloud 專案 ID 或專案編號 。
INSTANCE_NAME :執行個體的名稱。
BACKUP_ID :備份 ID。您可以從執行上一個呼叫的輸出內容取得這個 ID。
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME /backupRuns/BACKUP_ID
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME /backupRuns/BACKUP_ID "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_NAME /backupRuns/BACKUP_ID " | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"name": "projects/PROJECT_ID /instances/INSTANCE_NAME /backupRuns/BACKUP_ID ",
"kind": "sql#backupRun",
"enqueuedTime": "2024-04-24T22:16:02.208Z",
"id": "INSTANCE_ID ",
"startTime": "2020-01-21T11:25:33.858Z",
"endTime": "2020-01-21T11:26:18.663Z",
"type": "AUTOMATED",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/instances/INSTANCE_NAME /backupRuns/BACKUP_ID ",
"location": "us",
"description": "view details about a backup",
"maxChargeableBytes": "BYTE_NUMBER ",
"instance": "INSTANCE_NAME "
}
設定自動備份保留期限
如要設定要保留的自動備份數量,請按照下列步驟操作:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Backups」 。
按一下 [編輯] 。
在「自動備份」 區段中,展開「進階選項」 。
輸入一次儲存的備份數量 。
按一下 [儲存] 。
gcloud
編輯執行個體,設定要保留的自動備份數量。
這個數字不得少於預設值 (七)。
gcloud sql instances patch INSTANCE_NAME \
--retained-backups-count= NUM_TO_RETAIN
REST v1beta4
使用任何要求資料之前,請先替換以下項目:
unit :選用:保留時間單位可以是整數或字串。目前支援的 (預設) 值為 1 或「COUNT」。
num-to-retain :要保留的自動備份數量,範圍為 1 到 365。
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"backupConfiguration":
{
"backupRetentionSettings":
{
"retentionUnit": unit ,
"retainedBackups": "num-to-retain "
}
}
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id " | 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": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
刪除備份
您可以刪除自動及隨選備份。
針對 MySQL 執行個體,刪除備份所釋放的空間可能無法達到備份的大小。這是因為備份是以增量方式備份,因此刪除較舊備份可能會將其部分內容轉移到更近的備份,以保留較新備份的完整性。
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Backups」 。
對您要刪除的備份,按一下更多動作圖示 。
選取 [刪除] 。
在「Delete backup」(刪除備份) 視窗中,將 Delete
輸入到欄位中,然後按一下「Delete」(刪除) 。
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 方法和網址:
DELETE https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /backupRuns/backup-id
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /backupRuns/backup-id "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method DELETE ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /backupRuns/backup-id " | 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": "DELETE_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-id :備份 ID
HTTP 方法和網址:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /backupRuns/backup-id
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /backupRuns/backup-id "
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method DELETE ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /backupRuns/backup-id " | 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": "DELETE_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 導覽選單中選取「Backups」 。
按一下「管理自動備份」
取消勾選「自動備份」 。
按一下「儲存並重新啟動」 。
gcloud
編輯執行個體以停用備份:
gcloud sql instances patch INSTANCE_NAME \
--no-backup
REST v1
使用任何要求資料之前,請先替換以下項目:
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"backupConfiguration":
{
"enabled": false,
"binaryLogEnabled": false
}
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id " | 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": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
REST v1beta4
使用任何要求資料之前,請先替換以下項目:
project-id :專案 ID
instance-id :執行個體 ID
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id
JSON 要求主體:
{
"settings":
{
"backupConfiguration":
{
"enabled": false,
"binaryLogEnabled": false
}
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id "
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id " | 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": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
時間點復原
進一步瞭解時間點復原功能 。
後續步驟
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-05-16 (世界標準時間)。
想進一步說明嗎?
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-05-16 (世界標準時間)。"],[],[]]