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 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 or a Cold 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.
    • Archive objects

      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 extend the restored state 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 state in days by calling RestoreObject once. You can specify a duration of at most seven days.

    • Cold Archive objects
      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 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 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:

package main

import (
    "fmt"
    "os"
    "strings"
    "time"

    "github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func HandleError(err error) {
    fmt.Println("Error:", err)
    os.Exit(-1)
}

func main() {
    // Create an OSSClient instance. 
    // 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. Specify your actual endpoint. 
    // 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. 
    client, err := oss.New("yourEndpoint", "yourAccessKeyId", "yourAccessKeySecret")
    if err != nil {
        HandleError(err)
    }

    // Specify the bucket name. Example: examplebucket. 
    bucketName := "examplebucket"
    // Specify the full path of the object. The full path of the object cannot contain the bucket name. Example: exampledir/exampleobject.txt. 
    objectName := "exampledir/exampleobject.txt"
    // Specify the full path of the local file that you want to upload. Example: D:\\localpath\\examplefile.txt. 
    localFilename := "D:\\localpath\\examplefile.txt"

    // Create the bucket. 
    err = client.CreateBucket(bucketName, oss.StorageClass(oss.StorageArchive))
    if err != nil {
        HandleError(err)
    }
    
    archiveBucket, err := client.Bucket(bucketName)
    if err != nil {
        HandleError(err)
    }

    // Upload the object. 
    var val = "More than just cloud."
    err = archiveBucket.PutObject(objectName, strings.NewReader(val))
    if err != nil {
        HandleError(err)
    }

    // Query the storage class of the object. 
    meta, err := archiveBucket.GetObjectDetailedMeta(objectName)
    if err != nil {
        HandleError(err)
    }
    fmt.Println("X-Oss-Storage-Class : ", meta.Get("X-Oss-Storage-Class"))

    // Restore the Archive object. 
    err = archiveBucket.RestoreObject(objectName)
    if err != nil {
        HandleError(err)
    }

    // Wait until the Archive object is restored. 
    meta, err = archiveBucket.GetObjectDetailedMeta(objectName)
    if err != nil {
        HandleError(err)
    }
    for meta.Get("X-Oss-Restore") == "ongoing-request=\"true\"" {
        fmt.Println("x-oss-restore:" + meta.Get("X-Oss-Restore"))
        time.Sleep(10 * time.Second)
        meta, err = archiveBucket.GetObjectDetailedMeta(objectName)
        if err != nil {
            HandleError(err)
        }
    }
    fmt.Println("x-oss-restore:" + meta.Get("X-Oss-Restore"))

    // Download the restored object. 
    err = archiveBucket.GetObjectToFile(objectName, localFilename)
    if err != nil {
        HandleError(err)
    }

    // Restore the object again. The duration for which the object can remain in the restored state is extended by 24 hours. 
    err = archiveBucket.RestoreObject(objectName)
    if err != nil {
        HandleError(err)
    }

    fmt.Println("ArchiveSample completed")
}

Restore a Cold Archive object

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

package main

import (
    "fmt"
    "os"

    "github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
    // Create an OSSClient instance. 
    // 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. Specify your actual endpoint. 
    // 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. 
    client, err := oss.New("yourEndpoint", "yourAccessKeyId", "yourAccessKeySecret")
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }

    // Specify the bucket name. Example: examplebucket. 
    bucket, err := client.Bucket("examplebucket")
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }

    var restoreConfig oss.RestoreConfiguration

    // The object is restored within 1 hour. 
    // restoreConfig.Tier = string(oss.RestoreExpedited)
    // The object is restored within 2 to 5 hours. 
    // restoreConfig.Tier = string(oss.RestoreStandard)
    // The object is restored within 5 to 12 hours. 
    // restoreConfig.Tier = string(oss.RestoreBulk)

    // Specify the duration for which the object can remain in the restored state. Unit: days. Valid values: 1 to 365. 
    restoreConfig.Days = 1
    // Specify the full path of the object. The full path of the object cannot contain the bucket name. Example: exampledir/exampleobject.txt. 
    err = bucket.RestoreObjectDetail("exampledir/exampleobject.txt", restoreConfig)
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }
}

References

For more information about the API operation that you can call to restore Archive and Cold Archive objects, see RestoreObject.