管理轉移作業

本頁面說明如何管理現有的移轉工作和作業。

如要建立新的轉移工作,請參閱「建立轉移」一文。

編輯轉移設定

您可以編輯現有轉移作業的下列屬性:

  • 轉移工作的說明
  • Microsoft Azure Blob 儲存體或 Amazon S3 來源憑證
  • 套用至移轉工作的任何篩選器
  • 覆寫或刪除檔案的選項
  • 轉移工作的排程

gcloud CLI

如要編輯現有的轉移設定,請使用 gcloud transfer jobs update 指令。

gcloud transfer jobs update \
  JOB_NAME \
  [options]

其中:

  • JOB_NAME 是需要更新的工作的專屬名稱。

  • 執行 gcloud transfer jobs update --help 即可列出可更新的選項。

舉例來說,如要更新工作來源和目的地,並移除工作說明,請執行下列指令:

gcloud transfer jobs update \
  JOB_NAME \
  --source=gs://new-bucket-1 \
  --destination=gs://new-bucket-2 \
  --clear-description

Google Cloud 控制台

如要編輯移轉工作,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Storage Transfer Service」頁面。

    前往 Storage 移轉服務

  2. 按一下轉移工作的說明。系統隨即會顯示「工作詳細資料」頁面。

  3. 按一下「設定」。系統會顯示移轉工作設定。

  4. 如要變更項目,請按一下項目旁邊的 「編輯」

  5. 如要啟動含有編輯內容的工作,請按一下「啟動執行作業」

REST

如要編輯轉移設定,請使用 transferJobs.patch 方法。

從現有設定執行移轉工作

您可以執行現有的轉移工作。這麼做可讓您啟動沒有排程的工作,或在排程以外的時間啟動工作。

gcloud CLI

如要從現有設定執行移轉作業,請使用 gcloud transfer jobs run

gcloud transfer jobs run JOB_NAME

您可以指定選用的 --no-async 標記,在轉移作業完成前,阻擋終端機中的其他工作。

Google Cloud 控制台

如要從現有設定執行轉移作業,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Storage Transfer Service」頁面。

    前往 Storage 移轉服務

  2. 按一下轉移工作的說明。系統隨即會顯示「工作詳細資料」頁面。

  3. 如要啟動移轉工作,請按一下「啟動執行作業」

REST

如要執行轉移工作,請使用 transferJobs.run 方法。

監控移轉工作

gcloud CLI

如要即時監控工作進度,請使用 gcloud transfer jobs monitor

gcloud transfer jobs monitor JOB_NAME

回應會顯示目前作業、工作開始時間和傳輸的資料量。系統也會計算略過的位元組和錯誤。

Cloud Monitoring

如要進一步瞭解如何搭配使用 Cloud Monitoring 和 Storage 移轉服務,請參閱「監控移轉工作」。

查看轉移工作詳細資料

gcloud CLI

如要查看轉移工作詳細資料,請使用 gcloud transfer jobs describe

gcloud transfer jobs describe JOB_NAME

如要查看這項工作的最新作業,請將 latestOperationName 的值傳遞至 operations describe 指令:

gcloud transfer operations describe OPERATION_NAME

如要列出工作所有移轉作業,請使用 gcloud transfer operations list 指令:

gcloud transfer operations list --job-names=JOB_NAME

您可以將多個作業的運算列為 --job-names 的值,並以半形逗號分隔,省略 --job-names 即可查看所有工作的作業。

Google Cloud 控制台

您可以在 Google Cloud 控制台中查看下列工作詳細資料:

  • 職務說明和名稱
  • 來源類型和位置
  • 目的地位置
  • 工作頻率
  • 工作統計資料

如要查看轉移工作詳細資料,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Storage Transfer Service」頁面。

    前往 Storage 移轉服務

  2. 按一下轉移工作的說明。系統隨即會顯示「工作詳細資料」頁面。

如要顯示特定執行作業的詳細資料,請按一下工作執行作業的「開始時間」。您可以查看下列工作資訊:

  • 移轉狀態
  • 開始和結束時間
  • 時間長度
  • 進度
  • 已轉移的資料量
  • 錯誤數
  • 已略過的資料量
  • 預估平均速度

REST

如要查看轉移工作的詳細資料,請使用 transferJobs.get 方法,傳回特定轉移工作的相關資訊,例如作業 ID。

用戶端程式庫

使用 transferJobs.create 時,系統會傳回 TransferJob 資源。

您可以使用 transferJobs.get 建立工作後,查看轉移作業的狀態。如果移轉工作已開始,這項作業會傳回包含已填入資料的 TransferJob latestOperationName 欄位。否則,如果轉移工作未開始,latestOperationName 欄位會是空白。

如何查看轉移工作的狀態

REST

使用 transferJobs get 的要求:
GET https://storagetransfer.googleapis.com/v1/{jobName="name"}

Go

import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/longrunning/autogen/longrunningpb"
	storagetransfer "cloud.google.com/go/storagetransfer/apiv1"
	"cloud.google.com/go/storagetransfer/apiv1/storagetransferpb"
)

func checkLatestTransferOperation(w io.Writer, projectID string, jobName string) (*storagetransferpb.TransferOperation, error) {
	// Your Google Cloud Project ID
	// projectID := "my-project-id"

	// The name of the job whose latest operation to check
	// jobName := "transferJobs/1234567890"
	ctx := context.Background()
	client, err := storagetransfer.NewClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("storagetransfer.NewClient: %w", err)
	}
	defer client.Close()

	job, err := client.GetTransferJob(ctx, &storagetransferpb.GetTransferJobRequest{
		JobName:   jobName,
		ProjectId: projectID,
	})
	if err != nil {
		return nil, fmt.Errorf("failed to get transfer job: %w", err)
	}

	latestOpName := job.LatestOperationName
	if latestOpName != "" {
		lro, err := client.LROClient.GetOperation(ctx, &longrunningpb.GetOperationRequest{
			Name: latestOpName,
		})
		if err != nil {
			return nil, fmt.Errorf("failed to get transfer operation: %w", err)
		}
		latestOp := &storagetransferpb.TransferOperation{}
		lro.Metadata.UnmarshalTo(latestOp)

		fmt.Fprintf(w, "the latest transfer operation for job %q is: \n%v", jobName, latestOp)
		return latestOp, nil
	} else {
		fmt.Fprintf(w, "Transfer job %q hasn't run yet, try again later", jobName)
		return nil, nil
	}
}

Java

想查看較舊的範例嗎?請參閱 Storage 移轉服務遷移指南


import com.google.longrunning.Operation;
import com.google.storagetransfer.v1.proto.StorageTransferServiceClient;
import com.google.storagetransfer.v1.proto.TransferProto.GetTransferJobRequest;
import com.google.storagetransfer.v1.proto.TransferTypes.TransferJob;
import com.google.storagetransfer.v1.proto.TransferTypes.TransferOperation;
import java.io.IOException;

public class CheckLatestTransferOperation {

  // Gets the requested transfer job and checks its latest operation
  public static void checkLatestTransferOperation(String projectId, String jobName)
      throws IOException {
    // Your Google Cloud Project ID
    // String projectId = "your-project-id";

    // The name of the job to check
    // String jobName = "myJob/1234567890";

    StorageTransferServiceClient storageTransfer = StorageTransferServiceClient.create();

    // Get transfer job and check latest operation
    TransferJob transferJob =
        storageTransfer.getTransferJob(
            GetTransferJobRequest.newBuilder().setJobName(jobName).setProjectId(projectId).build());
    String latestOperationName = transferJob.getLatestOperationName();

    if (!latestOperationName.isEmpty()) {
      Operation operation = storageTransfer.getOperationsClient().getOperation(latestOperationName);
      TransferOperation latestOperation =
          TransferOperation.parseFrom(operation.getMetadata().getValue());

      System.out.println("The latest operation for transfer job " + jobName + " is:");
      System.out.println(latestOperation.toString());

    } else {
      System.out.println(
          "Transfer job "
              + jobName
              + " hasn't run yet,"
              + " try again once the job starts running.");
    }
  }
}

Node.js


// Imports the Google Cloud client library
const {
  StorageTransferServiceClient,
} = require('@google-cloud/storage-transfer');

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of the Google Cloud Platform Project that owns the job
// projectId = 'my-project-id'

// Storage Transfer Service job name
// jobName = 'transferJobs/1234567890'

// Creates a client
const client = new StorageTransferServiceClient();

/**
 * Checks the latest transfer operation for a given transfer job.
 */
async function checkLatestTransferOperation() {
  const [transferJob] = await client.getTransferJob({projectId, jobName});

  if (transferJob.latestOperationName) {
    const [transferOperation] = await client.operationsClient.getOperation({
      name: transferJob.latestOperationName,
    });

    const operation = JSON.stringify(transferOperation, null, 2);

    console.log(`Latest transfer operation for '${jobName}': ${operation}`);
  } else {
    console.log(`Transfer job '${jobName}' has not ran yet.`);
  }
}

checkLatestTransferOperation();

Python

想查看較舊的範例嗎?請參閱 Storage 移轉服務遷移指南

from google.cloud import storage_transfer


def check_latest_transfer_operation(project_id: str, job_name: str):
    """Checks the latest transfer operation for a given transfer job."""

    client = storage_transfer.StorageTransferServiceClient()

    # The ID of the Google Cloud Platform Project that owns the job
    # project_id = 'my-project-id'

    # Storage Transfer Service job name
    # job_name = 'transferJobs/1234567890'

    transfer_job = client.get_transfer_job(
        {
            "project_id": project_id,
            "job_name": job_name,
        }
    )

    if transfer_job.latest_operation_name:
        response = client.transport.operations_client.get_operation(
            transfer_job.latest_operation_name
        )
        operation = storage_transfer.TransferOperation.deserialize(
            response.metadata.value
        )

        print(f"Latest transfer operation for `{job_name}`: {operation}")
    else:
        print(f"Transfer job {job_name} has not ran yet.")

暫停移轉工作

您可以暫停目前進行中的轉移作業。暫停轉移作業後,系統會維持工作狀態,您之後可以再取消暫停。在移轉作業暫停期間,排程不會再次觸發工作。

gcloud CLI

如要暫停移轉工作,請將工作目前的作業名稱傳遞至 gcloud transfer operations pause

gcloud transfer operations pause OPERATION_NAME

如要繼續先前暫停的轉移作業,請使用 gcloud transfer operations resume,這樣系統就會在暫停時的位置重新啟動作業。

gcloud transfer operations resume OPERATION_NAME

Google Cloud 控制台

如要暫停轉移作業,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Storage Transfer Service」頁面。

    前往 Storage 移轉服務

  2. 按一下轉移工作的說明。系統隨即會顯示「工作詳細資料」頁面。

  3. 按一下「暫停執行」。目前作業的狀態會顯示為「已暫停」

如要繼續先前暫停的轉移工作,請按照下列步驟操作,在暫停時的工作位置重新啟動工作。

  1. 前往 Google Cloud 控制台的「Storage Transfer Service」頁面。

    前往 Storage 移轉服務

  2. 按一下轉移工作的說明。系統隨即會顯示「工作詳細資料」頁面。

  3. 按一下「繼續執行」

    目前作業的狀態會顯示為「進行中」

REST

如要暫停轉移工作,請使用 transferOperations.pause 方法。

停用轉移工作

停用移轉工作後,移轉工作就不會再啟動任何已排定的作業,或是從控制台手動啟動的作業。但這不會防止使用 API 或 jobs run gcloud 指令手動啟動工作。

gcloud CLI

如要停用轉移工作,請將工作狀態更新為 disabled

gcloud transfer jobs update JOB_NAME --status=disabled

如要重新啟用工作,請設定 --status=enabled

Google Cloud 控制台

如要停用轉移工作,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Storage Transfer Service」頁面。

    前往 Storage 移轉服務

  2. 按一下轉移工作的說明。系統隨即會顯示「工作詳細資料」頁面。

  3. 按一下「停用工作」。系統會顯示「Disable transfer job?」對話方塊。

  4. 閱讀對話方塊,然後按一下「確認」,確認工作已停用。

    「Job details」頁面頂端會顯示通知,提醒您工作已停用。

REST

使用 transferJobs.patch 方法,將轉移工作的狀態設為 DISABLED

刪除轉移工作

您可以刪除不再需要的移轉工作。刪除工作會執行以下操作:

  • 停止工作中所有現有的轉移作業。
  • 停止工作中任何週期性轉移作業。
  • 清除工作的設定詳細資料。

工作一經刪除即無法復原。刪除移轉工作後,系統會將該工作從移轉工作清單中移除。轉移工作資訊會在 30 天後從儲存空間轉移服務中徹底刪除。

或者,您也可以停用移轉工作,這樣該工作就會列在「工作」頁面中,您也可以重新啟用或修改該工作。

gcloud CLI

如要刪除轉移工作,請使用 gcloud transfer jobs delete

gcloud transfer jobs delete JOB_NAME

Google Cloud 控制台

如要刪除轉移作業,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Storage Transfer Service」頁面。

    前往 Storage 移轉服務

  2. 找出要刪除的移轉工作,然後選取旁邊的核取方塊。

  3. 按一下「刪除工作」

    系統會顯示「Delete transfer job?」對話方塊。

  4. 閱讀對話方塊,然後在欄位中輸入工作自動指派的名稱,然後按一下「Delete」確認刪除工作。

    工作會從「Jobs」頁面中移除。

REST

如要使用 REST API 刪除移轉作業,請參閱 transferJobs.delete 參考資料。

查看錯誤詳細資料

如果在轉移作業期間發生錯誤,您可以查看錯誤詳細資料,協助排除錯誤。

如要查看移轉工作執行作業的錯誤詳細資料,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Storage Transfer Service」頁面。

    前往 Storage 移轉服務

  2. 按一下轉移工作的說明。系統隨即會顯示「工作詳細資料」頁面。

  3. 執行下列任一操作,即可查看工作詳細資料:

    • 最近一次執行的工作:按一下「查看錯誤詳細資料」按鈕或「查看錯誤詳細資料」連結。系統會顯示「Error details」(錯誤詳細資料) 頁面。

    • 歷來的工作執行記錄:

      1. 按一下工作執行作業的「開始時間」

        系統隨即會顯示「執行作業詳細資料」頁面。

      2. 按一下「查看錯誤詳細資料」連結。

        系統隨即會顯示「Error details」(錯誤詳細資料) 頁面。

  4. 如要顯示每個顯示錯誤的其他詳細資料,請按一下 「展開更多」

  5. 如要篩選錯誤,請在「輸入屬性名稱或值」欄位中輸入要篩選的屬性。

    將游標移至欄位時,系統會顯示下拉式選單,列出相關選項,協助您建立篩選條件。