Creating the Object Lifecycle Policy in Object Storage
Create the object lifecycle policy for an Object Storage bucket.
The rule appears in the Lifecycle Policy Rules list.
Use the oci os object-lifecycle-policy put command and required parameters to create the object lifecycle policy for a bucket:
oci os object-lifecycle-policy put --bucket-name bucket_name [OPTIONS]
Specifying the Lifecycle Policy Rules
Use the
items
parameter to specify the bucket's set of lifecycle policy rules:oci os object-lifecycle-policy put --bucket-name bucket_name --items json_formatted_lifecycle_policy
The
items
parameter requires that you provide key-value pair input as valid formatted JSON. See Passing Complex Input and Using a JSON File for Complex Input for information about JSON formatting.Theitems
key-value pair input must specify the following:[ { "action": "string", "isEnabled": true, "name": "string", "objectNameFilter": { "exclusionPatterns": [ "string", "string" ], "inclusionPatterns": [ "string", "string" ], "inclusionPrefixes": [ "string", "string" ] }, "target": "string", "timeAmount": 0, "timeUnit": "string" } ]
Specify one of the following values foraction
:Value Description ARCHIVE
Specify this action to move objects, object versions, or previous object versions to the Archive tier. INFREQUENT_ACCESS
Specify this action to move objects, object versions, or previous object versions to the Infrequent Access tier. If Auto-Tiering is enabled on the bucket, you can't specify INFREQUENT_ACCESS
.DELETE
Specify this action to delete objects, object versions, or object versions. ABORT
Use this action to delete failed or incomplete multipart uploads. Specify one of the following values fortarget
:Value Description objects
Use this action to move objects, object versions, or previous object versions to the Archive tier. object-versions
Use this action to move objects, object versions, or previous object versions to the Infrequent Access tier. multipart-uploads
Use this action to delete objects, object versions, or previous object versions. Specify
timeUnit
in days.The following example creates or replaces a lifecycle policy that includes a rule for moving previous object versions with names that include the pattern
*.doc
from the Standard tier to the Archive tier after 60 days. The policy also includes a rule that deletes previous object versions after 180 days.oci os object-lifecycle-policy put --bucket-name MyStandardBucket --items '[ { "action": "ARCHIVE", "is-enabled": true, "name": "Move-to-Archive-Rule", "object-name-filter": { "exclusion-patterns": null, "inclusion-patterns": [ "*.doc" ], "inclusion-prefixes": null }, "target": "previous-object-versions", "time-amount": 60, "time-unit": "DAYS" }, { "action": "DELETE", "is-enabled": true, "name": "Delete-Rule", "object-name-filter": { "exclusion-patterns": null, "inclusion-patterns": [ "*.doc" ], "inclusion-prefixes": null }, "target": "previous-object-versions", "time-amount": 180, "time-unit": "DAYS" } ]'
The following example creates or replaces a lifecycle policy that includes a rule for moving all objects from the Standard tier to the Infrequent Access tier after 45 days. The policy also includes a rule that moves all objects to the Archive tier after 90 days.
oci os object-lifecycle-policy put --bucket-name MyStandardTierBucket --items '[ { "action": "INFREQUENT_ACCESS", "is-enabled": true, "name": "Move-to-Infrequent-Access-Rule", "object-name-filter": null, "target": "objects", "time-amount": 45, "time-unit": "DAYS" }, { "action": "ARCHIVE", "is-enabled": true, "name": "Move-to-Archive-Rule", "object-name-filter": null, "target": "objects", "time-amount": 90, "time-unit": "DAYS" } ]'
The following example creates or replaces a lifecycle policy rule that deletes previous object versions from the Archive tier after 240 days.
oci os object-lifecycle-policy put --bucket-name MyArchiveTierBucket --items '[ { "action": "DELETE", "is-enabled": true, "name": "Delete-from-Archive-Rule", "object-name-filter": null, "target": "previous-object-versions", "time-amount": 240, "time-unit": "DAYS" } ]'
The following example creates or replaces a lifecycle policy rule that deletes all uncommitted or failed multipart uploads after 5 days:
oci os object-lifecycle-policy put --bucket-name MyBucket --items '[ { "action": "ABORT", "is-enabled": true, "name": "Delete-Failed-Multipart-Uploads-Rule", "object-name-filter": null, "target": "multipart-uploads", "time-amount": 5, "time-unit": "DAYS" } ]'
Instead of using the
items
option, you can pass the JSON key-value pairs in a file. For example:oci os object-lifecycle-policy put --bucket-name MyStandardTierBucket --file /path/to/file/filename
Using Windows
On Windows, to pass complex input to the CLI as a JSON string, you must enclose the entire block in double quotes. Inside the block, each double quote for the key and value strings must be escaped with a backslash (\) character.For example:
oci os object-lifecycle-policy put --bucket-name MyStandardTierBucket --items "[{\"action\":\"ARCHIVE\",\"isEnabled\":true,\"name\":\"move-to-Archive-rule\",\"target\":\"previous-object-versions\",\"timeAmount\":180,\"timeUnit\":\"DAYS\"}]"
For a complete list of parameters and values for CLI commands, see the CLI Command Reference.
Run the PutObjectLifecyclePolicy operation to create the object lifecycle policy for a bucket.