GCP

Restoring from a GCP CloudSQL MySQL snapshot

misankim 2023. 5. 12. 23:50

Restoring from a GCP CloudSQL MySQL snapshot

 

 

https://cloud.google.com/sql/docs/postgres/backup-recovery/restoring?hl=ko

 

 

# Check backup id

curl -X GET \
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
"https://sqladmin.googleapis.com/v1/projects/my-project-a/instances/premisan-test/backupRuns"

 

 

Output

{
  "kind": "sql#backupRunsList",
  "items": [
    {
      "kind": "sql#backupRun",
      "status": "SUCCESSFUL",
      "enqueuedTime": "2022-09-21T14:53:31.940Z",
      "id": "1234123400000",
      "startTime": "2022-09-21T14:53:31.962Z",
      "endTime": "2022-09-21T14:54:12.634Z",
      "type": "AUTOMATED",
      "windowStartTime": "2022-09-21T14:00:00Z",
      "instance": "premisan-test",
      "selfLink": "https://sqladmin.googleapis.com/v1/projects/my-project-a/instances/premisan-test/backupRuns/1234123400000",
      "location": "asia-northeast3",
      "backupKind": "SNAPSHOT"
    },
    ...
}

 

 

# Restore from a snapshot of another project

-> When restoring from a snapshot, both user information and db information are restored.

 

vim request.json

{
  "restoreBackupContext":
  {
    "backupRunId": 1234123400000,
    "project": "my-project-a",
    "instanceId": "premisan-test"
  }
}

 

 

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/my-project-b/instances/premisan-test-new/restoreBackup"

 

 

Output

{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/my-project-b/instances/premisan-test-new",
  "status": "PENDING",
  "user": "test@example.com",
  "insertTime": "2022-09-21T15:25:48.922Z",
  "operationType": "RESTORE_VOLUME",
  "name": "a4a9ca68-1234-1234-1234-464700000042",
  "targetId": "premisan-test-new",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/my-project-b/operations/a4a9ca68-1234-1234-1234-464700000042",
  "targetProject": "my-project-b"
}