Todos os produtos
Search
Central de documentação

Object Storage Service:Use lifecycle rules based on last access time to implement intelligent data tiering

Última atualização: Jul 03, 2026

Regras de ciclo de vida baseadas no horário do último acesso permitem monitorar automaticamente os padrões de acesso aos dados e identificar dados frios. Em seguida, altere a classe de armazenamento desses dados para implementar o armazenamento inteligente em camadas e reduzir custos.

Descrição do cenário

Um site multimídia precisa classificar seus dados como quentes ou frios com base no horário do último acesso. O método tradicional exige análise manual de logs. No entanto, o uso de regras de ciclo de vida baseadas no último acesso permite identificar e organizar os dados em camadas automaticamente.

Neste cenário, os dados são categorizados e armazenados em caminhos diferentes dentro do bucket examplebucket. O objetivo é transferir alguns dados para uma classe de armazenamento de custo mais baixo após um período especificado.

Caminho de armazenamento

Cenário de armazenamento

Política de ciclo de vida

Resultado

data/

Armazena vídeos de streaming ao vivo WMV. Esses vídeos têm acesso pouco frequente nos dois primeiros meses após o upload e raramente são acessados depois disso.

Transição para a classe de armazenamento Infrequent Access (IA) 200 dias após o último acesso. Se os dados forem acessados novamente, permanecerão na classe de armazenamento IA.

A classe de armazenamento muda após o número especificado de dias. Os dados que não atendem aos critérios permanecem na classe de armazenamento Standard.

Armazena dados de vídeo de filmes MP4. A maioria dos arquivos é acessada frequentemente dentro de cada período de seis meses.

log/

Armazena uma grande quantidade de dados de log. Poucos arquivos apresentam registros de acesso nos últimos três meses. Quase todos os arquivos deixam de ter registros de acesso seis meses após o upload.

  • Transição para a classe de armazenamento Infrequent Access (IA) 120 dias após o último acesso. Se os dados forem acessados novamente, permanecerão na classe de armazenamento IA.

  • Transição para a classe de armazenamento Archive 250 dias após o último acesso.

Nota
  • Com uma política de ciclo de vida baseada no horário do último acesso, o OSS identifica e organiza automaticamente os dados quentes e frios em camadas. Por exemplo, vídeos MP4 acessados frequentemente no caminho data/ permanecem na classe de armazenamento Standard. Vídeos MP4 sem acesso por seis meses são transferidos para a classe de armazenamento Infrequent Access após 200 dias. Caso você configure uma regra de ciclo de vida baseada no horário da última modificação, os dados no caminho data/ só poderão ser transferidos ou excluídos com base nesse critério. Isso impede a implementação do armazenamento inteligente em camadas baseado na frequência de acesso aos arquivos.

  • As políticas de ciclo de vida e as ações recomendadas neste cenário servem apenas como referência. Configure as regras de ciclo de vida de acordo com as necessidades específicas do seu negócio.

Pré-requisitos

  • O rastreamento de acesso está ativado.

  • Para transferir objetos da classe de armazenamento Standard ou Infrequent Access para as classes Archive, Cold Archive ou Deep Cold Archive, envie um ticket para solicitar esse recurso.

    Importante

    Após a aprovação do ticket, se você usar uma política baseada no horário do último acesso para transferir objetos da classe Standard ou Infrequent Access para as classes Archive, Cold Archive ou Deep Cold Archive, o horário do último acesso desses objetos assumirá, por padrão, o momento em que o rastreamento de acesso foi ativado para o bucket.

Procedimento

Usar o console do OSS

  1. Ative o rastreamento de acesso.

    1. Faça login no console do OSS.

    2. No painel de navegação à esquerda, clique em Buckets. Na página exibida, clique no nome do bucket desejado.

    3. No painel de navegação à esquerda, escolha Data Management > Lifecycle.

    4. Na página Lifecycle, ative a chave Enable Access Tracking.

      Nota

      Ao ativar o rastreamento de acesso, o OSS define o horário do último acesso de todos os objetos no bucket como o momento em que o rastreamento foi ativado.

  2. Configure uma regra de ciclo de vida.

    1. Na página Lifecycle, clique em Create Rule.

    2. No painel Create Lifecycle Rule, configure as regras de ciclo de vida para o prefixo data/ e para o prefixo log/ conforme descrito nas seções abaixo.

      Regra de ciclo de vida para o prefixo data/

      Configure os parâmetros necessários para a regra de ciclo de vida do prefixo data/ conforme descrito abaixo. Mantenha as configurações padrão para os demais parâmetros.

      Item de configuração

      Descrição

      Status

      Clique em Start.

      Applied To

      Selecione Match by Prefix.

      Prefix

      Insira data/.

      Object Lifecycle

      Selecione Specify Days.

      Lifecycle-based Rules

      Na lista suspensa, selecione Last Access Time. Insira 200 dias. Os dados serão transferidos automaticamente para Infrequent Access (Data remains in IA after being accessed).

      Regra de ciclo de vida para o prefixo log/

      Defina os parâmetros obrigatórios da regra de ciclo de vida para o prefixo log/ conforme descrito abaixo. Os demais parâmetros podem manter as configurações padrão.

      Item de configuração

      Descrição

      Status

      Selecione Start.

      Applied To

      Selecione Match by Prefix.

      Prefix

      Insira log/.

      Object Lifecycle

      Selecione Specify Days.

      Lifecycle-based Rules

      • Na lista suspensa, selecione Last Access Time. Insira 120 dias. Os dados serão transferidos automaticamente para Infrequent Access (Data remains in IA after being accessed).

      • Na lista suspensa, selecione Last Access Time. Insira 250 dias. Os dados serão transferidos automaticamente para Archive.

    3. Clique em OK.

Usar um SDK do Alibaba Cloud

Apenas os SDKs Java, Python e Go suportam a criação de regras de ciclo de vida baseadas no horário do último acesso. Antes de criar uma regra desse tipo, ative o rastreamento de acesso para o bucket especificado.

  1. Ative o rastreamento de acesso.

    Java

    import com.aliyun.oss.*;
    import com.aliyun.oss.common.auth.*;
    import com.aliyun.oss.common.comm.SignVersion;
    import com.aliyun.oss.model.AccessMonitor;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            // In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
            String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
            // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
            EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
            // Specify the name of the bucket. Example: examplebucket. 
            String bucketName = "examplebucket";
    
            // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
            String region = "cn-hangzhou";
    
            // Create an OSSClient instance. 
            // Call the shutdown method to release associated resources when the OSSClient is no longer in use.
            ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
            clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);        
            OSS ossClient = OSSClientBuilder.create()
            .endpoint(endpoint)
            .credentialsProvider(credentialsProvider)
            .clientConfiguration(clientBuilderConfiguration)
            .region(region)               
            .build();
    
            try {
                // Enable access tracking for the bucket. If you want to change the access tracking status of a bucket from Enabled to Disabled, make sure that the bucket does not have lifecycle rules configured based on the last access time of the objects in the bucket. 
                ossClient.putBucketAccessMonitor(bucketName, AccessMonitor.AccessMonitorStatus.Enabled.toString());
            } catch (OSSException oe) {
                System.out.println("Caught an OSSException, which means your request made it to OSS, "
                        + "but was rejected with an error response for some reason.");
                System.out.println("Error Message:" + oe.getErrorMessage());
                System.out.println("Error Code:" + oe.getErrorCode());
                System.out.println("Request ID:" + oe.getRequestId());
                System.out.println("Host ID:" + oe.getHostId());
            } catch (ClientException ce) {
                System.out.println("Caught an ClientException, which means the client encountered "
                        + "a serious internal problem while trying to communicate with OSS, "
                        + "such as not being able to access the network.");
                System.out.println("Error Message:" + ce.getMessage());
            } finally {
                if (ossClient != null) {
                    ossClient.shutdown();
                }
            }
        }
    }

    Python

    # -*- coding: utf-8 -*-
    import oss2
    from oss2.credentials import EnvironmentVariableCredentialsProvider
    
    # Obtain access credentials from environment variables. Before running this code, ensure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
    auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
    
    # Specify the endpoint for the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
    endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
    # Specify the region that corresponds to the endpoint, for example, cn-hangzhou. Note: This parameter is required for V4 signatures.
    region = "cn-hangzhou"
    
    # Replace "examplebucket" with the name of your bucket.
    bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)
    
    # Enable access tracking for the bucket. After access tracking is enabled, if you want to change the status to Disabled, ensure that the bucket has no lifecycle rules based on the LastAccessTime match rule.
    bucket.put_bucket_access_monitor("Enabled")

    Go

    package main
    
    import (
    	"context"
    	"flag"
    	"log"
    
    	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
    	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
    )
    
    // Define global variables.
    var (
    	region     string // The bucket region.
    	bucketName string // The bucket name.
    )
    
    // The init function initializes command-line parameters.
    func init() {
    	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
    	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
    }
    
    // The main function enables access tracking for the bucket.
    func main() {
    	// Parse command-line parameters.
    	flag.Parse()
    
    	// Check whether the bucket name is empty.
    	if len(bucketName) == 0 {
    		flag.PrintDefaults()
    		log.Fatalf("invalid parameters, bucket name required")
    	}
    
    	// Check whether the region is empty.
    	if len(region) == 0 {
    		flag.PrintDefaults()
    		log.Fatalf("invalid parameters, region required")
    	}
    
    	// Load the default configurations, and set the credential provider and region.
    	cfg := oss.LoadDefaultConfig().
    		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
    		WithRegion(region)
    
    	// Create an OSS client.
    	client := oss.NewClient(cfg)
    
    	// Create a request to enable access tracking for the bucket.
    	request := &oss.PutBucketAccessMonitorRequest{
    		Bucket: oss.Ptr(bucketName),
    		AccessMonitorConfiguration: &oss.AccessMonitorConfiguration{
    			Status: oss.AccessMonitorStatusEnabled, // Enable access tracking.
    		},
    	}
    
    	// Execute the operation to enable access tracking for the bucket.
    	putResult, err := client.PutBucketAccessMonitor(context.TODO(), request)
    	if err != nil {
    		log.Fatalf("failed to put bucket access monitor %v", err)
    	}
    
    	// Print the result.
    	log.Printf("put bucket access monitor result: %#v\n", putResult)
    }
    
  2. Configure regras de ciclo de vida baseadas no horário do último acesso para os prefixos data/ e log/.

    Java

    import com.aliyun.oss.ClientException;
    import com.aliyun.oss.OSS;
    import com.aliyun.oss.common.auth.*;
    import com.aliyun.oss.OSSClientBuilder;
    import com.aliyun.oss.OSSException;
    import com.aliyun.oss.model.*;
    import java.util.ArrayList;
    import java.util.List;
    
    public class Lifecycle {
    
        public static void main(String[] args) throws Exception {
            // The endpoint is set to China (Hangzhou) in this example. Specify the actual endpoint.
            String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
            // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
            EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
            // Specify the bucket name, for example, examplebucket.
            String bucketName = "examplebucket";
    
            // Create an OSSClient instance.
            // When the OSSClient instance is no longer needed, call the shutdown method to release resources.
            OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
    
            try {
                String ruleId1 = "rule1";
                String ruleId2 = "rule2";
                // Specify the prefix as data/.
                String matchPrefix = "data/";
                // Specify the prefix as log/.
                String matchPrefix2 = "log/";
    
                SetBucketLifecycleRequest request = new SetBucketLifecycleRequest(bucketName);
    
                // In lifecycle rule 1, transition all files with the data/ prefix to the Infrequent Access storage class 200 days after their last access time. When these files are accessed again, they remain in the Infrequent Access storage class.
                List<LifecycleRule.StorageTransition> storageTransitions = new ArrayList<LifecycleRule.StorageTransition>();
                LifecycleRule.StorageTransition storageTransition = new LifecycleRule.StorageTransition();
                storageTransition.setStorageClass(StorageClass.IA);
                storageTransition.setExpirationDays(200);
                storageTransition.setIsAccessTime(true);
                storageTransition.setReturnToStdWhenVisit(false);
                storageTransitions.add(storageTransition);
    
                LifecycleRule rule = new LifecycleRule(ruleId1, matchPrefix, LifecycleRule.RuleStatus.Enabled);
                rule.setStorageTransition(storageTransitions);
                request.AddLifecycleRule(rule);
    
                // In lifecycle rule 2, transition all files with the log/ prefix to the Infrequent Access storage class 120 days after their last access time. When these files are accessed again, they remain in the Infrequent Access storage class.
                List<LifecycleRule.StorageTransition> storageTransitions2 = new ArrayList<LifecycleRule.StorageTransition>();
                LifecycleRule.StorageTransition storageTransition2 = new LifecycleRule.StorageTransition();
                storageTransition2.setStorageClass(StorageClass.IA);
                storageTransition2.setExpirationDays(120);
                storageTransition2.setIsAccessTime(true);
                storageTransition2.setReturnToStdWhenVisit(false);
                storageTransitions2.add(storageTransition2);
                // In the same rule, transition all files with the log/ prefix to the Archive storage class 250 days after their last modification time.
                LifecycleRule.StorageTransition storageTransition3 = new LifecycleRule.StorageTransition();
                storageTransition3.setStorageClass(StorageClass.Archive);
                storageTransition3.setExpirationDays(250);
                storageTransition3.setIsAccessTime(false);
                storageTransitions2.add(storageTransition3);
    
                LifecycleRule rule2 = new LifecycleRule(ruleId2, matchPrefix2, LifecycleRule.RuleStatus.Enabled);
                rule2.setStorageTransition(storageTransitions2);
                request.AddLifecycleRule(rule2);
    
                VoidResult result = ossClient.setBucketLifecycle(request);
    
                System.out.println("Return status code:"+result.getResponse().getStatusCode()+" set lifecycle succeed");
            } catch (OSSException oe) {
                System.out.println("Caught an OSSException, which means your request made it to OSS, "
                        + "but was rejected with an error response for some reason.");
                System.out.println("Error Message:" + oe.getErrorMessage());
                System.out.println("Error Code:" + oe.getErrorCode());
                System.out.println("Request ID:" + oe.getRequestId());
                System.out.println("Host ID:" + oe.getHostId());
            } catch (ClientException ce) {
                System.out.println("Caught an ClientException, which means the client encountered "
                        + "a serious internal problem while trying to communicate with OSS, "
                        + "such as not being able to access the network.");
                System.out.println("Error Message:" + ce.getMessage());
            } finally {
                if (ossClient != null) {
                    ossClient.shutdown();
                }
            }
        }
    }

    Python

    # -*- coding: utf-8 -*-
    import oss2
    from oss2.credentials import EnvironmentVariableCredentialsProvider
    from oss2.models import LifecycleRule, BucketLifecycle, StorageTransition
    
    # Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
    auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
    # Set yourEndpoint to the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
    # Specify the bucket name, for example, examplebucket.
    bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
    
    # In lifecycle rule 1, transition all files with the data/ prefix to the Infrequent Access storage class 200 days after their last access time. When these files are accessed again, they remain in the Infrequent Access storage class.
    rule1 = LifecycleRule('rule1', 'data/', status=LifecycleRule.ENABLED)
    rule1.storage_transitions = [StorageTransition(days=200,
                                                   storage_class=oss2.BUCKET_STORAGE_CLASS_IA,
                                                   is_access_time=True,
                                                   return_to_std_when_visit=False)]
    
    # In lifecycle rule 2, transition all files with the log/ prefix to the Infrequent Access storage class 120 days after their last access time. When these files are accessed again, they remain in the Infrequent Access storage class.
    # In the same rule, transition all files with the log/ prefix to the Archive storage class 250 days after their last modification time.
    rule2 = LifecycleRule('rule2', 'log/', status=LifecycleRule.ENABLED)
    rule2.storage_transitions = [StorageTransition(days=120,
                                                   storage_class=oss2.BUCKET_STORAGE_CLASS_IA,
                                                   is_access_time=True,
                                                   return_to_std_when_visit=False),
                                 StorageTransition(days=250,
                                                   storage_class=oss2.BUCKET_STORAGE_CLASS_ARCHIVE,
                                                   is_access_time=False)]
    
    lifecycle = BucketLifecycle([rule1, rule2])
    
    # Set the lifecycle rule.
    result = bucket.put_bucket_lifecycle(lifecycle)
    
    print('Lifecycle rule set successfully. Return status:' + str(result.status))

    Go

    package main
    
    import (
    	"context"
    	"flag"
    	"log"
    
    	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
    	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
    )
    
    // Define global variables.
    var (
    	region     string // The region where the bucket is located.
    	bucketName string // The name of the bucket.
    )
    
    // The init function initializes command-line arguments.
    func init() {
    	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
    	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
    }
    
    func main() {
    	// Parse command-line arguments.
    	flag.Parse()
    
    	// Check if the bucket name is provided.
    	if len(bucketName) == 0 {
    		flag.PrintDefaults()
    		log.Fatalf("invalid parameters, bucket name required")
    	}
    
    	// Check if the region is provided.
    	if len(region) == 0 {
    		flag.PrintDefaults()
    		log.Fatalf("invalid parameters, region required")
    	}
    
    	// Load the default configuration, and set the credentials provider and region.
    	cfg := oss.LoadDefaultConfig().
    		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
    		WithRegion(region)
    
    	// Create an OSS client.
    	client := oss.NewClient(cfg)
    
    	// Create a request to set lifecycle rules for the bucket.
    	request := &oss.PutBucketLifecycleRequest{
    		Bucket: oss.Ptr(bucketName), // The name of the bucket.
    		LifecycleConfiguration: &oss.LifecycleConfiguration{
    			Rules: []oss.LifecycleRule{
    				{
    					// In lifecycle rule "rule1", transition all objects with the prefix "data/"
    					// to the Infrequent Access (IA) storage class 200 days after they are last accessed.
    					// When these objects are accessed again, they remain in the IA storage class.
    					ID:     oss.Ptr("rule1"),
    					Status: oss.Ptr("Enabled"),
    					Prefix: oss.Ptr("data/"),
    					Transitions: []oss.LifecycleRuleTransition{
    						{
    							Days:                 oss.Ptr(int32(200)),
    							StorageClass:         oss.StorageClassIA,
    							IsAccessTime:         oss.Ptr(true), // Set to true for a rule based on last access time.
    							ReturnToStdWhenVisit: oss.Ptr(false),
    						},
    					},
    				},
    				{
    					// In lifecycle rule "rule2", transition all objects with the prefix "log/"
    					// to the Infrequent Access (IA) storage class 120 days after they are last accessed.
    					// When these objects are accessed again, they remain in the IA storage class.
    					// A single rule cannot contain more than one IsAccessTime=true Transition.
    					// The 250-day Archive transition is configured in a separate rule (rule3) below.
    					ID:     oss.Ptr("rule2"),
    					Status: oss.Ptr("Enabled"),
    					Prefix: oss.Ptr("log/"),
    					Transitions: []oss.LifecycleRuleTransition{
    						{
    							Days:                 oss.Ptr(int32(120)),
    							StorageClass:         oss.StorageClassIA,
    							IsAccessTime:         oss.Ptr(true), // Set to true for a rule based on last access time.
    							ReturnToStdWhenVisit: oss.Ptr(false),
    						},
    					},
    				},
    				{
    					// In lifecycle rule "rule3", transition all objects with the prefix "log/"
    					// to the Archive storage class 250 days after they are last accessed.
    					// When these objects are accessed again, they remain in the Archive storage class.
    					// This rule is separate from rule2 because a single rule cannot contain
    					// more than one IsAccessTime=true Transition.
    					ID:     oss.Ptr("rule3"),
    					Status: oss.Ptr("Enabled"),
    					Prefix: oss.Ptr("log/"),
    					Transitions: []oss.LifecycleRuleTransition{
    						{
    							Days:                 oss.Ptr(int32(250)),
    							StorageClass:         oss.StorageClassArchive,
    							IsAccessTime:         oss.Ptr(true), // Set to true for a rule based on last access time.
    							ReturnToStdWhenVisit: oss.Ptr(false),
    						},
    					},
    				},
    			},
    		},
    	}
    
    	// Set the lifecycle rules for the bucket.
    	result, err := client.PutBucketLifecycle(context.TODO(), request)
    	if err != nil {
    		log.Fatalf("failed to put bucket lifecycle %v", err)
    	}
    
    	// Print the result of setting the lifecycle rules.
    	log.Printf("put bucket lifecycle result:%#v\n", result)
    }
    

Usar a interface de linha de comando ossutil

ossutil 2.0

  1. Ative o rastreamento de acesso.

    1. Configure o rastreamento de acesso no arquivo local config1.xml.

      <?xml version="1.0" encoding="UTF-8"?>
      <AccessMonitorConfiguration>
          <Status>Enabled</Status>
      </AccessMonitorConfiguration>
    2. Defina o status de rastreamento de acesso para o bucket desejado.

      ossutil api put-bucket-access-monitor --bucket bucketname --access-monitor-configuration file://config1.xml
  2. Configure regras de ciclo de vida baseadas no horário do último acesso para os prefixos data/ e log/.

    1. Configure as seguintes regras de ciclo de vida no arquivo local config2.xml.

      <?xml version="1.0" encoding="UTF-8"?>
      <LifecycleConfiguration>
        <Rule>
          <ID>rule1</ID>
          <Prefix>data/</Prefix>
          <Status>Enabled</Status>
          <Transition>
            <Days>200</Days>
            <StorageClass>IA</StorageClass>
            <IsAccessTime>true</IsAccessTime>
            <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit>
          </Transition>    
        </Rule>
        <Rule>
          <ID>rule2</ID>
          <Prefix>log/</Prefix>
          <Status>Enabled</Status>
          <Transition>
            <Days>120</Days>
            <StorageClass>IA</StorageClass>
            <IsAccessTime>true</IsAccessTime>
            <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit>
          </Transition>
          <Transition>
            <Days>250</Days>
            <StorageClass>Archive</StorageClass>
            <IsAccessTime>true</IsAccessTime>
            <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit>
          </Transition>    
        </Rule>
      </LifecycleConfiguration>
    2. Defina as regras de ciclo de vida para o bucket desejado.

      ossutil api put-bucket-lifecycle --bucket bucketname --lifecycle-configuration file://config2.xml

ossutil 1.0

  1. Ative o rastreamento de acesso.

    1. Configure o rastreamento de acesso no arquivo local config1.xml.

      <?xml version="1.0" encoding="UTF-8"?>
      <AccessMonitorConfiguration>
          <Status>Enabled</Status>
      </AccessMonitorConfiguration>
    2. Defina o status de rastreamento de acesso para o bucket desejado.

      ossutil access-monitor --method put oss://examplebucket/ config1.xml
  2. Configure regras de ciclo de vida baseadas no horário do último acesso para os prefixos data/ e log/.

    1. Configure as seguintes regras de ciclo de vida no arquivo local config2.xml.

      <?xml version="1.0" encoding="UTF-8"?>
      <LifecycleConfiguration>
        <Rule>
          <ID>rule1</ID>
          <Prefix>data/</Prefix>
          <Status>Enabled</Status>
          <Transition>
            <Days>200</Days>
            <StorageClass>IA</StorageClass>
            <IsAccessTime>true</IsAccessTime>
            <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit>
          </Transition>    
        </Rule>
        <Rule>
          <ID>rule2</ID>
          <Prefix>log/</Prefix>
          <Status>Enabled</Status>
          <Transition>
            <Days>120</Days>
            <StorageClass>IA</StorageClass>
            <IsAccessTime>true</IsAccessTime>
            <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit>
          </Transition>
          <Transition>
            <Days>250</Days>
            <StorageClass>Archive</StorageClass>
            <IsAccessTime>true</IsAccessTime>
            <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit>
          </Transition>    
        </Rule>
      </LifecycleConfiguration>
    2. Defina as regras de ciclo de vida para o bucket desejado.

      ossutil lifecycle --method put oss://examplebucket config2.xml

Usar uma API REST

Se o seu programa exigir alto nível de personalização, faça solicitações diretamente via API REST. Para isso, escreva manualmente o código para calcular as assinaturas. Para mais informações, consulte PutBucketAccessMonitor e PutBucketLifecycle.

Referências