É necessário restaurar objetos Archive, Cold Archive e Deep Cold Archive antes de acessá-los. Este tópico descreve como restaurar esses tipos de objeto.
Observações
A operação RestoreObject aplica-se exclusivamente a objetos Archive, Cold Archive e Deep Cold Archive.
Este tópico utiliza o endpoint público da região China (Hangzhou). Para acessar o OSS a partir de outros serviços da Alibaba Cloud na mesma região, use um endpoint interno. Para mais informações sobre regiões e endpoints do OSS, consulte Regiões e endpoints.
O exemplo obtém credenciais de acesso de variáveis de ambiente. Para saber como configurar credenciais de acesso, consulte Configurar credenciais de acesso (Python SDK V1).
Este tópico demonstra a criação de uma instância OSSClient com um endpoint do OSS. Para configurações alternativas, como uso de domínio personalizado ou autenticação com credenciais do Security Token Service (STS), consulte Inicialização.
A restauração de objetos exige a permissão
oss:RestoreObject. Para mais detalhes, consulte Conceder uma política personalizada.
Restaurar um objeto Archive
O código a seguir exemplifica como restaurar um objeto Archive:
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
from oss2.models import RestoreConfiguration
# 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.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"
# Specify the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)
# Specify the full path of the Archive object. Do not include the bucket name in the full path.
objectName = 'yourArchiveObjectName'
# Specify the duration for which the object remains in the restored state. Default value: 1. Unit: day. In this example, the duration is 2 days.
days = 2
restore_config = RestoreConfiguration(days=days)
# Initiate a RestoreObject request.
bucket.restore_object(objectName, input=restore_config)
Restaurar um objeto Cold Archive
O exemplo abaixo mostra como restaurar um objeto Cold Archive:
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
from oss2.models import (RestoreJobParameters,
RestoreConfiguration,
RESTORE_TIER_EXPEDITED,
RESTORE_TIER_STANDARD,
RESTORE_TIER_BULK)
# 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.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"
# Specify the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)
# Specify the full path of the Deep Cold Archive object. Do not include the bucket name in the full path.
object_name = "yourColdArchiveObjectName"
# Specify the duration for which the object remains in the restored state. Default value: 1. Unit: day. In this example, the duration is 2 days.
days = 2
# Specify the restoration mode. In this example, the restoration mode is RESTORE_TIER_BULK.
# RESTORE_TIER_EXPEDITED: The object is restored within 1 hour.
# RESTORE_TIER_STANDARD: The object is restored within 2 to 5 hours.
# RESTORE_TIER_BULK: The object is restored within 5 to 12 hours.
job_parameters = RestoreJobParameters(RESTORE_TIER_BULK)
restore_config = RestoreConfiguration(days=days, job_parameters=job_parameters)
# Initiate a RestoreObject request.
bucket.restore_object(object_name, input=restore_config)
Restaurar um objeto Deep Cold Archive
Confira a seguir um exemplo de código para restaurar um objeto Deep Cold Archive:
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
from oss2.models import (RestoreJobParameters,
RestoreConfiguration,
RESTORE_TIER_EXPEDITED,
RESTORE_TIER_STANDARD)
# 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.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"
# Specify the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)
# Specify the full path of the Deep Cold Archive object. Do not include the bucket name in the full path.
object_name = "yourDeepColdArchiveObjectName"
# Specify the duration for which the object remains in the restored state. Default value: 1. Unit: day. In this example, the duration is 2 days.
days = 2
# Specify the restoration mode. In this example, the restoration mode is RESTORE_TIER_STANDARD.
# RESTORE_TIER_EXPEDITED: The object is restored within 12 hours.
# RESTORE_TIER_STANDARD: The object is restored within 48 hours.
job_parameters = RestoreJobParameters(RESTORE_TIER_STANDARD)
restore_config = RestoreConfiguration(days=days, job_parameters=job_parameters)
# Initiate a RestoreObject request.
bucket.restore_object(object_name, input=restore_config)
Referências
Para obter o código de exemplo completo de restauração de objetos Archive, Cold Archive e Deep Cold Archive, acesse o GitHub.
Para mais informações sobre a operação de API de restauração desses objetos, consulte RestoreObject.