aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

aws s3 sync --delete: delete files _after_ uploading

Open tusbar opened this issue 10 years ago • 11 comments

Hello,

With awscli==1.7.37, when using s3 sync --delete, is there a way to have the files be deleted after the rest is uploaded? It seems like they’re always deleted before uploading.

$ aws s3 sync --delete dist s3://bucket
delete: s3://bucket/scripts/bundle.65406bc3e1133110.js
upload: dist/index.html to s3://bucket/index.html
upload: dist/scripts/bundle.9ad9b21077147aa5.js to s3://bucket/scripts/bundle.9ad9b21077147aa5.js
upload: dist/styles/bundle.6de17660ab595a44.css to s3://bucket/styles/bundle.6de17660ab595a44.css

tusbar avatar Jul 09 '15 17:07 tusbar

What's the reasoning for waiting to delete until after all uploads are complete? If we did that, then we'd have to keep every delete request in memory, which could consume a large amount of memory for large buckets.

mtdowling avatar Jul 09 '15 17:07 mtdowling

@mtdowling all the reasoning that’s behind rsync’s --delete-after.

For example, if the transfer fails while syncing, let’s say right after the delete, I’ve deleted the old files, but haven’t added any of the new, which could be a problem.

tusbar avatar Jul 09 '15 18:07 tusbar

Interesting. I suppose we could also evaluate adding other delete strategies similar to the delete options offered by rsync. I'll mark this as a feature request, and we'll add it to our backlog.

mtdowling avatar Jul 09 '15 18:07 mtdowling

A quick workaround is to run the sync command twice, once without --delete, then with the --delete flag.

tusbar avatar Jul 15 '15 09:07 tusbar

Good Morning!

We're closing this issue here on GitHub, as part of our migration to UserVoice for feature requests involving the AWS CLI.

This will let us get the most important features to you, by making it easier to search for and show support for the features you care the most about, without diluting the conversation with bug reports.

As a quick UserVoice primer (if not already familiar): after an idea is posted, people can vote on the ideas, and the product team will be responding directly to the most popular suggestions.

We’ve imported existing feature requests from GitHub - Search for this issue there!

And don't worry, this issue will still exist on GitHub for posterity's sake. As it’s a text-only import of the original post into UserVoice, we’ll still be keeping in mind the comments and discussion that already exist here on the GitHub issue.

GitHub will remain the channel for reporting bugs.

Once again, this issue can now be found by searching for the title on: https://aws.uservoice.com/forums/598381-aws-command-line-interface

-The AWS SDKs & Tools Team

ASayre avatar Feb 06 '18 10:02 ASayre

Based on community feedback, we have decided to return feature requests to GitHub issues.

jamesls avatar Apr 06 '18 21:04 jamesls

Any updates on this? the feature delete_after is important IMHO in order to clean up source systems that have been synced

mehditlili avatar Aug 16 '18 14:08 mehditlili

@mehditlili use rclone instead.

tusbar avatar Aug 16 '18 14:08 tusbar

Run your command twice, second time with --delete will delete the files after and won't re-upload the files the second time you run it.

balloob avatar Jul 26 '19 05:07 balloob

Run your command twice, second time with --delete will delete the files after and won't re-upload the files the second time you run it.

That's a nice workaround! However it is slower than if the command was run once with the deletes at the end.

lcswillems avatar May 16 '22 11:05 lcswillems

@mehditlili use rclone instead.

Thank you for sharing this holy grail! This is exactly what I needed - rclone delete-after.

For deploying a static website to S3, I can safely say that storing the website's content in memory due to delete-after, which usually takes up to 30MB (depending on the website), is ok.

Thanks again!

unfor19 avatar Sep 13 '22 21:09 unfor19