Archive, Cold Archive, and Deep Cold Archive objects must be restored before you can read them. This topic describes how to restore Archive and Cold Archive objects by using OSS PHP SDK V1.
Prerequisites
Before you begin, make sure that you have:
A bucket containing Archive or Cold Archive objects
The
oss:RestoreObjectpermission granted to your RAM user. For more information, see Grant custom permissions to a RAM user.The
OSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables configured
Usage notes
Only Archive, Cold Archive, and Deep Cold Archive objects support the RestoreObject operation.
In this topic, the public endpoint of the China (Hangzhou) region is used. To access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For details about supported regions and endpoints, see Regions and endpoints.
This topic demonstrates creating an OSSClient instance with an OSS endpoint. For alternative configurations, such as using a custom domain or authenticating with credentials from Security Token Service (STS), see Create an OssClient.
Cold Archive restoration tiers
When you restore a Cold Archive object, specify a restoration priority to control the restore speed. The following table lists the available tiers.
| Restoration priority | Restore time | Use case |
|---|---|---|
| Expedited | Within 1 hour | Urgent access to a small number of objects |
| Standard | 2 to 5 hours | Routine access with moderate time sensitivity |
| Bulk | 5 to 12 hours | Large-scale restores where cost efficiency matters |
The restored Cold Archive object stays accessible for 1 to 365 days, depending on the value you specify in RestoreConfig. For Archive objects, the valid range is 1 to 7 days.
Deep Cold Archive objects also support the RestoreObject operation but are not covered in the code examples in this topic. Deep Cold Archive supports two restoration tiers: Expedited (within 12 hours) and Standard (within 48 hours).
Restore an Archive object
The following code restores an Archive object:
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\Core\OssException;
// Obtain access credentials from environment variables.
// Make sure that OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET are set.
$provider = new EnvironmentVariableCredentialsProvider();
// Specify the endpoint. This example uses the China (Hangzhou) region.
$endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// Specify the bucket name. Example: examplebucket.
$bucket= "examplebucket";
// Specify the full path of the Archive object. Do not include the bucket name.
// Example: srcexampleobject.txt.
$object = "srcexampleobject.txt";
try {
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region"=> "cn-hangzhou"
);
$ossClient = new OssClient($config);
// Restore the Archive object. No additional restore configuration is required.
$ossClient->restoreObject($bucket, $object);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");Restore a Cold Archive object
Cold Archive objects require a RestoreConfig that specifies the number of days the object stays in the restored state and the restoration priority.
The following code restores a Cold Archive object:
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Model\RestoreConfig;
// Obtain access credentials from environment variables.
// Make sure that OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET are set.
$provider = new EnvironmentVariableCredentialsProvider();
// Specify the endpoint. This example uses the China (Hangzhou) region.
$endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// Specify the bucket name. Example: examplebucket.
$bucket= "examplebucket";
// Specify the full path of the Cold Archive object. Do not include the bucket name.
// Example: srcexampleobject.txt.
$object = "srcexampleobject.txt";
try {
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region"=> "cn-hangzhou"
);
$ossClient = new OssClient($config);
// Number of days the object remains in the restored state. Valid values: 1 to 365.
$day = 3;
// Restoration priority. Options: Expedited (within 1 hour),
// Standard (2 to 5 hours), or Bulk (5 to 12 hours).
$tier = "Bulk";
$config = new RestoreConfig($day, $tier);
$options = array(
OssClient::OSS_RESTORE_CONFIG => $config
);
$result = $ossClient->restoreObject($bucket, $object, $options);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");References
For more information about the API operation used to restore Archive, Cold Archive, and Deep Cold Archive objects, see RestoreObject.