You must restore an Archive or a Cold Archive object before you can read it. This topic describes how to restore an Archive 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 takes several hours to restore a Cold Archive object.

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 before restoration.
  2. After you submit a restore request, the object is in the restoring state.
  3. After the server completes the restore task, the object enters the restored state and you can read the object.

    For Archive objects, the restored state lasts 24 hours by default. During the 24 hours, if you call RestoreObject again, the restored state is extended by 24 hours. You can prolong the restored state up to seven days by calling RestoreObject six times during the first 24 hours of restored state. You can also configure the duration of the restored in days by calling RestoreObject once. You can specify a duration of at most seven days.

    For Cold Archive objects, you can specify the duration of restored state and restoration priority. The duration of the restored state must be at least one day and at most seven 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 element is not passed in, the default restoration priority is Standard.
    • Bulk: The object is restored within five to twelve hours.
  4. After 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:

// 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 endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. 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. 
String accessKeyId = "yourAccessKeyId";
String accessKeySecret = "yourAccessKeySecret";
// Specify the name of the bucket. 
String bucketName = "yourBucketName";
// Specify the full path of the Archive object. The path cannot contain the bucket name. 
String objectName = "yourArchiveObjectName";

// Create an OSSClient instance. 
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, objectName);

// Check whether the object is an Archive object. 
StorageClass storageClass = objectMetadata.getObjectStorageClass();
if (storageClass == StorageClass.Archive) {
    // Restores the object. 
    ossClient.restoreObject(bucketName, objectName);

    // Wait until the object is restored. 
    do {
        Thread.sleep(1000);
        objectMetadata = ossClient.getObjectMetadata(bucketName, objectName);
    } while (!objectMetadata.isRestoreCompleted());
}

// Obtain the restored object. 
OSSObject ossObject = ossClient.getObject(bucketName, objectName);
ossObject.getObjectContent().close();

// Shut down the OSSClient instance. 
ossClient.shutdown();
            

Restore a Cold Archive object

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

// 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 endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. 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. 
String accessKeyId = "yourAccessKeyId";
String accessKeySecret = "yourAccessKeySecret";
// Specify the name of the bucket. 
String bucketName = "yourBucketName";
// Specify the full path of the object. The path cannot contain the bucket name. 
String objectName = "yourColdArchiveObjectName";

// Create an OSSClient instance. 
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

// Refer to the following code if you want to set the storage class of the object to Cold Archive when you upload the object. 
// Create a PutObjectRequest object. 
// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, new ByteArrayInputStream("<yourContent>".getBytes()));
// Set the storage class of the object to Cold Archive in the object metadata. 
// ObjectMetadata metadata = new ObjectMetadata();
// metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.ColdArchive.toString());
// putObjectRequest.setMetadata(metadata);
// Set the storage class of the object when you upload the object. 
// ossClient.putObject(putObjectRequest);

// Set the restoration priority of the Cold Archive object. 
// RestoreTier.RESTORE_TIER_EXPEDITED: The object is restored within an hour. 
// RestoreTier.RESTORE_TIER_STANDARD: The object is restored within two to five hours. 
// RestoreTier.RESTORE_TIER_STANDARD: The object is restored within five to twelve hours. 
RestoreJobParameters jobParameters = new RestoreJobParameters(restoreTier);

// Configure parameters. For example, set the restoration priority of the object to Standard, and set the duration for which the object can remain in the restored state to two days. 
// The first parameter indicates the validity period of the restored state. The default value is one day. This parameter applies to Archive and Cold Archive objects. 
// jobParameters indicates the restoration priority of the object and applies only to Cold Archive objects. 
RestoreConfiguration configuration = new RestoreConfiguration(2, jobParameters);

// Initiate a restore request. 
ossClient.restoreObject(bucketName, objectName, configuration);

// Shut down the OSSClient instance. 
ossClient.shutdown();

References

  • For more information about 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.