Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving many files in the same bucket

Tags:

amazon-s3

I've got 200k files in a bucket which I need to move into a sub folder within the same bucket, whats the best approach?

like image 760
martin blank Avatar asked Aug 12 '11 16:08

martin blank


People also ask

Is bucket same as folder?

You can have folders within folders, but not buckets within buckets. You can upload and copy objects directly into a folder. Folders can be created, deleted, and made public, but they cannot be renamed.

What is the max size of the file in a bucket?

Individual Amazon S3 objects can now range in size from 1 byte all the way to 5 terabytes (TB).


3 Answers

I recently encountered the same problem. I solved it using the command line API.

http://docs.aws.amazon.com/cli/latest/index.html http://docs.aws.amazon.com/cli/latest/reference/s3/mv.html

aws s3 mv s3://BUCKETNAME/myfolder/photos/ s3://BUCKETNAME/myotherfolder/photos/ --recursive 

I had a need for the objects to be publicly viewable, so I added the --acl public-read option.

like image 79
Matt Healy Avatar answered Sep 22 '22 17:09

Matt Healy


Recently was able to do this with one command. Went much faster than individual requests for each file too.

Running a snippet like this:

aws s3 mv s3://bucket-name/ s3://bucket-name/subfolder --recursive --exclude "*" --include "*.txt" 

Use the --include flag to selectively pick up the files you want

like image 22
nokatzhere Avatar answered Sep 22 '22 17:09

nokatzhere


There is no 'Rename' operation though it would be great if there was.

Instead, you need to loop through each item that you want to rename, perform a copy to a new object and then a delete on the old object.

  • http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectCOPY.html
  • http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectDELETE.html

Note: for simplistic purposes I'm assuming you don't have versioning enabled on your bucket.

like image 45
chilts Avatar answered Sep 19 '22 17:09

chilts