Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy file while preserving directory structure using AWS command line

I have the following directory in my local computer:

dir1
  |
  |__ randomfile.jpg
  |__ dir2
        |
        |__ file1.txt
        |__ file2.txt
        |__ pict.png

What I want to do is to copy all the files with *.txt and preserving the subdirectory structure to Amazon S3 bucket. How can I do that?

At the end of the day in S3. We'd like to find this file and directory structure:

 dir1
      |
      |__ dir2
            |
            |__ file1.txt
            |__ file2.txt

With standard Unix command I can do this:

find . -name '*.txt' -exec cp --parents \{\} /target \;

But not sure how to do with with AWS command line.

In reality with have files with ~10Tb of size to transfer.

like image 455
neversaint Avatar asked Feb 06 '17 05:02

neversaint


1 Answers

Just use sync:

aws s3 sync src/ s3://mybucket --exclude "*" --include "*.txt"

Exclude include doc

like image 174
Ôrel Avatar answered Nov 20 '22 00:11

Ôrel