Skip to content

Instantly share code, notes, and snippets.

@wilsaj
Created April 14, 2015 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilsaj/85ad9a16ff8c5191bde1 to your computer and use it in GitHub Desktop.
Save wilsaj/85ad9a16ff8c5191bde1 to your computer and use it in GitHub Desktop.
boto multipart copy
def _s3_multipart_copy(old_bucket, old_key, new_bucket, new_key):
old_key_obj = old_bucket.lookup(old_key)
key_size = old_key_obj.size
part_size = 1000000000
parts = [
(i+1, i * part_size, min(key_size - 1, ((i + 1) * part_size) - 1))
for i in range((old_key_obj.size / part_size) + 1)
]
multipart = new_bucket.initiate_multipart_upload(new_key)
for (i, start, end) in parts:
print("copying %s part %s of %s " % (old_key, i, len(parts)))
multipart.copy_part_from_key(etl_config.old_bucket, old_key, i, start, end)
multipart.complete_upload()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment