You must restore an Archive object or a Cold Archive object before you can read the object. This topic describes how to restore an Archive object or a Cold Archive object.

Notice Do not call RestoreObject to restore an object whose storage class is not Archive or Cold Archive.

Restoration

If you want to read an Archive object or a Cold Archive object, you must restore the object in advance. It takes several minutes to restore an Archive object, and it takes several hours to restore a Cold Archive object based on different restoration priorities. The actual restoration time prevails.

The following section describes the status of an Archive object or a Cold Archive object throughout the restoration process:
  1. By default, an Archive object is in the frozen state.
  2. After you submit a request to restore the object, the object enters the restoring state.
  3. After the Object Storage Service (OSS) server completes the restoration task, the object enters the restored state and can be read.
    • Archive objects

      For Archive objects, the restored state lasts 24 hours by default. During the 24 hours, you can call RestoreObject again to extend the duration of the restored state for another 24 hours. During one restoration process, you can call RestoreObject for up to seven times to extend the duration of the restored state of the object. In other words, an object can remain in the restored state for up to seven days. You can also configure the duration of the restored state in days by calling RestoreObject. You can specify a duration of up to seven days.

    • Cold Archive objects
      For Cold Archive objects, you can specify the duration of the restored state and the restoration priority. The duration of the restored state must be at least one day and at most 365 days. The time required to restore a Cold Archive object to the readable state is determined based on the restoration priority of the object:
      • Expedited: The object is restored within one hour.
      • Standard: The object is restored within two to five hours. If the JobParameters parameter is not passed in, the default restoration mode is Standard.
      • Bulk: The object is restored within five to twelve hours.
  4. After the duration of the restored state expires, the object returns to the frozen state.

Restore Archive objects

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

using Aliyun.OSS;
using Aliyun.OSS.Model;

// 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. 
var endpoint = "yourEndpoint";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Object Storage Service (OSS) is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
var accessKeyId = "yourAccessKeyId";
var accessKeySecret = "yourAccessKeySecret";
// Specify the bucket name. 
var bucketName = "examplebucket";
// Specify the full path of the Archive object. The full path of the object cannot contain the bucket name. 
var objectName = "yourObjectName";
// Customize the content of the object. 
var objectContent = "More than just cloud.";
int maxWaitTimeInSeconds = 600;
// Create an OSSClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
    // Create an Archive bucket. 
    var bucket = client.CreateBucket(bucketName, StorageClass.Archive);
    Console.WriteLine("Create Archive bucket succeeded, {0} ", bucket.Name);
}
catch (Exception ex)
{
    Console.WriteLine("Create Archive bucket failed, {0}", ex.Message);
}
// Upload the object to the bucket and set the storage class of the object to Archive. 
try
{
    byte[] binaryData = Encoding.ASCII.GetBytes(objectContent);
    MemoryStream requestContent = new MemoryStream(binaryData);
    client.PutObject(bucketName, objectName, requestContent);
    Console.WriteLine("Put object succeeded, {0}", objectName);
}
catch (Exception ex)
{
    Console.WriteLine("Put object failed, {0}", ex.Message);
}
var metadata = client.GetObjectMetadata(bucketName, objectName);
string storageClass = metadata.HttpMetadata["x-oss-storage-class"] as string;
if (storageClass != "Archive")
{
    Console.WriteLine("StorageClass is {0}", storageClass);
    return;
}
// Restore the Archive object. 
RestoreObjectResult result = client.RestoreObject(bucketName, objectName);
Console.WriteLine("RestoreObject result HttpStatusCode : {0}", result.HttpStatusCode);
if (result.HttpStatusCode != HttpStatusCode.Accepted)
{
    throw new OssException(result.RequestId + ", " + result.HttpStatusCode + " ,");
}
while (maxWaitTimeInSeconds > 0)
{
    var meta = client.GetObjectMetadata(bucketName, objectName);
    string restoreStatus = meta.HttpMetadata["x-oss-restore"] as string;
    if (restoreStatus != null && restoreStatus.StartsWith("ongoing-request=\"false\"", StringComparison.InvariantCultureIgnoreCase))
    {
        break;
    }
    Thread.Sleep(1000);
    // The maximum wait time decreases by 1 second. 
    maxWaitTimeInSeconds--;
}
if (maxWaitTimeInSeconds == 0)
{
    Console.WriteLine("RestoreObject is timeout. ");
    throw new TimeoutException();
}
else
{
    Console.WriteLine("RestoreObject is successful. ");
}

Restore Cold Archive objects

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

using Aliyun.OSS;
using Aliyun.OSS.Model;
// 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. 
var endpoint = "yourEndpoint";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
var accessKeyId = "yourAccessKeyId";
var accessKeySecret = "yourAccessKeySecret";
// Specify the bucket name. 
var bucketName = "examplebucket";
// Specify the full path of the Cold Archive object. The full path of the object cannot contain the bucket name. 
var objectName = "yourObjectName";

// Create an OSSClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);

// Restore the Cold Archive object. 
var request = new RestoreObjectRequest(bucketName, objectName);

// Set the restoration priority of the Cold Archive object. 
// If you set the request.Tier parameter to TierType.Expedited, the object is restored within 1 hour. 
// If you set the request.Tier parameter to TierType.Standard, the object is restored within 2 to 5 hours. 
// If you set the request.Tier parameter to TierType.Bulk, the object is restored within 5 to 12 hours. 
// Configure restoration parameters. For example, you can set the restoration priority of the object to Expedited, and set the duration for which the object can remain in the restored state to two days. 
// The Days parameter indicates the duration for which the object can remain in the restored state. The default value is one day. This parameter applies to Archive and Cold Archive objects. 
// The Tier parameter indicates the restoration priority of the object and applies only to Cold Archive objects. 
request.Days = 2;
request.Tier = TierType.Expedited;
RestoreObjectResult result = client.RestoreObject(request);
Console.WriteLine("RestoreObject result HttpStatusCode : {0}", result.HttpStatusCode);

References

  • For the complete sample code that is used to restore Archive and Cold Archive objects, visit GitHub.
  • For more information about the API operation that you can call to restore Archive and Cold Archive objects, see RestoreObject.