amazon-s3 - 在 S3 存储桶之间移动文件的最佳方式?

标签 amazon-s3

我想每天将一些文件从生产存储桶复制到开发存储桶。

例如: 复制 Productionbucket/feed/feedname/date 到developmentbucket/feed/feedname/date

由于我想要的文件在文件夹结构中太深,因此转到每个文件夹并复制/粘贴太耗时。

我尝试过将驱动器安装到每个存储桶并编写 Windows 批处理脚本,但这非常慢,并且不必要地将所有文件/文件夹下载到本地服务器并再次备份。

最佳答案

更新

pointed out by alberge (+1),现在优秀的AWS Command Line Interface提供了与(几乎)所有 AWS 事物交互的最通用方法 - 它同时涵盖了大多数服务的 API,并且还具有用于专门处理您的用例的更高级别的 S3 命令,请参阅 AWS CLI reference for S3 :

  • sync - 同步目录和 S3 前缀。 Example 2 涵盖了您的用例。 (还可以使用 --exclude--include 和前缀处理等更细粒度的用法):

    The following sync command syncs objects under a specified prefix and bucket to objects under another specified prefix and bucket by copying s3 objects. [...]

    aws s3 sync s3://from_my_bucket s3://to_my_other_bucket
    

为了完整起见,我会提到较低级别的 S3 命令仍然可以通过 s3api 获得。 sub 命令,它允许在最终采用其更高级别的功能之前将任何基于开发工具包的解决方案直接转换为 AWS CLI。

<小时/>

初步回答

在 S3 存储桶之间移动文件可以通过 PUT Object - Copy API 来实现(后跟 DELETE Object ):

This implementation of the PUT operation creates a copy of an object that is already stored in Amazon S3. A PUT copy operation is the same as performing a GET and then a PUT. Adding the request header, x-amz-copy-source, makes the PUT operation copy the source object into the destination bucket. Source

所有现有 AWS 开发工具包都有各自的示例,请参阅 Copying Objects in a Single Operation 。当然,基于脚本的解决方案显然是这里的首选,因此 Copy an Object Using the AWS SDK for Ruby可能是一个很好的起点;如果您更喜欢 Python,也可以通过 boto 实现相同的目的当然,请参阅 boto 的 S3 API documentation 中的方法 copy_key() .

PUT Object 仅复制文件,因此在成功复制操作后,您仍然需要通过 DELETE Object 显式删除文件,但这只是另外几个一旦处理存储桶和文件名的整体脚本到位(也有相应的示例,请参阅 Deleting One Object Per Request )。

关于amazon-s3 - 在 S3 存储桶之间移动文件的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9664904/

相关文章:

java - 拒绝访问(服务: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: xxxxxxxxxxxxx)

amazon-web-services - 使用 amazon s3 存储 solr 数据

amazon-s3 - 尝试使用以下配置创建 S3 存储桶时,继续遇到此错误 : Template validation error

ruby - 预签名的 GET url 返回 403

android - 在 Android 上下载 amazon s3 图片

javascript - 自动上传图片到s3

amazon-web-services - 在 Lambda 中创建 AmazonS3Client 时出现 OutOfMemoryError

java - 使用 Apache Camel 根据 S3 事件通知传输 S3 文件

scala - 无法使用 spark 从 s3 存储桶中读取

bash - 可以通过没有 aws-cli 的 shell 脚本上传到 S3 吗?