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

Add --no-overwrite option to aws s3 cp/mv

Open alexjurkiewicz opened this issue 7 years ago • 67 comments

It would be nice to have a convenience function --no-overwrite for aws s3 cp/mv commands, which would check the target destination doesn't already exist before putting a file into an s3 bucket.

Of course this logic couldn't be guaranteed by the AWS API (afaik...) and is vulnerable to race conditions, etc. But it would be helpful to prevent unintentional mistakes!

alexjurkiewicz avatar Oct 06 '17 03:10 alexjurkiewicz

Marking as a feature request. The tricky part if we did it in cp or mv is that the CLI may have to query S3 to see if the file exists before trying to upload it. So it may make more sense to add it to sync as it already does that.

kyleknap avatar Oct 06 '17 20:10 kyleknap

I'd like to see this in cp and/or mv as well.

The reason I don't use sync for this right now is that sync has major performance problems if the destination bucket has a lot of existing files under the target directory.

When you run aws s3 cp --recursive newdir s3://bucket/parentdir/, it only visits each of the files it's actually copying.

When you run aws s3 sync newdir s3://bucket/parentdir/, it visits the files it's copying, but also walks the entire list of files in s3://bucket/parentdir (which may already contain thousands or millions of files) and gets metadata for each existing file.

On a sufficiently large destination bucket, aws s3 cp --recursive can take seconds and aws s3 sync can take hours to copy the same data.

Obviously fixing sync would be nice, but if adding a "check to see if the file already exists" query to cp is a more tractable problem than revamping the sync code to make it fast, it might make sense to do that instead.

sgrimm-sg avatar Oct 21 '17 03:10 sgrimm-sg

I'm also very interested in this feature. An optional interactive prompt for overwriting files would also be nice to have.

slavaaaaaaaaaa avatar Nov 21 '17 17:11 slavaaaaaaaaaa

yes @sgrimm-sg, it makes sense. I am also interested to see CLI cp command which can actually handle these conditions.

shabeebk avatar Dec 21 '17 08:12 shabeebk

It would be extremely useful for this to be an option on aws s3 sync. rsync has this functionality available as --ignore-existing. My preference would be try to use the same option names as rsync as I suspect there are a lot of folks already familiar with rsync.

jhoblitt avatar Jan 29 '18 16:01 jhoblitt

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

This entry can specifically be found on UserVoice at: https://aws.uservoice.com/forums/598381-aws-command-line-interface/suggestions/33168406-add-no-overwrite-option-to-aws-s3-cp-mv

ASayre avatar Feb 06 '18 10:02 ASayre

Related:

kenorb avatar Feb 13 '18 12:02 kenorb

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

jamesls avatar Apr 06 '18 19:04 jamesls

@jamesls that's great! can you please respond to the suggest at hand? --no-overwrite would be a great addition and it will avoid wrapping the calls with scripts

guyisra avatar Oct 21 '18 10:10 guyisra

+1 to this issue. I propose -n, --no-clobber to match existing Linux cp command options.

evanstucker-hates-2fa avatar Dec 05 '18 20:12 evanstucker-hates-2fa

Has there been any implementation of this request? Trying to work with Windows batch files to do local backup > S3, this is the easiest methods, a simple no-overwrite or similar flag.

CaptainPalapa avatar Feb 12 '19 15:02 CaptainPalapa

Any update regarding this feature?

adiii717 avatar Feb 26 '19 09:02 adiii717

Any update regarding this feature ? Thanks

julio75012 avatar Mar 04 '19 02:03 julio75012

Any update regarding this feature?

noelnamai avatar Mar 22 '19 22:03 noelnamai

Any update regarding this feature?

avanier avatar May 02 '19 20:05 avanier

sev3, +1

pgolebiowski avatar May 13 '19 13:05 pgolebiowski

Really need this feature added as S3 sync does not seem to upload every file.

southpaw5271 avatar Jun 07 '19 15:06 southpaw5271

Any updates or workarounds?

mehmetfazil avatar Jun 18 '19 08:06 mehmetfazil

Any updates or workarounds?

I had to write a python script to load all of the items in the bucket into an array (list), then load all the items from the directory I want to sync, then compare the arrays and upload the local items not in the S3 array.

southpaw5271 avatar Jun 18 '19 13:06 southpaw5271

I had to write a python script to load all of the items in the bucket into an array (list), then load all the items from the directory I want to sync, then compare the arrays and upload the local items not in the S3 array.

@southpaw5271 - care to share your script and save me some time ? ; )

kevb avatar Jul 04 '19 09:07 kevb

I had to write a python script to load all of the items in the bucket into an array (list), then load all the items from the directory I want to sync, then compare the arrays and upload the local items not in the S3 array.

@southpaw5271 - care to share your script and save me some time ? ; )

I don't seem to have it anymore :( Sorry!

southpaw5271 avatar Jul 08 '19 13:07 southpaw5271

This flag would also be valuable for the cp command, since sync does not allow to copy a file while changing the destination name.

aws s3 cp --no-overwrite ./somefile s3://bucket/othername

mpdude avatar Aug 28 '19 06:08 mpdude

We also need the --no-overwrite option from s3 to local. We've been burned by accidental overwrites from well-meaning individuals, and this would be a very much appreciated way to put up a "guardrail" for them. Thanks!

RobElEmYew avatar Nov 07 '19 00:11 RobElEmYew

any update?

EralpB avatar Jan 13 '20 11:01 EralpB

Any update regarding this feature? Thank you

cbachhuber avatar Feb 05 '20 07:02 cbachhuber

+1

danielwhatmuff avatar Mar 26 '20 07:03 danielwhatmuff

+1

I'm migrating files from old system. I have a python script that generates different paths according to db columns (ie each org has now its own folder on specific bucket), so I cant rely on sync command. I could run a script to do partial migrations if a -skip-duplicate or some sort of parameter would be available.

dsovino-alma avatar Apr 05 '20 17:04 dsovino-alma

+1

plastic-abubakr avatar May 13 '20 20:05 plastic-abubakr

This is badly needed. Why is it not already there?

rjurney avatar May 19 '20 00:05 rjurney

+1

ghost avatar May 22 '20 17:05 ghost