Search code examples
amazon-web-servicesamazon-s3amazon-glacier

How do I restore from AWS Glacier back to S3 permanently?


I have about 50Gb worth of files that was stored in S3. Yesterday I stupidly added a lifecycle rule to transfer files that were more than 30 days old from S3 to Glacier not realising that this will disable the public link to the original file.

I actually really need these files to stay in S3 as they are images and drawings that are linked on our website.

I've have requested a restore of the files from Glacier, however as far as I understand this has limits for the number of days that the files will be available for before they go back to Glacier.

I was thinking that I am going to have to create a new bucket, then copy the files across to it and then link that new bucket up to my website.

My questions:

  1. I was wondering if there is a way to do this without having to copy my files to a new bucket?

  2. If I just change the storage class of the file once it is back in S3 will this stop it going back to Glacier?

  3. If I have to copy the files to a new bucket I'm assuming that these copies won't randomly go back to Glacier?

I'm quite new to S3 (as you can probably tell by my bone-headed mistake) so please try to be gentle


Solution

  • You don't need a new bucket. You restore the objects from glacier (temporarily) and then overwrite them using the COPY operation, which essentially creates new objects and they'll stay around. Needless to say, you'll need to disable your aging-away-to-glacier lifecycle.

    Temporary restore:

    aws s3api restore-object --restore-request Days=7 --bucket <bucketName> --key <keyName>
    

    Replace with copied object:

    aws s3 cp s3://bucketName/keyName s3://bucketName/keyName --force-glacier-transfer --storage-class STANDARD
    

    Docs say:

    The transition of objects to the GLACIER storage class is one-way.

    You cannot use a lifecycle configuration rule to convert the storage class of an object from GLACIER to STANDARD or REDUCED_REDUNDANCY storage classes. If you want to change the storage class of an archived object to either STANDARD or REDUCED_REDUNDANCY, you must use the restore operation to make a temporary copy first. Then use the copy operation to overwrite the object as a STANDARD, STANDARD_IA, ONEZONE_IA, or REDUCED_REDUNDANCY object.

    Ref.

    ...going back to Glacier

    Being pedantic for a moment, the archived objects aren't moving between s3 and glacier, they're permanently in glacier and temporary copies are made in S3 - It's important to note that you're paying for both glacier and s3 when you temporarily restore them. Once your retention period expires, the S3 copies are deleted.