Is it possible to copy all files from one S3 bucket to another with s3cmd?

前端 未结 11 1740
陌清茗
陌清茗 2020-12-12 12:30

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?

EDIT: I\'ve found a way to copy files

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 13:20

    It's actually possible. This worked for me:

    import boto
    
    
    AWS_ACCESS_KEY = 'Your access key'
    AWS_SECRET_KEY = 'Your secret key'
    
    conn = boto.s3.connection.S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY)
    bucket = boto.s3.bucket.Bucket(conn, SRC_BUCKET_NAME)
    
    for item in bucket:
        # Note: here you can put also a path inside the DEST_BUCKET_NAME,
        # if you want your item to be stored inside a folder, like this:
        # bucket.copy(DEST_BUCKET_NAME, '%s/%s' % (folder_name, item.key))
        bucket.copy(DEST_BUCKET_NAME, item.key)
    

提交回复
热议问题