Creating the Object Lifecycle Policy in Object Storage

Create the object lifecycle policy for an Object Storage bucket.

    1. Open the navigation menu and click Storage. Under Object Storage & Archive Storage, click Buckets.
    2. Select the compartment from the list under List Scope. All buckets in that compartment are listed in tabular form.
    3. Click the bucket for which you're creating a lifecycle policy rule. The bucket's Details page appears.
    4. Click Lifecycle Policy Rules under Resources. The Lifecycle Policy Rules list appears. All lifecycle policy rules are listed in tabular form.
    5. Click Create Rule. The Create Lifecycle Rule dialog box appears.

      The Console checks the IAM policies that are in place to perform this task successfully. If you see a policy missing warning, you can let the Console try to create any missing policies or copy the missing policy details to the clipboard to email your administrator. If you have the required policies in place, create the lifecycle policy rule.

    6. Complete the following:
      • Name: Enter a name or accept the default system name. The system generates a rule name that reflects the current year, month, day, and time, for example, lifecycle-rule-20190321-1559. If you change this name, use letters, numbers, dashes, underscores, and periods.

      • Target: Select the target to which the lifecycle rule applies:

        • If object versioning is disabled, select Objects or Uncommitted Multipart Uploads.

        • If object versioning is enabled or suspended, select Latest Version of Objects, Previous Versions of Objects, or Uncommitted Multipart Uploads.

      • Lifecycle Action: Select one of the following actions:

        • If the rule target is Objects, Latest Version of Objects, or Previous Versions of Objects, select Move to Archive, Move to Infrequent Access, or Delete. If auto-tiering is enabled on the bucket, Move to Infrequent Access isn't available for selection.

        • If the rule target is Uncommitted Multipart Uploads, Delete is the only option and is selected by default.

      • Number of Days: Enter the number of days until the specified action is taken.

      Note

      If the rule archives or deletes a previous object version, the "number of days" countdown is based on when the object version transitioned from being the latest object version to being a previous object version. You can determine this time by looking at the "last modified" time of the previous most recent version of the object.

    7. If the rule target is Objects, Latest Version of Objects, or Previous Versions of Objects, you can optionally add one or more object name filters to specify which objects the lifecycle rule applies to. You can choose objects or object versions by using prefixes and pattern matching. If no object name filters are specified, the rule applies to all objects in the bucket.

      To create an object name filter:

      1. Click Add Filter.

      2. Select the filter type.

      3. Enter the filter value.

      Click Add Another Filter to add more filters to this rule. Click the X next to a filter to remove it.

    8. Use the State switch to specify whether the rule is enabled or disabled after it's created.
    9. Click Create.
      Tip

      To enable or disable the rule, click the Actions menu (Actions Menu) next to the rule and select Enable or Disable.

    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.

    The items 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 for action:
    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 for target:
    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.