Todos los productos
Search
Centro de documentos

Object Storage Service:Restaurar archivos (PHP SDK V1)

Última actualización: Sep 25, 2026

Los objetos Archive, Cold Archive y Deep Cold Archive deben restaurarse antes de poder leerlos. En este tema se describe cómo restaurar objetos Archive y Cold Archive.

Notas

  • Solo los objetos Archive, Cold Archive y Deep Cold Archive admiten la operación RestoreObject.

  • En este tema se utiliza el endpoint público de la región China (Hangzhou). Para acceder a OSS desde otros servicios de Alibaba Cloud en la misma región, use un endpoint interno. Para obtener más información sobre las regiones y los endpoints compatibles, consulte Regions and endpoints.

  • Este tema muestra cómo crear una instancia de OSSClient con un endpoint de OSS. Para conocer configuraciones alternativas, como usar un dominio personalizado o autenticarse con credenciales de Security Token Service (STS), consulte Create an OssClient.

  • Para restaurar un archivo, debe contar con el permiso oss:RestoreObject. Para obtener más información, consulte Grant custom permissions to a RAM user.

Restaurar un objeto Archive

A continuación se muestra el código para restaurar un objeto Archive:

<?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\CoreOssException;

// 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.
$provider = new EnvironmentVariableCredentialsProvider();
// The Endpoint is set to the China (Hangzhou) region. Replace it with the actual Endpoint.
$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 file.
    $ossClient->restoreObject($bucket, $object);
} catch (OssException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}
print(__FUNCTION__ . ": OK" . "\n");        

Restaurar un objeto Cold Archive

A continuación se muestra el código para restaurar un objeto Cold Archive:

<?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\CoreOssException;
use OSS\Model\RestoreConfig;

// 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.
$provider = new EnvironmentVariableCredentialsProvider();
// The Endpoint is set to the China (Hangzhou) region. Replace it with the actual Endpoint.
$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);
    // The number of days for which the object remains in the restored state. Valid values: 1 to 7.
    $day = 3; 
    // The restoration priority. This is set to Bulk, which means the object is restored within 5 to 12 hours.
    // To restore the object within 2 to 5 hours, set this parameter to Standard. To restore the object within 1 hour, set this parameter to Expedited.
    $tier = "Bulk"; 

    $config = new RestoreConfig($day,$tier);

    $options = array(
      OssClient::OSS_RESTORE_CONFIG => $config
    );

        $result = $ossClient->restoreObject($bucket, $object,$options);
} catch (OssException $e) {
    printf($e->getMessage() . "\n");
    return;
}            

Referencias

Para obtener más información sobre la operación de API que se usa para restaurar archivos Archive y Cold Archive, consulte RestoreObject.