{OCI オブジェクト・ストレージ} オブジェクト・ライフサイクル管理

https://docs.oracle.com/ja-jp/iaas/Content/Object/Tasks/usinglifecyclepolicies.htm

https://xn--w8j8bac3czf5bl7e.com/2023/04/24/oci-%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%83%BB%E3%82%B9%E3%83%88%E3%83%AC%E3%83%BC%E3%82%B8-%E3%83%A9%E3%82%A4%E3%83%95%E3%82%B5%E3%82%A4%E3%82%AF%E3%83%AB%E3%83%BB%E3%83%9D/

 

 

-- 1. IAMポリシー設定

-- テナンシのルート・コンパートメントに次のポリシーを作成します:
-- Allow service objectstorage-<region_identifier> to manage object-family in compartment <compartment_name>

 

oci iam policy create \
--compartment-id ocid1.tenancy.oc1..000000000000000000000000000000000000000000000000000000000000 \
--description policy01 \
--name policy01 \
--statements '[
"Allow service objectstorage-us-ashburn-1 to manage object-family in compartment cmp01",
]' 

 

-- 2. バケット作成


oci os bucket list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 

 


oci os bucket create \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--name bucket123 \
--auto-tiering Disabled \
--object-events-enabled false \
--public-access-type NoPublicAccess \
--storage-tier Standard \
--versioning Disabled


-- 3. テストオブジェクト作成


echo test01 > file01.txt
echo test02 > file02.txt
echo test03 > file03.txt

oci os object list \
--bucket-name bucket123


oci os object put \
--bucket-name bucket123 \
--file ./file01.txt \
--name file01.txt \
--content-type "text/plain"

oci os object put \
--bucket-name bucket123 \
--file ./file02.txt \
--name file02.txt \
--content-type "text/plain"

oci os object put \
--bucket-name bucket123 \
--file ./file03.txt \
--name file03.txt \
--content-type "text/plain"

 

-- 4. ライフサイクル・ポリシーの作成

oci os object-lifecycle-policy get \
--bucket-name bucket123 

oci os object-lifecycle-policy put --generate-full-command-json-input


oci os object-lifecycle-policy put \
--bucket-name bucket123 \
--items '[
    {
      "action": "INFREQUENT_ACCESS",
      "isEnabled": true,
      "name": "rule01",
      "objectNameFilter": {
        "exclusionPatterns": null,
        "inclusionPatterns": [
          "*file01*"
        ],
        "inclusionPrefixes": null
      },
      "target": "objects",
      "timeAmount": 1,
      "timeUnit": "DAYS"
    },
    {
      "action": "DELETE",
      "isEnabled": true,
      "name": "rule02",
      "objectNameFilter": {
        "exclusionPatterns": null,
        "inclusionPatterns": [
          "*file02*"
        ],
        "inclusionPrefixes": null
      },
      "target": "objects",
      "timeAmount": 1,
      "timeUnit": "DAYS"
    }
  ]' \
--force 


時間がかかるので動確はしない

 

-- 5. クリーンアップ


oci os bucket list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 

oci os bucket delete \
--name bucket123 \
--empty \
--force