I'm currently writing a script to sync files in s3 buckets with s3cmd.
I check the document and it says:
s3cmd sync LOCAL_DIR s3://BUCKET[/PREFIX] or s3://BUCKET[/PREFIX] LOCAL_DIR
also I find a nice option:
--delete-removed
Delete remote objects with no corresponding local file [sync]
I tested on the first form of s3cmd sync with --delete-removed:
s3cmd sync -r --delete-removed LOCAL_DIR s3://BUCKET[/PREFIX]
It works like a charm that s3 bucket will delete any files not in my LOCAL_DIR
However when I try the second form:
s3cmd sync -r --delete-removed s3://BUCKET[/PREFIX] LOCAL_DIR
The s3cmd seems first to delete all my files under LOCAL_DIR and then download files from s3 bucket to my LOCAL_DIR
It is apparently a waste of time, so is there another better way to sync without deleting all my local files first. That is, copy all files from s3 bucket to my local dir exactly