• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (PHP SDK)
  4. Lifecycle Management
  5. Setting Lifecycle Rules

Setting Lifecycle Rules

You can call ObsClient->setBucketLifecycleConfiguration to set lifecycle rules for a bucket.

Setting an Object Transition Policy

Sample code:
// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',         
       'endpoint' => 'https://yourdomainname'
] );

$resp = $obsClient->setBucketLifecycleConfiguration ( [ 
       'Bucket' => 'bucketname',
       'Rules' => [ 
                     [ 
                           'ID' => 'rule1',
                           'Prefix' => 'prefix1',
                           'Status' => 'Enabled',
                           // Specify that objects whose names contain the prefix will be transited to OBS Warm after being created for 30 days.
                           'Transitions' => [ 
                                 [
                                     'StorageClass' => ObsClient::StorageClassWarm,
                                     'Days' => 30
                                 ] 
                           ],
                           // Specify that objects whose names contain the prefix will be transited to OBS Cold after becoming noncurrent versions for 30 days.
                           'NoncurrentVersionTransitions' => [ 
                                 [
                                     'StorageClass' => ObsClient::StorageClassCold,
                                     'NoncurrentDays' => 30
                                 ]                                        
                           ] 
                     ],
                     [ 
                           'ID' => 'rule2',
                           'Prefix' => 'prefix2',
                           'Status' => 'Enabled',
                           // Specify the date when objects whose names contain the prefix will be transited to OBS Warm.
                           'Transitions' => [ 
                                    [
                                        'StorageClass' => ObsClient::StorageClassWarm,
                                        'Date' => '2018-12-31T00:00:00Z'
                                    ]                                       
                           ] 
                     ] 
       ] 
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );

Setting an Object Expiration Time

Sample code:

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',         
       'endpoint' => 'https://yourdomainname'
] );

$resp = $obsClient->setBucketLifecycleConfiguration ( [ 
       'Bucket' => 'bucketname',
       'Rules' => [ 
                     [ 
                           'ID' => 'rule1',
                           'Prefix' => 'prefix1',
                           'Status' => 'Enabled',
                           // Specify that objects whose names contain the prefix will expire after being created for 60 days.
                           'Expiration' => [ 
                                         'Days' => 60
                           ],
                           // Specify that objects whose names contain the prefix will expire after becoming noncurrent versions for 60 days.
                           'NoncurrentVersionExpiration' => [ 
                                         'NoncurrentDays' => 60 
                           ] 
                     ],
                     [ 
                           'ID' => 'rule2',
                           'Prefix' => 'prefix2',
                           'Status' => 'Enabled',
                           // Specify a date when the objects whose name contain the prefix will expire. The value must conform to the ISO8601 standards and must be at 00:00 (UTC time).
                           'Expiration' => [ 
                                         'Date' => '2018-12-31T00:00:00Z' 
                           ] 
                     ] 
       ] 
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
NOTE:

Use the Rules parameter to specify the lifecycle rules for a bucket.