從與 S3 相容的儲存空間轉移至 Cloud Storage

Storage 移轉服務支援從與 Amazon S3 API 相容的雲端或地端部署物件儲存系統移轉資料。

Storage 移轉服務會使用部署在資料來源附近 VM 上的移轉代理程式,存取 S3 相容儲存空間中的資料。這些代理程式會在 Docker 容器中執行,並屬於代理程式集區,也就是使用相同設定並共同平行移動資料的代理程式集合。

這項功能可讓您從地端部署或雲端物件儲存空間遷移至 Cloud Storage、封存資料以釋出地端部署儲存空間容量、將資料複製到Google Cloud 以維持業務連續性,或將資料移轉至Google Cloud 進行分析和處理。 對於從 AWS S3 遷移至 Cloud Storage 的客戶,這項功能可讓您控制連往 Google Cloud的網路路徑,大幅降低傳出資料移轉費用。

事前準備

設定移轉作業前,請先完成下列步驟:

必要條件

設定移轉作業前,請務必先完成下列設定:

轉移作業選項

從 S3 相容儲存空間移轉至 Cloud Storage 時,可使用下列 Storage 移轉服務功能:

使用資訊清單轉移特定檔案
您可以傳遞檔案清單,讓 Storage 移轉服務執行操作。詳情請參閱「使用資訊清單移轉特定檔案或物件」。
指定儲存空間級別
您可以指定要用於目的地 bucket 中資料的 Cloud Storage 儲存空間級別。請參閱 StorageClass 選項瞭解 REST 詳細資料,或搭配使用 --custom-storage-class 旗標與 Google Cloud CLI。

請注意,如果目的地 bucket 已啟用自動調整級別功能,系統會忽略所有儲存空間級別設定。如果啟用自動調整級別功能,轉移至 bucket 的物件一開始會設為 Standard Storage。

保存中繼資料

從與 S3 相容的儲存空間移轉檔案時,Storage 移轉服務可選擇將特定屬性保留為自訂中繼資料。

如要瞭解可保留的中繼資料,以及如何設定移轉作業,請參閱「中繼資料保留」的「從 Amazon S3 或 S3 相容儲存空間移轉至 Cloud Storage」一節。

記錄和監控
您可以在 Cloud Logging 和 Cloud Monitoring 中,查看從與 S3 相容儲存空間轉移的作業。詳情請參閱「Storage 移轉服務的 Cloud Logging」和「監控移轉工作」。您也可以設定 Pub/Sub 通知。

建立代理程式集區

請勿在代理程式集區名稱或代理程式 ID 前置字串中加入機密資訊,例如個人識別資訊 (PII) 或安全性資料。資源名稱可能會傳播至其他 Google Cloud 資源的名稱,並可能在專案外部向 Google 內部系統公開。

如要建立代理程式集區,請按照下列步驟操作:

Google Cloud 控制台

  1. 前往 Google Cloud 控制台的「Agent pools」(代理程式集區) 頁面。

    前往「Agent pools」(代理程式集區) 頁面

    系統會顯示「Agent pools」(代理程式集區) 頁面,列出您現有的代理程式集區。

  2. 按一下「建立其他集區」。

  3. 為集區命名,並視需要輸入說明。

  4. 您可以選擇設定頻寬限制,套用至整個集區。指定頻寬 (以 MB/s 為單位) 會分配給集區中的所有代理程式。詳情請參閱「管理網路頻寬」。

  5. 點選「建立」。

REST API

使用 projects.agentPools.create:

POST https://storagetransfer.googleapis.com/v1/projects/PROJECT_ID/agentPools?agent_pool_id=AGENT_POOL_ID

更改下列內容:

  • PROJECT_ID:要建立代理程式集區的專案 ID。
  • AGENT_POOL_ID:要建立的代理程式集區 ID。

如果代理程式集區卡在 Creating 狀態超過 30 分鐘,建議您刪除代理程式集區並重新建立。

如果代理程式集區處於 Creating 狀態,撤銷專案所需的 Storage 移轉服務權限會導致服務行為不正確。

gcloud CLI

如要使用 gcloud 指令列工具建立代理程式集區,請執行 gcloud transfer agent-pools create。

gcloud transfer agent-pools create AGENT_POOL

可用的選項如下:

  • AGENT_POOL 是這個集區的專屬永久 ID。

  • --no-async 會封鎖終端機中的其他工作,直到集區建立完成為止。如未提供,集區建立作業會以非同步方式執行。

  • --bandwidth-limit 定義要提供給這個集區代理程式的頻寬 (以 MB/s 為單位)。頻寬限制適用於集區中的所有代理程式,可防止集區的移轉工作負載干擾共用頻寬的其他作業。例如,輸入「50」即可將頻寬限制設為 50 MB/s。如未指定這個旗標,這個集區的代理程式將使用所有可用頻寬。

  • --display-name 是可修改的名稱,方便您識別這個集區。您可以加入集區專屬完整資源名稱中可能不適合的詳細資料。

安裝移轉代理程式

移轉代理程式是軟體代理程式,可透過 Storage 移轉服務協調來源的移轉活動。必須安裝在可存取來源資料的系統上。

gcloud CLI

如要使用 gcloud CLI 安裝代理程式,以便與 S3 相容來源搭配使用,請使用 transfer agents install 指令。

您必須提供存取憑證,可以做為環境變數 (AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 的值),也可以儲存為系統設定檔中的預設憑證。

export AWS_ACCESS_KEY_ID=ID
export AWS_SECRET_ACCESS_KEY=SECRET
gcloud transfer agents install --pool=POOL_NAME

如要使用服務帳戶金鑰執行代理程式,請使用 --creds-file 選項:

gcloud transfer agents install --pool=POOL_NAME \
  --creds-file=/relative/path/to/service-account-key.json

建立移轉工作

Google Cloud 控制台

請按照下列步驟,建立從 S3 相容來源到 Cloud Storage bucket 的移轉作業。

  1. 前往 Google Cloud 控制台的「Storage 移轉服務」頁面。

    前往 Storage 移轉服務

  2. 按一下「建立移轉工作」。系統會顯示「Create a transfer job」(建立移轉工作) 頁面。

  3. 選取「與 S3 相容的物件儲存庫」做為「來源類型」。目的地必須是「Cloud Storage」。

    點選「下一步」。

設定來源

  1. 指定這項移轉作業的必要資訊:

    1. 選取您為這項移轉作業設定的代理程式集區。

    2. 輸入與端點相關的值區名稱。舉例來說,如果資料位於:

      https://example.com/bucket_a

      輸入:bucket_a

    3. 輸入端點。請勿加入通訊協定 (http:// 或 https://) 或 bucket 名稱。例如:

      example.com

  2. 為這項轉移作業指定任何選用屬性:

    1. 輸入要用於簽署要求的「簽署區域」。

    2. 選擇這項要求的「簽署程序」。

    3. 選取「位址樣式」。這會決定 bucket 名稱是以路徑樣式 (例如 https://example.com/bucket-name/key-name) 或虛擬主機樣式 (例如 https://bucket-name.example.com/key-name) 提供。詳情請參閱 Amazon 說明文件中的「虛擬主機 bucket」。

    4. 選取「網路通訊協定」。

    5. 選取要使用的產品資訊 API 版本。詳情請參閱 ListObjectsV2 和 ListObjects 說明文件。

  3. 點選「下一步」。

設定接收器

  1. 在「Bucket or folder」(Bucket 或資料夾) 欄位中,輸入目的地 bucket 和資料夾名稱 (選用),或按一下「Browse」(瀏覽),從目前專案的現有 bucket 清單中選取 bucket。如要建立新的 bucket,請按一下 「值區」圖示「Create new bucket」(建立新的 bucket)。

  2. 點選「下一步」。

選擇轉移設定

  1. 在「Description」(說明) 欄位中,輸入移轉作業的說明。建議您輸入有意義且不重複的說明,以便區分工作。

  2. 在「Metadata options」(中繼資料選項) 下方,選擇使用預設選項,或按一下「View and select options」(查看並選取選項),為所有支援的中繼資料指定值。詳情請參閱「中繼資料保留」。

  3. 在「何時覆寫」下方,選取下列其中一個選項:

    • 如果不同:如果同名來源檔案的 Etag 或核對和值不同,則覆寫目的地檔案。

    • Always:來源檔案與目的地檔案的名稱相同時,一律覆寫目的地檔案,即便檔案內容完全相同。

  4. 在「刪除時間」下方,選取下列其中一個選項:

    • 一律不:一律不刪除來源或目的地的檔案。

    • 轉移檔案後,請從來源刪除檔案:檔案轉移至目的地後,從來源刪除檔案。如果來源檔案未轉移 (例如目的地已存在該檔案),則不會刪除來源檔案。

    • Delete files from destination if they're not also at source:如果目的地 Cloud Storage bucket 中的檔案未同時存在於來源,則從 Cloud Storage bucket 中刪除檔案。

      這個選項可確保目的地 Cloud Storage bucket 與來源完全相符。

  5. 在「Notification options」(通知選項) 下方,選取 Pub/Sub 主題和要通知的事件。詳情請參閱「Pub/Sub 通知」。

  6. 點選「下一步」。

排定轉移作業

您可以安排只執行一次移轉作業,或設定週期性移轉作業。

點選「建立」,建立移轉工作。

gcloud CLI

使用 gcloud CLI 建立移轉作業前,請按照「設定 Cloud Storage 接收器的存取權」一文中的操作說明進行。

如要使用 gcloud CLI 建立移轉作業,將 S3 相容來源的資料移轉至 Cloud Storage bucket,請使用下列指令。

gcloud transfer jobs create s3://SOURCE_BUCKET_NAME gs://SINK_BUCKET_NAME \
  --source-agent-pool=POOL_NAME \
  --source-endpoint=ENDPOINT \
  --source-signing-region=REGION \
  --source-auth-method=AWS_SIGNATURE_V2 | AWS_SIGNATURE_V4 \
  --source-request-model=PATH_STYLE | VIRTUAL_HOSTED_STYLE \
  --source-network-protocol=HTTP | HTTPS \
  --source-list-api=LIST_OBJECTS | LIST_OBJECTS_V2

必須使用下列旗標:

  • --source-agent-pool 是要用於這項移轉作業的代理程式集區名稱。

  • --source-endpoint 指定儲存系統的端點。例如:s3.us-east.example.com。請向供應商確認正確格式。請勿加入通訊協定 (例如 https://) 或 bucket 名稱。

其餘旗標為選用:

  • --source-signing-region 指定經簽署的要求的區域。如果儲存空間供應商未要求輸入簽署區域,請略過這個旗標。
  • --source-auth-method 指定要使用的驗證方式。有效值為 AWS_SIGNATURE_V2 或 AWS_SIGNATURE_V4。詳情請參閱 Amazon 的 SigV4 和 SigV2 說明文件。
  • --source-request-model 會指定要使用的位址樣式。有效值為 PATH_STYLE 或 VIRTUAL_HOSTED_STYLE。路徑樣式使用 https://s3.REGION.example.com/BUCKET_NAME/KEY_NAME 格式。虛擬主機樣式使用 https://BUCKET_NAME.s3.REGION.example.com/KEY_NAME 格式。
  • --source-network-protocol 指定代理程式應在這項工作中使用的網路通訊協定。有效值為 HTTP 或 HTTPS。
  • --source-list-api 指定 S3 Listing API 的版本,以便從值區傳回物件。有效值為 LIST_OBJECTS 或 LIST_OBJECTS_V2。詳情請參閱 Amazon 的 ListObjectsV2 和 ListObjects 說明文件。

如需其他轉移工作選項,請執行 gcloud transfer jobs create --help,或參閱 gcloud 參考文件。

REST API

使用 REST API 建立移轉作業前,請按照「設定 Cloud Storage 接收器的存取權」一文中的操作說明操作。

如要使用 REST API 從 S3 相容來源建立移轉作業,請建立類似下列範例的 JSON 物件。

POST https://storagetransfer.googleapis.com/v1/transferJobs
{
"projectId": "PROJECT_ID",
"status": "ENABLED",
"transferSpec": {
  "sourceAgentPoolName": "projects/PROJECT_ID/agentPools/POOL_NAME",
  "awsS3CompatibleDataSource": {
    "region": "us-east-1",
    "s3Metadata": {
      "protocol": "NETWORK_PROTOCOL_HTTPS",
      "requestModel": "REQUEST_MODEL_VIRTUAL_HOSTED_STYLE",
      "authMethod": "AUTH_METHOD_AWS_SIGNATURE_V4"
    },
    "endpoint": "example.com",
    "bucketName": "BUCKET_NAME",
    "path": "PATH"
  },
  "gcsDataSink": {
    "bucketName": "SINK_NAME",
    "path": "SINK_PATH"
  },
  "transferOptions": {
    "deleteObjectsFromSourceAfterTransfer": false
  }
}
}

如需欄位說明,請參閱 AwsS3CompatibleData API 參考資料。

用戶端程式庫

使用用戶端程式庫建立移轉作業前,請按照「設定 Cloud Storage 接收器的存取權」中的操作說明操作。

Go

如要瞭解如何安裝及使用 Storage 移轉服務的用戶端程式庫,請參閱「Storage 移轉服務用戶端程式庫」。詳情請參閱 Storage 移轉服務 Go API 參考文件。

如要向 Storage 移轉服務進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


import (
	"context"
	"fmt"
	"io"

	storagetransfer "cloud.google.com/go/storagetransfer/apiv1"
	"cloud.google.com/go/storagetransfer/apiv1/storagetransferpb"
)

func transferFromS3CompatibleSource(w io.Writer, projectID string, sourceAgentPoolName string, sourceBucketName string, sourcePath string, gcsSinkBucket string, gcsPath string) (*storagetransferpb.TransferJob, error) {
	// Your project id.
	// projectId := "my-project-id"

	// The agent pool associated with the S3 compatible data source. If not provided, defaults to the default agent.
	// sourceAgentPoolName := "projects/my-project/agentPools/transfer_service_default"

	// The S3 compatible bucket name to transfer data from.
	//sourceBucketName = "my-bucket-name"

	// The S3 compatible path (object prefix) to transfer data from.
	//sourcePath = "path/to/data"

	// The ID of the GCS bucket to transfer data to.
	//gcsSinkBucket = "my-sink-bucket"

	// The GCS path (object prefix) to transfer data to.
	//gcsPath = "path/to/data"

	// The S3 region of the source bucket.
	region := "us-east-1"

	// The S3 compatible endpoint.
	endpoint := "us-east-1.example.com"

	// The S3 compatible network protocol.
	protocol := storagetransferpb.S3CompatibleMetadata_NETWORK_PROTOCOL_HTTPS

	// The S3 compatible request model.
	requestModel := storagetransferpb.S3CompatibleMetadata_REQUEST_MODEL_VIRTUAL_HOSTED_STYLE

	// The S3 Compatible auth method.
	authMethod := storagetransferpb.S3CompatibleMetadata_AUTH_METHOD_AWS_SIGNATURE_V4

	ctx := context.Background()
	client, err := storagetransfer.NewClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("storagetransfer.NewClient: %w", err)
	}
	defer client.Close()

	req := &storagetransferpb.CreateTransferJobRequest{
		TransferJob: &storagetransferpb.TransferJob{
			ProjectId: projectID,
			TransferSpec: &storagetransferpb.TransferSpec{
				SourceAgentPoolName: sourceAgentPoolName,
				DataSource: &storagetransferpb.TransferSpec_AwsS3CompatibleDataSource{
					AwsS3CompatibleDataSource: &storagetransferpb.AwsS3CompatibleData{
						BucketName: sourceBucketName,
						Path:       sourcePath,
						Endpoint:   endpoint,
						Region:     region,
						DataProvider: &storagetransferpb.AwsS3CompatibleData_S3Metadata{
							S3Metadata: &storagetransferpb.S3CompatibleMetadata{
								AuthMethod:   authMethod,
								RequestModel: requestModel,
								Protocol:     protocol,
							},
						},
					}},
				DataSink: &storagetransferpb.TransferSpec_GcsDataSink{
					GcsDataSink: &storagetransferpb.GcsData{
						BucketName: gcsSinkBucket,
						Path:       gcsPath,
					},
				},
			},
			Status: storagetransferpb.TransferJob_ENABLED,
		},
	}

	resp, err := client.CreateTransferJob(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("failed to create transfer job: %w", err)
	}
	if _, err = client.RunTransferJob(ctx, &storagetransferpb.RunTransferJobRequest{
		ProjectId: projectID,
		JobName:   resp.Name,
	}); err != nil {
		return nil, fmt.Errorf("failed to run transfer job: %w", err)
	}
	fmt.Fprintf(w, "Created and ran transfer job from %v to %v with name %v", sourceBucketName, gcsSinkBucket, resp.Name)
	return resp, nil
}

Java

如要瞭解如何安裝及使用 Storage 移轉服務的用戶端程式庫,請參閱「Storage 移轉服務用戶端程式庫」。詳情請參閱 Storage 移轉服務 Java API 參考文件。

如要向 Storage 移轉服務進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import static com.google.storagetransfer.v1.proto.TransferTypes.S3CompatibleMetadata.AuthMethod;
import static com.google.storagetransfer.v1.proto.TransferTypes.S3CompatibleMetadata.NetworkProtocol;
import static com.google.storagetransfer.v1.proto.TransferTypes.S3CompatibleMetadata.RequestModel;

import com.google.storagetransfer.v1.proto.StorageTransferServiceClient;
import com.google.storagetransfer.v1.proto.TransferProto;
import com.google.storagetransfer.v1.proto.TransferTypes;
import com.google.storagetransfer.v1.proto.TransferTypes.GcsData;
import com.google.storagetransfer.v1.proto.TransferTypes.TransferJob;
import com.google.storagetransfer.v1.proto.TransferTypes.TransferSpec;
import java.io.IOException;

public class TransferFromS3CompatibleSource {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.

    // Your project id
    String projectId = "my-project-id";

    // The agent pool associated with the S3 compatible data source. If not provided, defaults to
    // the default agent
    String sourceAgentPoolName = "projects/my-project-id/agentPools/transfer_service_default";

    // The S3 compatible bucket name to transfer data from
    String sourceBucketName = "my-bucket-name";

    // The S3 compatible path (object prefix) to transfer data from
    String sourcePath = "path/to/data";

    // The ID of the GCS bucket to transfer data to
    String gcsSinkBucket = "my-sink-bucket";

    // The GCS path (object prefix) to transfer data to
    String gcsPath = "path/to/data";

    // The S3 region of the source bucket
    String region = "us-east-1";

    // The S3 compatible endpoint
    String endpoint = "us-east-1.example.com";

    // The S3 compatible network protocol
    NetworkProtocol protocol = NetworkProtocol.NETWORK_PROTOCOL_HTTPS;

    // The S3 compatible request model
    RequestModel requestModel = RequestModel.REQUEST_MODEL_VIRTUAL_HOSTED_STYLE;

    // The S3 Compatible auth method
    AuthMethod authMethod = AuthMethod.AUTH_METHOD_AWS_SIGNATURE_V4;

    transferFromS3CompatibleSource(
        projectId,
        sourceAgentPoolName,
        sourceBucketName,
        sourcePath,
        region,
        endpoint,
        protocol,
        requestModel,
        authMethod,
        gcsSinkBucket,
        gcsPath);
  }

  public static void transferFromS3CompatibleSource(
      String projectId,
      String sourceAgentPoolName,
      String sourceBucketName,
      String sourcePath,
      String region,
      String endpoint,
      NetworkProtocol protocol,
      RequestModel requestModel,
      AuthMethod authMethod,
      String gcsSinkBucket,
      String gcsPath)
      throws IOException {
    TransferJob transferJob =
        TransferJob.newBuilder()
            .setProjectId(projectId)
            .setTransferSpec(
                TransferSpec.newBuilder()
                    .setSourceAgentPoolName(sourceAgentPoolName)
                    .setAwsS3CompatibleDataSource(
                        TransferTypes.AwsS3CompatibleData.newBuilder()
                            .setRegion(region)
                            .setEndpoint(endpoint)
                            .setBucketName(sourceBucketName)
                            .setPath(sourcePath)
                            .setS3Metadata(
                                TransferTypes.S3CompatibleMetadata.newBuilder()
                                    .setProtocol(protocol)
                                    .setRequestModel(requestModel)
                                    .setAuthMethod(authMethod)
                                    .build())
                            .build())
                    .setGcsDataSink(
                        GcsData.newBuilder().setBucketName(gcsSinkBucket).setPath(gcsPath).build()))
            .setStatus(TransferJob.Status.ENABLED)
            .build();

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources,
    // or use "try-with-close" statement to do this automatically.
    try (StorageTransferServiceClient storageTransfer = StorageTransferServiceClient.create()) {

      // Create the transfer job
      TransferJob response =
          storageTransfer.createTransferJob(
              TransferProto.CreateTransferJobRequest.newBuilder()
                  .setTransferJob(transferJob)
                  .build());

      System.out.println(
          "Created a transfer job from "
              + sourceBucketName
              + " to "
              + gcsSinkBucket
              + " with "
              + "name "
              + response.getName());
    }
  }
}

Node.js

如要瞭解如何安裝及使用 Storage 移轉服務的用戶端程式庫,請參閱「Storage 移轉服務用戶端程式庫」。詳情請參閱 Storage 移轉服務 Node.js API 參考文件。

如要向 Storage 移轉服務進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


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

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// Useful enums for AWS S3-Compatible Transfers
// const {AuthMethod, NetworkProtocol, RequestModel} = storageTransfer.protos.google.storagetransfer.v1.S3CompatibleMetadata;

// Your project id
// const projectId = 'my-project';

// The agent pool associated with the S3-compatible data source. Defaults to the default agent
// const sourceAgentPoolName = 'projects/my-project/agentPools/transfer_service_default';

// The S3-compatible bucket name to transfer data from
// const sourceBucketName = "my-bucket-name";

// The S3-compatible path (object prefix) to transfer data from
// const sourcePath = "path/to/data/";

// The ID of the GCS bucket to transfer data to
// const gcsSinkBucket = "my-sink-bucket";

// The GCS path (object prefix) to transfer data to
// const gcsPath = "path/to/data/";

// The S3 region of the source bucket
// const region = 'us-east-1';

// The S3-compatible endpoint
// const endpoint = "us-east-1.example.com";

// The S3-compatible network protocol
// const protocol = NetworkProtocol.NETWORK_PROTOCOL_HTTPS;

// The S3-compatible request model
// const requestModel = RequestModel.REQUEST_MODEL_VIRTUAL_HOSTED_STYLE;

// The S3-compatible auth method
// const authMethod = AuthMethod.AUTH_METHOD_AWS_SIGNATURE_V4;

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

/**
 * Creates a transfer from an AWS S3-compatible source to GCS
 */
async function transferFromS3CompatibleSource() {
  // Runs the request and creates the job
  const [transferJob] = await client.createTransferJob({
    transferJob: {
      projectId,
      transferSpec: {
        sourceAgentPoolName,
        awsS3CompatibleDataSource: {
          region,
          s3Metadata: {
            authMethod,
            protocol,
            requestModel,
          },
          endpoint,
          bucketName: sourceBucketName,
          path: sourcePath,
        },
        gcsDataSink: {
          bucketName: gcsSinkBucket,
          path: gcsPath,
        },
      },
      status: 'ENABLED',
    },
  });

  await client.runTransferJob({
    jobName: transferJob.name,
    projectId,
  });

  console.log(
    `Created and ran a transfer job from '${sourceBucketName}' to '${gcsSinkBucket}' with name ${transferJob.name}`
  );
}

transferFromS3CompatibleSource();

Python

如要瞭解如何安裝及使用 Storage 移轉服務的用戶端程式庫,請參閱「Storage 移轉服務用戶端程式庫」。詳情請參閱 Storage 移轉服務 Python API 參考文件。

如要向 Storage 移轉服務進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

from google.cloud import storage_transfer

AuthMethod = storage_transfer.S3CompatibleMetadata.AuthMethod
NetworkProtocol = storage_transfer.S3CompatibleMetadata.NetworkProtocol
RequestModel = storage_transfer.S3CompatibleMetadata.RequestModel


def transfer_from_S3_compat_to_gcs(
    project_id: str,
    description: str,
    source_agent_pool_name: str,
    source_bucket_name: str,
    source_path: str,
    gcs_sink_bucket: str,
    gcs_path: str,
    region: str,
    endpoint: str,
    protocol: NetworkProtocol,
    request_model: RequestModel,
    auth_method: AuthMethod,
) -> None:
    """Creates a transfer from an AWS S3-compatible source to GCS"""

    client = storage_transfer.StorageTransferServiceClient()

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

    # A useful description for your transfer job
    # description = 'My transfer job'

    # The agent pool associated with the S3-compatible data source.
    # Defaults to 'projects/{project_id}/agentPools/transfer_service_default'
    # source_agent_pool_name = 'projects/my-project/agentPools/my-agent'

    # The S3 compatible bucket name to transfer data from
    # source_bucket_name = "my-bucket-name"

    # The S3 compatible path (object prefix) to transfer data from
    # source_path = "path/to/data/"

    # The ID of the GCS bucket to transfer data to
    # gcs_sink_bucket = "my-sink-bucket"

    # The GCS path (object prefix) to transfer data to
    # gcs_path = "path/to/data/"

    # The S3 region of the source bucket
    # region = 'us-east-1'

    # The S3-compatible endpoint
    # endpoint = "us-east-1.example.com"

    # The S3-compatible network protocol
    # protocol = NetworkProtocol.NETWORK_PROTOCOL_HTTPS

    # The S3-compatible request model
    # request_model = RequestModel.REQUEST_MODEL_VIRTUAL_HOSTED_STYLE

    # The S3-compatible auth method
    # auth_method = AuthMethod.AUTH_METHOD_AWS_SIGNATURE_V4

    transfer_job_request = storage_transfer.CreateTransferJobRequest(
        {
            "transfer_job": {
                "project_id": project_id,
                "description": description,
                "status": storage_transfer.TransferJob.Status.ENABLED,
                "transfer_spec": {
                    "source_agent_pool_name": source_agent_pool_name,
                    "aws_s3_compatible_data_source": {
                        "region": region,
                        "s3_metadata": {
                            "auth_method": auth_method,
                            "protocol": protocol,
                            "request_model": request_model,
                        },
                        "endpoint": endpoint,
                        "bucket_name": source_bucket_name,
                        "path": source_path,
                    },
                    "gcs_data_sink": {
                        "bucket_name": gcs_sink_bucket,
                        "path": gcs_path,
                    },
                },
            }
        }
    )

    result = client.create_transfer_job(transfer_job_request)
    print(f"Created transferJob: {result.name}")

常見問題

如果我的 S3 相容供應商使用自訂 SSL 憑證,該怎麼辦?

如果 S3 相容供應商使用的 SSL 憑證並非由公開憑證授權單位核發,移轉作業可能會失敗,並顯示 TLS 錯誤。如要解決這個問題,請使用 -v Docker 旗標,將供應商的根憑證掛接至 /etc/ssl/certs/CERT_FILE 的移轉代理程式容器。

例如:

sudo docker run --ulimit memlock=64000000 -d --rm \
-v HOST_DIRECTORY:CONTAINER_DIRECTORY \
-v PATH/TO/KEY.JSON:/etc/gcloud/key.json:ro \
-v /path/to/your/CERT_FILE:/etc/ssl/certs/CERT_FILE \
-e AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY \
gcr.io/cloud-ingest/tsop-agent:latest \
--project-id=PROJECT_ID \
--creds-file=/etc/gcloud/key.json \
--hostname=$(hostname) \
--agent-pool=POOL_NAME

從與 S3 相容的儲存空間移轉資料需要付費嗎?

從與 S3 相容的儲存空間轉移資料,不會產生「需要代理的 Storage 移轉服務移轉作業」費用。如要瞭解可能產生的其他費用,請參閱「定價」一節。您可能也須支付來源雲端服務供應商規定的資料轉出和作業費用。

與 S3 相容的儲存空間移轉作業是否支援 Cloud Logging?

可以,請按照「Storage 移轉服務的 Cloud Logging」中的操作說明,為移轉作業啟用 Cloud Logging。

是否支援使用資訊清單進行移轉?

可以,S3 相容移轉作業支援資訊清單檔案。

如果我在工作啟動後將物件新增至來源 bucket,該物件會轉移嗎?

Storage 移轉服務會對來源 bucket 執行清單作業,計算與目的地的差異。如果新增物件時,清單作業已完成,系統會略過該物件,直到下次轉移。

Storage 移轉服務是否會對與 S3 相容的來源執行核對和比對?

Storage 移轉服務會依據來源傳回的核對和資料,如果是與 S3 相容的儲存空間,Storage 移轉服務會預期物件的 Etag 為物件的 MD5 雜湊。

不過,使用 S3 多部分上傳功能移轉至 S3 相容儲存空間的物件,不會有 MD5 ETag。在這種情況下,Storage 移轉服務會使用檔案大小來驗證移轉的物件。

從與 S3 相容的儲存空間轉移資料時,可以達到多少處理量?

您可以新增更多移轉代理程式,提高移轉處理量。建議使用 3 個代理程式,以容錯並填滿 <10Gbps 管道。如要進一步擴充,請新增更多代理。在轉移過程中,您可以新增及移除代理。

應將移轉代理程式部署在何處,才能將資料從 Amazon S3 移轉至 Cloud Storage?

您可以在與 bucket 位於相同區域的 Amazon EC2 或 EKS 中安裝代理程式。您也可以在最靠近的區域中,透過 Google Cloud 執行代理。