是否可以使用 s3cmd 将所有文件从一个 S3 存储桶复制到另一个存储桶? [英] Is it possible to copy all files from one S3 bucket to another with s3cmd?

查看:27
本文介绍了是否可以使用 s3cmd 将所有文件从一个 S3 存储桶复制到另一个存储桶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 s3cmd 很满意,但有一个问题:如何将所有文件从一个 S3 存储桶复制到另一个存储桶?甚至有可能吗?

I'm pretty happy with s3cmd, but there is one issue: How to copy all files from one S3 bucket to another? Is it even possible?

我找到了一种使用 Python 和 boto 在存储桶之间复制文件的方法:

I've found a way to copy files between buckets using Python with boto:

from boto.s3.connection import S3Connection

def copyBucket(srcBucketName, dstBucketName, maxKeys = 100):
  conn = S3Connection(awsAccessKey, awsSecretKey)

  srcBucket = conn.get_bucket(srcBucketName);
  dstBucket = conn.get_bucket(dstBucketName);

  resultMarker = ''
  while True:
    keys = srcBucket.get_all_keys(max_keys = maxKeys, marker = resultMarker)

    for k in keys:
      print 'Copying ' + k.key + ' from ' + srcBucketName + ' to ' + dstBucketName

      t0 = time.clock()
      dstBucket.copy_key(k.key, srcBucketName, k.key)
      print time.clock() - t0, ' seconds'

    if len(keys) < maxKeys:
      print 'Done'
      break

    resultMarker = keys[maxKeys - 1].key

同步几乎和复制一样简单.有 ETag、大小和上次修改的字段可用于键.

Syncing is almost as straight forward as copying. There are fields for ETag, size, and last-modified available for keys.

也许这对其他人也有帮助.

Maybe this helps others as well.

推荐答案

s3cmd 同步 s3://from/this/bucket/s3://to/this/bucket/

对于可用选项,请使用:$s3cmd --help

For available options, please use: $s3cmd --help

这篇关于是否可以使用 s3cmd 将所有文件从一个 S3 存储桶复制到另一个存储桶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆