# AWS - 大規模從 S3 Glacier 復原回 Standard

# 前言

最近工作上剛好遇到需求，需要將整批的物件從 S3 Glacier Deep Archive 中復原回 Standard。而這項操作需要用到兩項主要的服務：Inventory report 和 Batch operation。

## 先決條件

需要先到需要復原的物件的 Bucket 中設定 Inventory report，會需要在某個 S3 bucket 中存放 Inventory report，如果是要跨不同的 Bucket，可以考慮自己編寫。

然後因為會需要提供 IAM Role 給 Batch operation 做授權，所以寫需要建立一個有權限做存取 S3 的 IAM Role

## 操作執行

因為 Glacier 的 Storage class 是無法直接存取的，所以我們需要間執行 Restore 的操作。然後再依照 Inventory report 做 Copy 將這些檔案複製到 Standard 的 Storage class。

因此實際上會有兩個 Batch operation 的 Job 來執行：

1. 建立 Job 執行 Restore（有分 Bulk 和 Standard，Bulk 比較慢最慢 48 小時，Standard 最慢 12 小時）
2. 建立 Job 依照 Inventory report 將這些檔案複製到 Standard

## 後續注意

因為 Bucket 中 Inventory report 的設定會有 daily 和 weekly，如果只是要一次性的話記得關閉或刪除。因為他其實是用複製的，所以 Glacier 中封存的檔案還是存在（除非你指定複製的地點是原本的地方，那就會蓋過去）。再來要注意的就是時間了，光是 Restore 最快也是要等 12 小時。因此如果是想要封存但是至少一季內都還會用到的話，建議先到 Glacier Instant Retrieval 的層集就夠了，因為這樣不需要 Restore 即可存取。

## Reference

- [How can I initiate restores for a large volume of Amazon S3 objects that are currently in the S3 Glacier or S3 Glacier Deep Archive storage class?](https://aws.amazon.com/premiumsupport/knowledge-center/s3-batch-operation-initiate-restore/?nc1=h_ls)
