Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover Deleted Objects From Amazon S3

I have a bucket (version enabled), how can i get back the objects that are accidentally permanent deleted from my bucket.

like image 301
Chaitanya Srivastava Avatar asked Jul 28 '15 13:07

Chaitanya Srivastava


1 Answers

I have created a script to restore the objects with deletemarker. You'll have to input it like below:

sh Undelete_deletemarker.sh bucketname path/to/certain/folder

**Script:**
#!/bin/bash
#please provide the bucketname and path to destination folder to restore
# Remove all versions and delete markers for each object
 aws s3api list-object-versions --bucket $1 --prefix $2 --output text | 
 grep "DELETEMARKERS" | while read obj
   do
        KEY=$( echo $obj| awk '{print $3}')
        VERSION_ID=$( echo $obj | awk '{print $5}')
        echo $KEY
        echo $VERSION_ID
        aws s3api delete-object --bucket $1 --key $KEY --version-id 
        $VERSION_ID

   done

Happy Coding! ;)

like image 54
Kc Bickey Avatar answered Sep 30 '22 01:09

Kc Bickey