Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to recover a file I deleted from my S3 bucket?

share|improve this question
up vote 16 down vote accepted

According to the Amazon S3 Documentation:

Once deleted, there is no method to restore or undelete an object.

share|improve this answer
    
It's unfortunate S3 doesn't support snapshots. – churnd Mar 24 '10 at 11:40

If you have versioning enable, yes you can! On a versioned bucket, a delete action on a file does not really delete it but it adds a version with a "Delete Marker". You can delete the delete marker with the AWS CLI:

aws s3api delete-object --bucket yourbucket-name --key "yourfile" --version-id id_of_the_delete_marker

You can get all the files in the bucket with

aws --output text s3api list-object-versions --bucket yourbucket-name > files.txt

If you want to undelete all the files in the bucket you can try:

echo '#!/bin/bash' > undeleteScript.sh && aws --output text s3api list-object-versions --bucket yourbucket-name | grep -E "^DELETEMARKERS" | awk '{FS = "[\t]+"; print "aws s3api delete-object --bucket yourbucket-name --key \42"$3"\42 --version-id "$5";"}' >> undeleteScript.sh && . undeleteScript.sh; rm -f undeleteScript.sh;
share|improve this answer
    
I appreciate this answer! Worked flawlessly. – nojak Jan 4 at 22:11
    
this saved my evening. thank you! – Von Landfried Feb 18 at 4:19
    
dude! your undelete all files script just saved my life. thank you. – herostwist Mar 16 at 11:39

Just updating this question as I was looking for the answer:

You can add VERSIONING to S3 buckets now. This will cause S3 to keep versions of an object even after deletion. Full documentation: http://docs.amazonwebservices.com/AmazonS3/latest/dev/Versioning.html

share|improve this answer
    
Is it possible to retrieve a deleted file over AWS Console? Can't find a way to do that. – Rafael Oliveira Jan 30 '14 at 22:25

can someone please help me understand why when i delete the 'delete marker' the object does not return immediately to the bucket ( i need to Reenter to S3 service then to the bucket and then to delete it again) just with this action it's working?!

share|improve this answer
    
This does not answerthe author's question. – Ramhound Jul 21 at 21:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .