Create a retention policy
You can use a command to create a retention policy.
Usage notes
-
To create a retention policy, you must have the
oss:InitiateBucketWormpermission. For more information, see Attach a custom policy to a RAM user. -
Object Storage Service (OSS) supports the Write Once Read Many (WORM) feature. This feature prevents data from being deleted or modified. You can set a time-based retention policy for a bucket. The retention period can be from 1 day to 70 years.
-
If a time-based retention policy is not locked within 24 hours after it is created, the policy automatically becomes invalid. After the retention policy is locked, you can upload objects to and read objects from the bucket. However, you cannot delete the objects or the retention policy until the retention period expires. For more information about retention policies, see Retention policies.
Command syntax
ossutil api initiate-bucket-worm --bucket value --initiate-worm-configuration value [flags]
|
Parameter |
Type |
Description |
|
--bucket |
string |
The name of the bucket. |
|
--initiate-worm-configuration |
string |
The request body. |
The initiate-bucket-worm command corresponds to the InitiateBucketWorm API operation. For more information about the parameters in the API operation, see InitiateBucketWorm.
--initiate-worm-configuration
The --initiate-worm-configuration option supports both XML and JSON syntax:
-
XML syntax:
<InitiateWormConfiguration> <RetentionPeriodInDays>integer</RetentionPeriodInDays> </InitiateWormConfiguration> -
JSON syntax:
{ "RetentionPeriodInDays": integer }
For more information, see Command-line options.
Examples
Create a retention policy for the examplebucket bucket.
-
You can use an XML configuration file. The following code shows the content of initiate-worm-configuration.xml:
<?xml version="1.0" encoding="UTF-8"?> <InitiateWormConfiguration> <RetentionPeriodInDays>365</RetentionPeriodInDays> </InitiateWormConfiguration>Sample command:
ossutil api initiate-bucket-worm --bucket examplebucket --initiate-worm-configuration file://initiate-worm-configuration.xml -
You can use a JSON configuration file. The following code shows the content of initiate-worm-configuration.json:
{ "RetentionPeriodInDays": "365" }Sample command:
ossutil api initiate-bucket-worm --bucket examplebucket --initiate-worm-configuration file://initiate-worm-configuration.json -
You can use JSON configuration parameters. The following is a sample command:
ossutil api initiate-bucket-worm --bucket examplebucket --initiate-worm-configuration "{\"RetentionPeriodInDays\":\"365\"}"