One Way Sync of a Bucket With Local Directory

amazon s3s3cmd

I have a local directory that I would like to synchronize with an S3 bucket.
I have two specific requirements:

  1. If local file is the same as the remote, do not re-transfer it to the bucket.
  2. If some files or directories exist in the bucket but do not exist on local, delete them. Basically the bucket should mirror the local copy and not vice-versa.

I looked into s3cmd sync command, but unfortunately requirement 2 is not fulfilled. If files exists in the bucket but not on local copy, they will be copied to the local instead of being deleted.

Best Answer

I finally found an answer by looking further in the s3cmd manual. It turns out that there are options that alter the behaviour of the commands. One option is --delete-removed which alters sync in the way I want:

--delete-removed

         Delete remote objects with no corresponding local file [sync]