使用 Cloud Storage 備份及還原檔案

本頁面說明如何使用 Cloud Storage 備份及還原 Vertex AI Workbench 執行個體上的檔案。

總覽

本指南說明如何透過兩種方式使用 Cloud Storage,協助您備份及還原 Vertex AI Workbench 執行個體上的檔案:

事前準備

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Notebooks API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Notebooks API.

    Enable the API

  8. 必要的角色

    如要取得將 Cloud Storage 值區掛接至 Vertex AI Workbench 執行個體所需的權限,請要求管理員授予您專案的下列 IAM 角色:

    如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

    您或許還可透過自訂角色或其他預先定義的角色取得必要權限。

    掛接 Cloud Storage bucket

    Vertex AI Workbench 執行個體包含 Cloud Storage 整合功能,可讓您掛接 Cloud Storage 值區。也就是說,您可以在 JupyterLab 介面中瀏覽 bucket 內容,並使用相容的檔案。

    在與 Vertex AI Workbench 執行個體相同的專案中,您可以存取執行個體有權存取的任何 Cloud Storage 值區和檔案。

    啟用共用儲存空間掛接功能所需的權限

    如要在 Vertex AI Workbench 執行個體中啟用共用儲存空間掛接功能,請要求管理員授予 Vertex AI Workbench 執行個體服務帳戶專案的 storage.buckets.list 權限。

    您必須具備 storage.buckets.list 權限,Vertex AI Workbench 執行個體的 JupyterLab 介面才會顯示「掛接共用儲存空間」按鈕。

    建立 bucket 和 Vertex AI Workbench 執行個體

    您必須有權存取與 Vertex AI Workbench 執行個體位於同一專案中的至少一個 Cloud Storage bucket。
    1. 如需建立 Cloud Storage bucket,請參閱「建立 bucket」。
    2. 如果尚未建立,請在與 Cloud Storage 值區相同的專案中建立 Vertex AI Workbench 執行個體

    開啟 JupyterLab

    1. 前往 Google Cloud 控制台的「Instances」(執行個體) 頁面。

      前往「Instances」(執行個體) 頁面

    2. 按一下 Vertex AI Workbench 執行個體名稱旁的「Open JupyterLab」(開啟 JupyterLab)

      Vertex AI Workbench 執行個體會開啟 JupyterLab。

    掛接 Cloud Storage bucket

    如要掛接並存取 Cloud Storage bucket,請按照下列步驟操作:

    1. 在 JupyterLab 中,確認已選取「File Browser」(檔案瀏覽器)  分頁標籤。

    2. 按一下左側邊欄中的「掛接共用儲存空間」按鈕。如果沒有看到這個按鈕,請拖曳側欄右側,展開側欄,直到看到這個按鈕為止。

      左側邊欄右上角的「掛接共用儲存空間」按鈕

    3. 在「Bucket name」(值區名稱) 欄位中,輸入要掛接的 Cloud Storage 值區名稱。

    4. 按一下「掛接」

    5. Cloud Storage bucket 會以資料夾的形式顯示在左側邊欄的「檔案瀏覽器」分頁中。按兩下資料夾,開啟並瀏覽內容。

    匯出至 Cloud Storage 及從中還原檔案

    本節說明如何將檔案匯出至 Cloud Storage,以及如何還原 Cloud Storage 值區中的檔案。

    匯出至 Cloud Storage

    1. 前往 Google Cloud 控制台的「Instances」(執行個體) 頁面。

      前往「Instances」(執行個體) 頁面

    2. 按一下 Vertex AI Workbench 執行個體名稱旁的「Open JupyterLab」(開啟 JupyterLab)

      Vertex AI Workbench 執行個體會開啟 JupyterLab。

    3. 在 JupyterLab 中,確認已選取「File Browser」(檔案瀏覽器)  分頁標籤。

    4. 按一下左側邊欄中的「匯出至 GCS」按鈕。如果沒有看到這個按鈕,請拖曳側欄右側,展開側欄,直到看到這個按鈕為止。

    5. 在「Provide export location」(提供匯出位置) 對話方塊中,輸入要匯出檔案的 Cloud Storage bucket 名稱。如需建立 Cloud Storage bucket,請參閱「建立 bucket」。

      Vertex AI Workbench 會開啟新筆記本,其中包含將執行個體檔案匯出至 Cloud Storage 的程式碼。

    6. 執行這個儲存格中的程式碼。

    從 Cloud Storage 還原檔案

    如要將檔案還原至 Vertex AI Workbench 執行個體,可以使用 gcloud storage cp 複製檔案。

    在其中一個執行個體筆記本的儲存格中執行下列程式碼:

    !gcloud storage cp URI /home/jupyter/FILE_NAME

    更改下列內容:

    • URI:要複製的檔案的 gsutil URI,例如:gs://BUCKET_NAME/ZONE/INSTANCE_ID/FILE_NAME
    • FILE_NAME:要複製的檔案名稱

    詳情請參閱「從 bucket 下載物件」。

    後續步驟