Restoring Amazon S3 files that are not versioned - amazon-web-services

Unfortunately, this morning I accidentally deleted a number of images from my S3 account, and I need to restore them. I have read about versioning, however this was not enabled on the bucket at the time of deletion (I have now enabled).
Is there any way of restoring these files either manually, or via Amazon directly?
Thanks,
Pete

Unfortunately, I don't think you can. Here is what AWS says in their docs -
To be able to undelete a deleted object, you must have had versioning
enabled on the bucket that contains the object before the object was
deleted.

Related

AWS S3 automated file upload

I wanted to automate the process of copying files between two S3 buckets.
scenario: whenever the same files are getting uploaded to S3(first bucket) the older versions of the file should be moved to another S3 bucket(second S3) and only the newer version file should reside in the first bucket. Please suggest to me the process of doing this
I don’t know if there is a direct way, but I want to use shell scripts to achieve:
aws s3 cp s3://newfile/ s3://backupfile --recursive
aws s3 cp /Local/file s3://newfile/ --recursive
When an object is uploaded to Amazon S3 with the same Key (filename) as an existing object, the new object will overwrite the existing object.
This can be avoided by activating Versioning on the bucket, which will retain all versions of an object. So, if a new object is uploaded with the same Key, then the old object becomes a 'previous version' and is still accessible in S3. (You will pay for the storage of all versions.)
If your requirements are to preserve previous versions of objects, then this should be sufficient for your need, without having to copy the older version to a different bucket.
If you really wanted to do as you ask, then you would need:
Versioning turned on (to preserve older versions)
An AWS Lambda function that is triggered by the upload that will copy the old version to a different bucket and optionally delete the 'old version'
A plan for what to do when there is another upload of the same object -- should it copy it to the 'other bucket' and overwrite the older version that is already there? It might need Versioning too!

how do i backup s3 or is it possible to backup s3?

does s3 have snapshots? how should I solve a problem where something would, for example, delete all my s3 data, how do I backup?
There are a couple options.
1. Enable versioning on your bucket. Every version of the objects will be retained. Deleting an object will just add a "delete marker" to indicate the object was deleted. You will pay for the storage of all the versions. Note that versions can also be deleted.
2. If you are just worried about deletion you can add a bucket policy to prevent deletion. You can also use some of the newer hold options.
3. You can use cross region replication to copy the objects to a bucket in a different region and optionally a different account.

Can I restore S3 objects from deleted folder with glacier storage class

I recently deleted by error a complete folder in an S3 bucket without versioning activated. This folder used to have a lifecycle policy, a lot of objects were in a glacier state. Now I can't find them, event in a vault.
Can I retrieve the deleted folder or is it a lost cause?
Unfortunately, I believe if you didn't have versioning running on the bucket to the best of my knowledge you cannot recover the items.
As stated on https://docs.aws.amazon.com/AmazonS3/latest/user-guide/undelete-objects.html
"To be able to undelete a deleted object, you must have had versioning
enabled on the bucket that contains the object before the object was
deleted."

Lifecycle policy on S3 bucket

I have an S3 bucket on which I've configured a Lifecycle policy which says to archive all objects in the bucket after 1 day(s) (since I want to keep the files in there temporarily but if there are no issues then it is fine to archive them and not have to pay for the S3 storage)
However I have noticed there are some files in that bucket that were created in February ..
So .. am I right in thinking that if you select 'Archive' as the lifecycle option, that means "copy-to-glacier-and-then-delete-from-S3"? In which case this issue of the files left from February would be a fault - since they haven't been?
Only I saw there is another option - 'Archive and then Delete' - but I assume that means "copy-to-glacier-and-then-delete-from-glacier" - which I don't want.
Has anyone else had issues with S3 -> Glacier?
What you describe sounds normal. Check the storage class of the objects.
The correct way to understand the S3/Glacier integration is the S3 is the "customer" of Glacier -- not you -- and Glacier is a back-end storage provider for S3. Your relationship is still with S3 (if you go into Glacier in the console, your stuff isn't visible there, if S3 put it in Glacier).
When S3 archives an object to Glacier, the object is still logically "in" the bucket and is still an S3 object, and visible in the S3 console, but can't be downloaded from S3 because S3 has migrated it to a different backing store.
The difference you should see in the console is that objects will have A "storage class" of Glacier instead of the usual Standard or Reduced Redundancy. They don't disappear from there.
To access the object later, you ask S3 to initiate a restore from Glacier, which S3 does... but the object is still in Glacier at that point, with S3 holding a temporary copy, which it will again purge after some number of days.
Note that your attempt at saving may be a little bit off target if you do not intend to keep these files for 3 months, because any time you delete an object from Glacier, you are billed for the remainder of the three months, if that object has been in Glacier for a shorter time than that.

How do I restore an entire S3 bucket from Glacier permanently?

A while ago when the price difference between standard storage and glacier was closer to 10:1 than 3:1, I moved a couple of bucket completely to Glacier using a life-cycle policy. Admittedly, I hadn't investigated how to reverse that process permanently.
I know the documentation states that I would have to "use the copy operation to overwrite the object as a Standard or RRS object", but I guess I'm unclear what that looks like. Do I just copy and paste within that bucket?
Restoration can only be done at the Object level, not Bucket or Folder. When an object is restored, it is a available in Amazon S3 for the period requested (eg 2 days), then reverts to only being in Glacier. You'll need to copy the objects out of the bucket during that time to keep a copy of them in S3.
The easiest method would be to use a utility to restore multiple Objects for you, eg:
How to restore whole directories from Glacier?
Also, see Stackoverflow: How to restore folders (or entire buckets) to Amazon S3 from Glacier?