Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

s3cmd sync is remote copying the wrong files to the wrong locations

I've got the following as part of a shell script to copy site files up to a S3 CDN:

for i in "${S3_ASSET_FOLDERS[@]}"; do
    s3cmd sync -c /path/to/.s3cfg --recursive --acl-public --no-check-md5 --guess-mime-type --verbose --exclude-from=sync_ignore.txt /path/to/local/${i} s3://my.cdn/path/to/remote/${i}
done

Say S3_ASSET_FOLDERS is:

("one/" "two/")

and say both of those folders contain a file called... "script.js"

and say I've made a change to two/script.js - but not touched one/script.js

running the above command will firstly copy the file from /one/ to the correct location, although I've no idea why it thinks it needs to:

INFO: Sending file '/path/to/local/one/script.js', please wait... File '/path/to/local/one/script.js' stored as 's3://my.cdn/path/to/remote/one/script.js' (13551 bytes in 0.1 seconds, 168.22 kB/s) [1 of 0]

... and then a remote copy operation for the second folder:

remote copy: two/script.js -> script.js

What's it doing? Why?? Those files aren't even similar. Different modified times, different checksums. No relation.

And I end up with an s3 bucket with two incorrect files in. The file in /two/ that should have been updated, hasn't. And the file in /one/ that shouldn't have changed is now overwritten with the contents of /two/script.js

Clearly I'm doing something bizarrely stupid because I don't see anyone else having the same issue. But I've no idea what??

like image 248
Wintermute Avatar asked Mar 04 '14 13:03

Wintermute


1 Answers

First of all, try to run it without --no-check-md5 option.
Second, I suggest you to pay attention to directory names, specifically trailing slashes.
s3cmd documentation says:

With directories there is one thing to watch out for – you can either upload the directory and its contents or just the contents. It all depends on how you specify the source. To upload a directory and keep its name on the remote side specify the source without the trailing slash On the other hand to upload just the contents, specify the directory it with a trailing slash

like image 160
user2256686 Avatar answered Oct 04 '22 03:10

user2256686