This topic describes how to restore objects of the Archive and Cold Archive storage classes.

Note You must restore an archived or cold archived object before you can read it. Do not call RestoreObject to perform restore operations on objects of which the storage class is not Archive and Cold Archive. For more information about the Archive and Cold Archive storage classes, see Overview. For more information about related status codes, see RestoreObject in API Reference.

Restore archived objects

The status of an archived object throughout the restoration process is described as follows:
  1. By default, the archived object is in the frozen state.
  2. After you submit a restore request, the object is in the restoring state. It takes about one minute to complete the restore task.
  3. After the server completes the restore task, the object enters the restored state and you can read the object. By default, the restored state lasts 24 hours and can be extended by another 24 hours after you call RestoreObject again. During one restoration process, RestoreObject can be called on an object for up to seven times. In other words, an object can remain in the restored state for up to seven days.
  4. After the restored state expires, the object returns to the frozen state.

For the complete code, visit GitHub.

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

package main

import (
    "fmt"
    "os"
    "time"
    "strings"
    "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.
    client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
    if err ! = nil {
        HandleError(err)
    }

    bucketName := "<yourBucketName>"
    objectName := "<yourObjectName>"
    localFilename := "<yourLocalFilename>"

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

    // Obtain the bucket.
    archiveBucket, err := client.Bucket(bucketName)
    if err ! = nil {
        HandleError(err)
    }

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

    // Check whether the object is of the Archive storage class.
    meta, err := archiveBucket.GetObjectDetailedMeta(objectName)
    if err ! = nil {
        HandleError(err)
    }

    fmt.Println("X-Oss-Storage-Class : ", meta.Get("X-Oss-Storage-Class"))
    if meta.Get("X-Oss-Storage-Class") == string(oss.StorageArchive) {
        // Restore the archived object.
        err = archiveBucket.RestoreObject(objectName)
        if err ! = nil {
            HandleError(err)
        }

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

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

    // Restore the archived object again.
    err = archiveBucket.RestoreObject(objectName)

    fmt.Println("ArchiveSample completed")
}
			

Restore cold archived objects

The status of a cold archived object throughout the restoration process is described as follows:

  1. By default, the cold archived object is in the frozen state.
  2. After you submit a restore request, the object is in the restoring state. The time used to restore a cold archived object is determined based on one of the following restore modes:
    • 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 restore mode is Standard.
    • Bulk: The object is restored within five to eleven hours.
  3. After the server completes the restore task, the object enters the restored state and you can read the object. You can specify the duration for which the object can remain in the restored state, which ranges from one to seven days.
  4. After the restored state expires, the object returns to the frozen state.

The following code provides an example on how to restore a cold archived object:

package main

import (
    "fmt"
    "os"

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

func main() {
    // Create an OSSClient instance.
    client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
    if err ! = nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }

    // Obtain the bucket.
    bucket, err := client.Bucket("<yourBucketName>")
    if err ! = nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }

    var restoreConfig oss.RestoreConfiguration

    // The archived object is restored within one hour.
    restoreConfig.Tier = string(oss.RestoreExpedited)
    // The archived object is restored within five hours.
    //restoreConfig.Tier = string(oss.RestoreStandard)
    // The archived object is restored within ten hours.
    //restoreConfig.Tier = string(oss.RestoreBulk)

    // The restored state of the object lasts one day.
    restoreConfig.Days = 1
    err = bucket.RestoreObjectDetail("<yourObjectName>", restoreConfig)
    if err ! = nil {
        fmt.Println("Error:", err)
        os.Exit(-1)
    }
}