Objects in Archive, Cold Archive, and Deep Cold Archive must be restored before they can be accessed. This topic describes how to restore Archive, Cold Archive, and Deep Cold Archive objects.
Usage notes
The RestoreObject operation can be called only on Archive, Cold Archive, and Deep Cold Archive objects.
In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access OSS by using other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about the regions and endpoints supported by OSS, see Regions and endpoints.
In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
In this topic, an OSSClient instance is created by using an OSS endpoint. If you want to create an OSSClient instance by using custom domain names or Security Token Service (STS), see Initialization.
To restore objects, you must have the
oss:RestoreObject
permission. For more information, see Common examples of RAM policies.
Restore an Archive object
The following sample code provides an example on how to restore an Archive object:
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# 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.ProviderAuth(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.
# Specify the name of the bucket. Example: examplebucket.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
# Specify the full path of the Archive object. Do not include the bucket name in the full path.
objectName = 'yourArchiveObjectName'
# Initiate a RestoreObject request.
bucket.restore_object(objectName)
Restore a Cold Archive object
The following sample code provides an example on how to restore a Cold Archive object:
# -*- 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.ProviderAuth(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.
# Specify the name of the bucket. Example: examplebucket.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
# Specify the full path of the 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_STANDARD.
# 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_STANDARD)
restore_config= RestoreConfiguration(days=days, job_parameters=job_parameters)
# Initiate a RestoreObject request.
bucket.restore_object(object_name, input=restore_config)
Restore a Deep Cold Archive object
The following sample code provides an example on how to restore a Deep Cold Archive object:
# -*- 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.ProviderAuth(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.
# Specify the name of the bucket. Example: examplebucket.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
# 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)
References
For the complete sample code for restoring Archive, Cold Archive, and Deep Cold Archive objects, visit GitHub.
For more information about the API operation for restoring Archive, Cold Archive, and Deep Cold Archive, see RestoreObject.