如何使用博托2 Amazon S3的桶之间移动文件? [英] How to move files between two Amazon S3 Buckets using boto?

查看:156
本文介绍了如何使用博托2 Amazon S3的桶之间移动文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个桶之间移动文件到另一个Pyhton博托API。 (我需要它从第一桶剪切文件和粘贴它在第二个)。 什么是做到这一点的最好方法是什么?

I have to move files between one bucket to another with Pyhton Boto API. (I need it to "Cut" the file from the first Bucket and "Paste" it in the second one). What is the best way to do that?

**注:?是不是问题,如果我有两个不同的访问和私钥

** Note: Is that matter if I have two different ACCESS KEYS and SECRET KEYS?

推荐答案

我觉得博托S​​3文档回答你的问题。

I think the boto S3 documentation answers your question.

https://github.com/boto/boto/ BLOB /开发/文档/源/ s3_tut.rst

将文件从一个桶到另一个通过博托有效的密钥的副本从源到目的地不是从源头去除的关键。

Moving files from one bucket to another via boto is effectively a copy of the keys from source to destination than removing the key from source.

您可以访问的水桶:

import boto

c = boto.connect_s3()
src = c.get_bucket('my_source_bucket')
dst = c.get_bucket('my_destination_bucket')

和重复键:

for k in src.list():
    # copy stuff to your destination here
    dst.copy_key(k.key, src, k.key)
    # then delete the source key
    k.delete()

另请参见:<一href="http://stackoverflow.com/questions/5194552/is-it-possible-to-copy-all-files-from-one-s3-bucket-to-another-with-s3cmd">Is它可以从一个S3存储到另一个的所有文件复制与s3cmd?

这篇关于如何使用博托2 Amazon S3的桶之间移动文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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