Copy files in thumbnail folder to a secondary location for Amazon S3

Hello all! I am trying to create a script that will copy files from one location, to another but only folders that are filled with thumbnails to an exact directory replica in the second location. For example:

/images/2012/01/19/Event/Photographer/thumbnails

to

/amazon/2012/01/19/Event/Photographer/thumbnails

I'm assuming there's a way with the copy command with the -u argument so that it only updates files that are newer in the source directory. There are photos in the photographer folder that I don't want transferred to the Amazon folder. I'd rather serve a few large images from my server but reap the benefits of CloudFront for all my thumbnails.

if your copy command supports -u option, you can just try

cp -R -u /images/2012/01/19/Event/Photographer/thumbnails /amazon/2012/01/19/Event/Photographer/thumbnails

Thanks for the response rdcwayx! :smiley:

I should have clarified in my first post that I have multiple directories that I want to crawl through and transfer all thumbnail folders over to. For example:

/images/2012/01/19/Event/Photographer/thumbnails
/images/2008/10/27/AnotherEvent/AnotherPhotographer/thumbnails
/images/2009/02/08/YetAnotherEvent/ADifferentPhotographer/thumbnails
etc.

I need to go through every directory and if a directory has a thumbnail folder, mimic the directory structure of the /images folder in the /amazon folder for only the thumbnail folder.. :wall:

find / -type d -name "thumbnail" |while read folder
do
  dir=$(echo $folder|sed "s/images/amazon/")
  mkdir -p $dir
  cp -u $folder $dir
done
1 Like

Awesome rdcwayx! That worked marveously! I had to change the / in the find function to the correct directory with the initial images but then it worked flawlessly! :smiley: