How to restore folders (or entire buckets) to Amazon S3 from Glacier?

后端 未结 10 824
天命终不由人
天命终不由人 2020-12-23 12:47

I changed the lifecycle for a bunch of my buckets on Amazon S3 so their storage class was set to Glacier. I did this using the online AWS Console. I now need those files a

10条回答
  •  半阙折子戏
    2020-12-23 13:28

    Here is my version of the aws cli interface and how to restore data from glacier. I modified some of the above examples to work when the key of the files to be restored contain spaces.

    # Parameters
    BUCKET="my-bucket" # the bucket you want to restore, no s3:// no slashes
    BPATH="path/in/bucket/" # the objects prefix you wish to restore (mind the `/`) 
    DAYS=1 # For how many days you wish to restore the data.
    
    # Restore the objects
    aws s3 ls s3://{BUCKET}/${BPATH} --recursive | \
    awk '{out=""; for(i=4;i<=NF;i++){out=out" "$i}; print out}'| \
    xargs -I {} aws s3api restore-object --restore-request Days={DAYS} \
    --bucket {BUCKET} --key "{}"
    

提交回复
热议问题