Los objetos Archive, Cold Archive y Deep Cold Archive deben restaurarse antes de acceder a ellos. En este tema se describe cómo restaurar objetos Archive, Cold Archive y Deep Cold Archive.
Notas
La operación RestoreObject solo se puede invocar en objetos Archive, Cold Archive y Deep Cold Archive.
En este tema se utiliza el endpoint público de la región China (Hangzhou). Si desea acceder a OSS desde otros servicios de Alibaba Cloud ubicados en la misma región que OSS, use un endpoint interno. Para obtener más información sobre las regiones y los endpoints de OSS, consulte Regions and endpoints.
En este tema, las credenciales de acceso se obtienen de variables de entorno. Para obtener más información sobre cómo configurar las credenciales de acceso, consulte Configure access credentials using OSS SDK for Python 1.0.
En este tema se muestra cómo crear una instancia de OSSClient con un endpoint de OSS. Para conocer configuraciones alternativas, como usar un dominio personalizado o autenticarse con credenciales de Security Token Service (STS), consulte Initialization.
Para restaurar objetos, necesita el permiso
oss:RestoreObject. Para obtener más información, consulte Grant a custom policy.
Restaurar un objeto Archive
A continuación se muestra un ejemplo de código para restaurar un 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 un objeto Cold Archive
A continuación se muestra un ejemplo de código para restaurar un 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 un objeto Deep Cold Archive
A continuación se muestra un ejemplo de código para restaurar un 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)
Referencias
El código de ejemplo completo para restaurar objetos Archive, Cold Archive y Deep Cold Archive está disponible en GitHub.
Para obtener más información sobre la API que permite restaurar objetos Archive, Cold Archive y Deep Cold Archive, consulte RestoreObject.