El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Setting Lifecycle Rules

Updated on 2025-02-08 GMT+08:00
NOTICE:

If you have any questions during the development, post them on the Issues page of GitHub.

You can call set_bucket_lifecycle_configuration to set lifecycle rules for a bucket.

Parameter Description

Field

Type

Mandatory or Optional

Description

option

The context of the bucket. For details, see Configuring option.

Mandatory

Bucket parameter

bucket_lifecycle_conf

obs_lifecycle_conf *

Mandatory

For details about the bucket lifecycle configuration, see the following table.

blcc_number

unsigned int

Mandatory

Number of array members in the array bucket_lifecycle_conf.

handler

obs_response_handler*

Mandatory

Callback function

callback_data

void *

Optional

Callback data

The following table describes the bucket lifecycle configuration structure obs_lifecycle_conf.

Field

Type

Mandatory or Optional

Description

date

const char *

If there is no days and no transition, noncurrent_version_days, or noncurrent_version_transition, this parameter is mandatory.

Indicates the time when the object expiration rule of the latest version takes effect. The value must conform to the ISO8601 standards and must be at 00:00 (UTC time).

days

const char *

If there is no date and no transition, noncurrent_version_days, noncurrent_version_transition is available, this parameter is mandatory.

Number of days when the expiration rule takes effect after the object creation (only applicable to latest versions of objects).

id

const char *

Optional

Unique identifier of a rule. The value can contain a maximum of 255 characters.

prefix

const char *

Mandatory

Object name prefix identifying one or more objects to which the rule applies.

status

const char *

Mandatory

Indicates whether the rule is enabled.

noncurrent_version_days

const char *

Optional

Number of days when the specified expiration rule takes effect after the object becomes a noncurrent version (only applicable to an object's noncurrent version).

Container for the expiration time of objects' noncurrent versions. If versioning is enabled or suspended for a bucket, you can set this parameter to delete noncurrent versions of objects that match the lifecycle rule (only applicable to the noncurrent versions of objects).

transition_num

unsigned int

If transition is not empty, this parameter is mandatory.

Number of array members in the array transition.

transition

obs_lifecycle_transition *

If there is no date, days, noncurrent_version_transition, or noncurrent_version_days, this parameter is mandatory.

Indicates the transition time and the object storage class after transition (valid only for the latest object version).

transition->date

const char *

This parameter is mandatory if there is transition but no transition.days.

Indicates the time when the object transition rule of the latest version takes effect. The value must conform to the ISO8601 standards and must be at 00:00 (UTC time).

transition->days

const char *

This parameter is mandatory if there is transition but no transition.date.

Number of days when the transition rule takes effect after the object creation (only applicable to latest versions of objects).

transition->storage_class

obs_storage_class

If there is transition, this parameter is mandatory.

The storage class to which the latest version object is modified.

noncurrent_version_transition_num

unsigned int

If obs_lifecycle_noncurrent_transition is not left blank, this parameter is mandatory.

Number of array members in the array noncurrent_version_transition.

noncurrent_version_transition

obs_lifecycle_noncurrent_transition *

If there is no date, days, transition, or noncurrent_version_days, this parameter is mandatory.

Transition time of noncurrent object versions and the object storage class after transition.

noncurrent_version_transition->noncurrent_version_days

const char *

If there is noncurrent_version_transition, this parameter is mandatory.

Number of days when the specified transition rule takes effect after the object becomes a noncurrent version (only applicable to an object's noncurrent version).

noncurrent_version_transition->storage_class

obs_storage_class

If there is noncurrent_version_transition, this parameter is mandatory.

The storage class to which the noncurrent version object is modified.

Setting an Object Transition Policy

Sample code:

static void test_set_bucket_lifecycle_configuration1()
{
    obs_status  ret_status = OBS_STATUS_BUTT;
    // Create and initialize option.
    obs_options option;
    init_obs_options(&option);
    option.bucket_options.host_name = "<your-endpoint>";
    option.bucket_options.bucket_name = "<Your bucketname>";

    // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY.
    // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
    option.bucket_options.access_key = getenv("ACCESS_KEY_ID");
    option.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY");
    // Set the completed callback function.
    obs_response_handler response_handler =
    { 
        NULL, &response_complete_callback
    };
    obs_lifecycle_conf bucket_lifecycle_conf;
    memset(&bucket_lifecycle_conf, 0, sizeof(obs_lifecycle_conf)); 
    // ID of the lifecycle rule
    bucket_lifecycle_conf.id = "test3"; 
    // Designate prefix "test".
    bucket_lifecycle_conf.prefix = "bcd"; 
    // The lifecycle rule takes effect.
    bucket_lifecycle_conf.status = "Enabled"; 
    // Specify that objects whose names contain the prefix will expire 10 days after creation.
    bucket_lifecycle_conf.days = "10"; 
    obs_lifecycle_transition transition;
    memset(&transition, 0, sizeof(obs_lifecycle_transition));
    // Specify that objects whose names contain the specified prefix will be transitioned 30 days after creation.
    transition.days = "30";
    // Specify the storage class that the object will be transitioned to.
    transition.storage_class = OBS_STORAGE_CLASS_STANDARD_IA;
    bucket_lifecycle_conf.transition = &transition;
    bucket_lifecycle_conf.transition_num = 1;
    obs_lifecycle_noncurrent_transition noncurrent_transition;
    memset(&noncurrent_transition, 0, sizeof(obs_lifecycle_noncurrent_transition));
    // Specify that objects whose names contain the specified prefix will be transitioned 30 days after becoming noncurrent versions.
    noncurrent_transition.noncurrent_version_days = "30";
    // Specify the storage class of objects whose names contain the prefix after changing into noncurrent versions.
    noncurrent_transition.storage_class = OBS_STORAGE_CLASS_STANDARD_IA;
    bucket_lifecycle_conf. noncurrent_version_transition = &noncurrent_transition;
    bucket_lifecycle_conf.noncurrent_version_transition_num = 1;
    set_bucket_lifecycle_configuration(&option, &bucket_lifecycle_conf, 1, 
                    &response_handler, &ret_status);
    if (OBS_STATUS_OK == ret_status) {
        printf("set bucket lifecycle configuration success.\n");
    }
    else
    {
        printf("set bucket lifecycle configuration failed(%s).\n", 
                    obs_get_status_name(ret_status));
    }
}

Setting an Object Expiration Time

Sample code:

static void test_set_bucket_lifecycle_configuration2()
{
    obs_options option;
    obs_status  ret_status = OBS_STATUS_BUTT;
    // Set option.
    init_obs_options(&option);
    option.bucket_options.host_name = HOST_NAME;
    option.bucket_options.bucket_name = bucket_name;

    //Read the AK/SK from environment variables.
    option.bucket_options.access_key = getenv("ACCESS_KEY_ID");
    option.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY");
    // Set the completed callback function.
    obs_response_handler response_handler =
    { 
        NULL, &response_complete_callback
    };
    obs_lifecycle_conf bucket_lifecycle_conf;
    memset(&bucket_lifecycle_conf, 0, sizeof(obs_lifecycle_conf)); 
    // ID of the lifecycle rule
    bucket_lifecycle_conf.id = "test1"; 
    // Designate prefix "test".
    bucket_lifecycle_conf.prefix = "test"; 
    // Specify that objects whose names contain the prefix will expire 10 days after creation.
    bucket_lifecycle_conf.days = "10"; 
    // Specify that objects whose names contain the specified prefix will expire 20 days after becoming noncurrent versions.
    bucket_lifecycle_conf.noncurrent_version_days = "20";
    // The lifecycle rule takes effect.
    bucket_lifecycle_conf.status = "Enabled"; 
    set_bucket_lifecycle_configuration(&option, &bucket_lifecycle_conf, 1, 
                &response_handler, &ret_status);
    if (OBS_STATUS_OK == ret_status) {
         printf("set bucket lifecycle configuration success.\n");
    }
    else
    {
        printf("set bucket lifecycle configuration failed(%s).\n",
                obs_get_status_name(ret_status));
    }
}

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback