Creates a Write Once Read Many (WORM) retention policy for a bucket. The policy prevents objects from being deleted or overwritten for a specified retention period of 1 day to 70 years.
Once locked, a retention policy cannot be deleted or shortened. Lock only after you have verified the retention period.
Prerequisites
Before you begin, ensure that you have:
The
oss:InitiateBucketWormpermission. For more information, see Attach a custom policy to a RAM user.A bucket without versioning enabled. Versioning and retention policies cannot coexist on the same bucket.
Usage notes
A newly created retention policy is unlocked. If you do not lock it within 24 hours, it becomes invalid.
After the policy is locked, you can read objects from and upload objects to the bucket, but you cannot delete objects or the policy until the retention period expires.
For background on how retention policies work, see Retention policies.
Command syntax
ossutil api initiate-bucket-worm --bucket <bucket-name> --initiate-worm-configuration <config> [flags]initiate-bucket-worm is the ossutil equivalent of the InitiateBucketWorm API operation. For available flags, see Command-line options.Parameters
| Parameter | Type | Description |
|---|---|---|
--bucket | string | The bucket name. |
--initiate-worm-configuration | string | The retention policy configuration. Accepts XML or JSON format (see below). |
--initiate-worm-configuration formats
XML:
<InitiateWormConfiguration>
<RetentionPeriodInDays>integer</RetentionPeriodInDays>
</InitiateWormConfiguration>JSON:
{
"RetentionPeriodInDays": integer
}RetentionPeriodInDays accepts any integer from 1 day to 70 years.
Examples
The following examples create a 365-day retention policy for examplebucket.
Using an XML configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<InitiateWormConfiguration>
<RetentionPeriodInDays>365</RetentionPeriodInDays>
</InitiateWormConfiguration>ossutil api initiate-bucket-worm --bucket examplebucket --initiate-worm-configuration file://initiate-worm-configuration.xmlUsing a JSON configuration file:
{
"RetentionPeriodInDays": "365"
}ossutil api initiate-bucket-worm --bucket examplebucket --initiate-worm-configuration file://initiate-worm-configuration.jsonUsing inline JSON:
ossutil api initiate-bucket-worm --bucket examplebucket --initiate-worm-configuration "{\"RetentionPeriodInDays\":\"365\"}"What's next
After you create the policy, lock it within 24 hours to activate protection. For instructions, see Lock a retention policy.