Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying files between s3 buckets without folders amazon aws cli

I'm looking through the documentation of aws cli and I cannot find the way to copy the only files in some directory structure to other bucket with "flattened" structure(I want one directory and all files inside of it).

for example

/a/b/c/1.pg
/a/2.jpg
/a/b/3.jpg

i would want to have in different bucket:

/x/1.jpg
/x/2.jpg
/x/3.jpg

Am I missing something or is it impossible? Do you have an idea how could I do that?

like image 923
fr3ak Avatar asked Oct 21 '25 16:10

fr3ak


1 Answers

Assuming that you have aws cli configured on the system and assuming that both the buckets are in the same region. What you can do is first dowload the s3 bucket to your local machine using:

aws s3 sync s3://originbucket /localdir/

Post this, use a find command to get all the files into one dir

find /localdir/ -type f -exec mv {} /anotherlocaldir/

Finally, you can upload the files to s3 again!

aws s3 sync /anotherlocaldir/ s3://destinationbucket
like image 92
Karan Shah Avatar answered Oct 23 '25 07:10

Karan Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!