Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 sync --delete, removed new files in local

aws s3 sync --delete removed some new files.

For example:

There is a file in the bucket - S3://my-bucket/images/1.jpg

Then, I uploaded a file to the server: 2.jpg

There are 2 files in the server: 1.jpg and 2.jpg

Start running the sync cronjob:

aws s3 sync s3://my-bucket/ ./ --delete aws s3 sync  ./ s3://my-bucket/ --delete 

Why do we add --delete - we want to delete the files in s3 and sync it to the server.

We will upload files to the server and remove the files in s3.

Is there any way to fix it?

like image 360
Keith Kong Avatar asked Jun 02 '15 09:06

Keith Kong


People also ask

Does aws S3 sync delete files?

Does AWS S3 sync delete files? The AWS S3 Sync command does not delete files, but rather copies any new or modified files between a source and target destination. What is this? Files can be deleted by using the —delete command in conjunction with the AWS S3 sync command.

Does aws sync delete?

aws sync is not used for deleting the files, it only copies or modifies the files. -- delete is used to delete files from the destination and not from the source or rather deletes the files that are not present in S3.

Does aws S3 sync overwrite files?

It only copies files that have been added or changed since the last sync. It is designed as a one-way sync, not a two-way sync. Your file is being overwritten because the file in the Source is not present in the Destination. This is correct behavior.

Does S3 sync copy locally?

The aws s3 sync command will, by default, copy a whole directory. It will only copy new/modified files. Just experiment to get the result you want.


2 Answers

By default, the aws sync command (see documentation) does not delete files. It simply copies new or modified files to the destination.

Using the --delete option deletes files that exist in the destination but not in the source.

So, if your source contains: 1.jpg and 2.jpg and the destination contains 1.jpg, 2.jpg and 3.jpg, then using the --delete option will delete 3.jpg from the destination.

I see that you are running the sync command in both directions. Your first command (that syncs S3 to a local directory) will delete any local files that are not in S3.

If your goal is to copy all local files to S3 and all S3 files to the local directory, without deleting any files, then do not use the --delete option.

like image 76
John Rotenstein Avatar answered Sep 24 '22 23:09

John Rotenstein


--delete option to remove files or objects from the target not present in the source.

like image 30
sarat chandra Avatar answered Sep 24 '22 23:09

sarat chandra