Parth Patel
Parth Patel

Reputation: 91

Moving files within amazon s3 bucket

I have uploaded files on s3 bucket. But due to my fault, s3cmd uploaded files on s3://backups/files/bkup14 instead of s3://backups/bkup14. Now for moving all the files under s3://backups/files/bkup14 to s3://backups/bkup14, I tried below command:

s3cmd mv --recursive s3://backups/files/bkup14 s3://backups/bkup14

But it gives me below error:

ERROR: S3 error: 400 (InvalidRequest): This copy request is illegal because it is trying to copy an object to itself without changing the object's metadata, storage class, website redirect location or encryption attributes.

What I am doing wrong here? Can anyone suggest me?

Upvotes: 1

Views: 3015

Answers (1)

George Rushby
George Rushby

Reputation: 1345

Try SYNC the buckets first (alway dry-run first):

s3cmd sync s3://backups/files/bkup14/ s3://backups/bkup14/ --dry-run
s3cmd sync s3://backups/files/bkup14/ s3://backups/bkup14/

then delete the folder that you no longer require:

s3cmd del --recursive s3://backups/files/bkup14 --dry-run
s3cmd del --recursive s3://backups/files/bkup14

AWS S3 bucket namespace is shared by all users of the system, so unless you're extremely lucky to catch the backups bucket your s# bucket is most probably something else.

Below is a example of the above tested and proved.

s3cmd sync s3://backups-stackoverflow-demo/files/bkup14/ s3://backups-stackoverflow-demo/bkup14/ --dry-run
  Summary: 1 source files to copy, 0 files at destination to delete
  Sync: s3://backups-stackoverflow-demo/files/bkup14/test.txt -> s3://backups-stackoverflow-demo/bkup14/test.txt
  WARNING: Exitting now because of --dry-run

s3cmd sync s3://backups-stackoverflow-demo/files/bkup14/ s3://backups-stackoverflow-demo/bkup14/
  Summary: 1 source files to copy, 0 files at destination to delete
  File s3://backups-stackoverflow-demo/files/bkup14/test.txt copied to s3://backups-stackoverflow-demo/bkup14/test.txt
  Done. Copied 1 files in 0.1 seconds, 16.72 files/s

s3cmd del --recursive s3://backups-stackoverflow-demo/files/bkup14 --dry-run
  delete: s3://backups-stackoverflow-demo/files/bkup14/
  delete: s3://backups-stackoverflow-demo/files/bkup14/test.txt
  WARNING: Exitting now because of --dry-run

s3cmd del --recursive s3://backups-stackoverflow-demo/files/bkup14
  File s3://backups-stackoverflow-demo/files/bkup14/ deleted
  File s3://backups-stackoverflow-demo/files/bkup14/test.txt deleted

Upvotes: 2

Related Questions