All Products
Search
Document Center

Object Storage Service:Restore objects

Last Updated:Oct 25, 2024

Archive, Cold Archive, and Deep Cold Archive objects 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 from other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about OSS regions and endpoints, see Regions, endpoints and open ports.

  • 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 Attach a custom policy to a RAM user.

Restore an Archive object

The following code provides an example on how to restore an Archive object:

# -*- 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)       

Restore a Cold Archive object

The following 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.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 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)

Restore a Deep Cold Archive object

The following 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)

# 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)

References

  • For the complete sample code that is used to restore Archive, Cold Archive, and Deep Cold Archive objects, visit GitHub.

  • For more information about the API operation that you can call to restore Archive, Cold Archive, and Deep Cold Archive objects, see RestoreObject.