将数据从 Google 云存储导出到 Amazon S3

Exporting data from Google Cloud Storage to Amazon S3

我想将数据从 BigQuery 中的 table 传输到 Redshift 中的另一个。 我计划的数据流如下:

BigQuery -> Google 云存储 -> Amazon S3 -> Redshift

我知道 Google 云存储传输服务,但我不确定它是否对我有帮助。来自 Google 云文档:

Cloud Storage Transfer Service

This page describes Cloud Storage Transfer Service, which you can use to quickly import online data into Google Cloud Storage.

我了解此服务可用于将数据导入 Google Cloud Storage 而不能从中导出。

有什么方法可以将数据从 Google 云存储导出到 Amazon S3?

您可以使用 gsutil 将数据从 Google Cloud Storage 存储桶复制到 Amazon 存储桶,使用如下命令:

gsutil -m rsync -rd gs://your-gcs-bucket s3://your-s3-bucket

请注意,上面的 -d 选项会导致 gsutil rsync 从 S3 存储桶中删除 GCS 存储桶中不存在的对象(除了添加新对象之外)。如果您只想将新对象从 GCS 添加到 S3 存储桶,则可以不使用该选项。

使用 Rclone (https://rclone.org/)。

Rclone 是一个命令行程序,用于同步文件和目录

Google Drive
Amazon S3
Openstack Swift / Rackspace cloud files / Memset Memstore
Dropbox
Google Cloud Storage
Amazon Drive
Microsoft OneDrive
Hubic
Backblaze B2
Yandex Disk
SFTP
The local filesystem

我需要将 2TB 的数据从 Google Cloud Storage 存储桶传输到 Amazon S3 存储桶。 对于任务,我创建了 V8CPU (30 GB) 的 Google Compute Engine

允许在 Compute Engine 上使用 SSH 登录。 登录后创建并清空 .boto configuration 文件以添加 AWS 凭证信息。通过参考上述 link.

添加 AWS 凭据

然后运行命令:

gsutil -m rsync -rd gs://your-gcs-bucket s3://your-s3-bucket

数据传输速率约为 1GB/秒。

希望对您有所帮助。 (不要忘记在作业完成后终止计算实例)

转到 GCP

中的任何实例或云 shell

首先在您的 GCP 中配置您的 AWS 凭证

aws configure

如果无法识别安装 AWS CLI,请遵循本指南 https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html

按照此 URL 进行 AWS 配置 https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

附上我的截图

然后使用gsutil

gsutil -m rsync -rd gs://storagename s3://bucketname

几分钟内传输了 16GB 数据

使用 gsutil 工具,我们可以执行范围广泛的存储桶和对象管理任务,包括:

  1. 创建和删除存储桶。
  2. 正在上传、下载和删除对象。
  3. 列出存储桶和对象。移动、复制和重命名对象。

我们可以使用 gsutil rsyncgsutil cp 操作将数据从 Google Cloud Storage 存储桶复制到 amazon s3 存储桶。而

gsutil rsync 从存储桶中收集所有元数据并将数据同步到 s3

gsutil -m rsync -r gs://your-gcs-bucket s3://your-s3-bucket

gsutil cp一个一个复制文件,由于传输速度不错,大约1分钟复制1GB。

gsutil cp gs://<gcs-bucket> s3://<s3-bucket-name>

如果您有大量数据量大的文件,请使用此 bash 脚本,并在后台使用 screen 命令在亚马逊或 运行 多线程中使用它配置了 AWS 凭据并验证了 GCP 身份验证的 GCP 实例。

在 运行ning 脚本之前列出所有文件并重定向到一个文件并读取该文件作为脚本中的输入以复制文件

gsutil ls gs://<gcs-bucket> > file_list_part.out

Bash 脚本:

#!/bin/bash
echo "start processing" 
input="file_list_part.out"
while IFS= read -r line
do
    command="gsutil cp ${line} s3://<bucket-name>"
    echo "command :: $command :: $now"
    eval $command
    retVal=$?
    if [ $retVal -ne 0 ]; then
        echo "Error copying file"
        exit 1
    fi
    echo "Copy completed successfully"
done < "$input"
echo "completed processing"

执行Bash脚本并将输出写入日志文件以检查完成和失败文件的进度。

bash file_copy.sh > /root/logs/file_copy.log 2>&1

对于大量大文件 (100MB+),您可能会遇到管道损坏和其他烦恼的问题,这可能是由于分段上传要求(如 Pathead 所述)。

对于这种情况,您只需将所有文件下载到您的计算机上,然后再将它们上传回来。根据您的连接和数据量,创建 VM 实例以利用高速连接和 运行 在与您不同的机器上在后台运行它的能力可能更有效。

创建 VM 机器(确保服务帐户可以访问您的存储桶),通过 SSH 连接并安装 AWS CLI (apt install awscli) 并配置对 S3 的访问 (aws configure)。

运行 这两行,或者把它做成一个 bash 脚本,如果你有很多桶要复制。

gsutil -m cp -r "gs://" ./
aws s3 cp --recursive "./" "s3://"

(一般情况下使用rsync更好,但是cp对我来说更快)