S3 Sync with "--delete" option is deleting files that have folders with the same name!
If you have a folder in your S3 bucket and a file name that contains the same starting characters as the folder name, the target files will be intermittently be deleted upon each run.
For example, create a folder in your S3 bucket:
s3://my-bucket/test/
Now create some txt files in the bucket with 'test' as the first 4 characters of the file name.. ie:
s3://my-bucket/test-123.txt s3://my-bucket/test-321.txt s3://my-bucket/test.txt
Run aws s3 sync --delete s3://my-bucket /my/local/folder.. Do this 3 or 4 times. You will see each file 'test-123.txt', 'test-321.txt', 'test.txt' will get intermittently be deleted and downloaded with each run. Each run produces different results.
Having files unexpectedly being deleting is a big concern as we use 's3 sync --delete' for daily backup's.
Please see AWS post for originating report https://forums.aws.amazon.com/message.jspa?messageID=497335#497335
I'm trying to repro this and I'm not able to. How are you creating your folder in the first step? I tried first creating a folder in the S3 console (clicking the "Create Folder" button). Then I followed the remaining steps.
touch test-123.txt
touch test-321.txt
touch test.txt
aws s3 cp test-123.txt s3://bucket-name/
aws s3 cp test-321.txt s3://bucket-name/
aws s3 cp test.txt s3://bucket-name/
When I ran s3 sync several times I didn't see anything change:
$ aws s3 sync --delete s3://bucket-name/ /tmp/testsync/
$ aws s3 sync --delete s3://bucket-name/ /tmp/testsync/
$ for i in $(seq 10); do aws s3 sync --delete s3://bucket-name/ /tmp/testsync/; done
S3 still has the same contents:
LastWriteTime Length Name
------------- ------ ----
PRE test/
2013-10-24 17:45:33 0 test-123.txt
2013-10-24 17:45:42 0 test-321.txt
2013-10-24 17:45:47 0 test.txt
and the local dir still has the same contents:
$ ls
test-123.txt test-321.txt test.txt
Perhaps there's a step I'm missing?
Also, what version of the CLI are you using aws --version?
Make sure there is a file within the 'test' folder to reproduce the issue:
touch test/example.txt
Then create your files:
touch test-123.txt
touch test-321.txt
touch test.txt
Now try running aws s3 sync --delete s3://my-bucket /home/username/my-bucket several times
delete: s3://my-bucket/test.txt
delete: s3://my-bucket/test-123.txt
delete: s3://my-bucket/test-321.txt
upload: ../../my-bucket/test-123.txt to s3://my-bucket/test-123.txt
upload: ../../my-bucket/test-321.txt to s3://my-bucket/test-321.txt
upload: ../../my-bucket/test.txt to s3://my-bucket/test.txt
run 2:
delete: s3://my-bucket/test-123.txt
delete: s3://my-bucket/test-321.txt
upload: ../../my-bucket/test-321.txt to s3://my-bucket/test-321.txt
delete: s3://my-bucket/test.txt
upload: ../../my-bucket/test-123.txt to s3://my-bucket/test-123.txt
upload: ../../my-bucket/test.txt to s3://my-bucket/test.txt
...results are different everytime
Version: aws-cli/1.1.0 Python/2.6.8 Linux/3.4.62-53.42.amzn1.x86_64
Also, I just tested reversing the direction of the sync by swapping source and destination... Looks like the same issue is present when sync'ing back up to S3.
Thanks, I'm now able to repro this issue. Working on a fix now.
I had a similar issue with aws-cli/1.15.10 Python/3.6.5 Darwin/15.6.0 botocore/1.10.45 but because of CAPITAL folders name. Basically I had data in my local computer within the folder/ directory but they were stored as s3://bucket-name/FOLDER/.
Each call to aws s3 sync s3://bucket-name/FOLDER folder --delete would remove them and them again in the same folder/ directory
I know this is an older post but the resolution to perfectly sync what you have on your local machine to your bucket all you need to do is add the --delete option to the original sync from your local (source) to your bucket (destination).
aws s3 sync /localfolder s3://bucket-name/localfolder --delete
If the file/folder exists on local it will create it in your bucket and if it no longer exists on local then it will delete it in your bucket. This is the proper way to fully sync (upload) your local to the bucket.