Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selective file download in AWS S3 CLI

I have files in S3 bucket. I was trying to download files based on a date, like 08th aug, 09th Aug etc.

I used the following code, but it still downloads the entire bucket:

aws s3 cp s3://bucketname/ folder/file \     --profile pname \     --exclude \"*\" \     --recursive \     --include \"" + "2015-08-09" + "*\" 

I am not sure, how to achieve this. How can I download selective date file?

like image 613
user4033385 Avatar asked Aug 11 '15 12:08

user4033385


People also ask

How do I download from S3 bucket to aws CLI?

To download an entire bucket to your local file system, use the AWS CLI sync command, passing it the s3 bucket as a source and a directory on your file system as a destination, e.g. aws s3 sync s3://YOUR_BUCKET . . The sync command recursively copies the contents of the source to the destination.

How do I extract files from S3 bucket?

In the Amazon S3 console, choose your S3 bucket, choose the file that you want to open or download, choose Actions, and then choose Open or Download. If you are downloading an object, specify where you want to save it.

How do I download multiple files from S3 bucket to local?

If you have Visual Studio with the AWS Explorer extension installed, you can also browse to Amazon S3 (step 1), select your bucket (step 2), select al the files you want to download (step 3) and right click to download them all (step 4).


1 Answers

This command will copy all files starting with 2015-08-15:

aws s3 cp s3://BUCKET/ folder --exclude "*" --include "2015-08-15*" --recursive 

If your goal is to synchronize a set of files without copying them twice, use the sync command:

aws s3 sync s3://BUCKET/ folder 

That will copy all files that have been added or modified since the previous sync.

In fact, this is the equivalent of the above cp command:

aws s3 sync s3://BUCKET/ folder --exclude "*" --include "2015-08-15*" 

References:

  • AWS CLI s3 sync command documentation
  • AWS CLI s3 cp command documentation
like image 181
John Rotenstein Avatar answered Sep 20 '22 05:09

John Rotenstein