All Products
Search
Document Center

Object Storage Service:Restore objects (Python SDK V1)

Last Updated:Nov 26, 2025

Archive, Cold Archive, and Deep Cold Archive objects must be restored before they can be read. This topic describes how to restore these objects.

Usage notes

  • You can call the RestoreObject method only on Archive, Cold Archive, or 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 OSS 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 using OSS SDK for Python 1.0.

  • 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 an object, you must have the oss:RestoreObject permission. For more information, see Attach a custom access policy to a RAM user.

Restore an Archive object

The following code shows 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 this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Set the endpoint to the one 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"
# Set the region ID that corresponds to the endpoint. Example: cn-hangzhou. This parameter is required if you use Signature V4.
region = "cn-hangzhou"

# Set yourBucketName to the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)

# Set objectName to the full path of the Archive object. Do not include the bucket name in the path.
objectName = 'yourArchiveObjectName'
# Set the number of days that the object remains in the restored state. The default value is 1. This example sets the value to 2.
days = 2
restore_config = RestoreConfiguration(days=days)
# Initiate a restore request.
bucket.restore_object(objectName, input=restore_config)       

Restore a Cold Archive object

The following code shows 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 this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Set the endpoint to the one 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"
# Set the region ID that corresponds to the endpoint. Example: cn-hangzhou. This parameter is required if you use Signature V4.
region = "cn-hangzhou"

# Set yourBucketName to the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)

# Set object_name to the full path of the Cold Archive object. Do not include the bucket name in the path.
object_name = "yourColdArchiveObjectName"

# Set the number of days that the object remains in the restored state. The default value is 1. This example sets the value to 2.
days = 2

# Set the restoration priority. This example sets the priority to 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 restore request.
bucket.restore_object(object_name, input=restore_config)

Restore a Deep Cold Archive object

The following code shows 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 this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Set the endpoint to the one 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"
# Set the region ID that corresponds to the endpoint. Example: cn-hangzhou. This parameter is required if you use Signature V4.
region = "cn-hangzhou"

# Set yourBucketName to the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)

# Set object_name to the full path of the Deep Cold Archive object. Do not include the bucket name in the path.
object_name = "yourDeepColdArchiveObjectName"

# Set the number of days that the object remains in the restored state. The default value is 1. This example sets the value to 2.
days = 2

# Set the restoration priority. This example sets the priority to 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 restore 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, see the GitHub example.

  • For more information about the API operation for restoring Archive, Cold Archive, and Deep Cold Archive objects, see RestoreObject.