You must restore Archive, Cold Archive, and Deep Cold Archive objects before you can read the objects. This topic describes how to restore Archive, Cold Archive, and Deep Cold Archive objects.
Usage notes
You can call the RestoreObject operation to restore only Archive and Cold Archive objects.
In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access Object Storage Service (OSS) by using other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about the regions and endpoints supported by OSS, see Regions, endpoints and open ports.
In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
In this topic, an OSSClient instance is created by using an OSS endpoint. If you want to create an OSSClient instance by using custom domain names or Security Token Service (STS), see Initialization.
To restore objects, you must have the oss:RestoreObject
permission. For more information, see Attach a custom policy to a RAM user.
Restore an Archive object
The following sample code provides an example on how to restore an Archive object:
package main
import (
"log"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
log.Fatalf("Failed to create credentials provider: %v", err)
}
clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
clientOptions = append(clientOptions, oss.Region("yourRegion"))
clientOptions = append(clientOptions, oss.AuthVersion(oss.AuthV4))
client, err := oss.New("yourEndpoint", "", "", clientOptions...)
if err != nil {
log.Fatalf("Failed to create OSS client: %v", err)
}
bucketName := "examplebucket"
objectName := "exampledir/exampleobject.txt"
bucket, err := client.Bucket(bucketName)
if err != nil {
log.Fatalf("Failed to get bucket '%s': %v", bucketName, err)
}
err = bucket.RestoreObject(objectName)
if err != nil {
log.Fatalf("Failed to restore object '%s': %v", objectName, err)
}
log.Println("ArchiveSample completed")
}
Restore a Cold Archive or Deep Cold Archive object
The following sample code provides an example on how to restore a Cold Archive or Deep Cold Archive object:
package main
import (
"log"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
log.Fatalf("Failed to create credentials provider: %v", err)
}
clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
clientOptions = append(clientOptions, oss.Region("yourRegion"))
clientOptions = append(clientOptions, oss.AuthVersion(oss.AuthV4))
client, err := oss.New("yourEndpoint", "", "", clientOptions...)
if err != nil {
log.Fatalf("Failed to create OSS client: %v", err)
}
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
log.Fatalf("Failed to get bucket '%s': %v", bucketName, err)
}
var restoreConfig oss.RestoreConfiguration
restoreConfig.Tier = string(oss.RestoreBulk)
restoreConfig.Days = 1
objectName := "exampledir/exampleobject.txt"
err = bucket.RestoreObjectDetail(objectName, restoreConfig)
if err != nil {
log.Fatalf("Failed to restore object '%s': %v", objectName, err)
}
log.Println("ArchiveSample completed")
}
References
For more information about the API operation that you can call to restore Archive, Cold Archive, and Cold archive objects, see RestoreObject.