Vous devez restaurer les objets de type Archive, Cold Archive et Deep Cold Archive avant de pouvoir les lire.
Notes
Appelez l'opération RestoreObject pour restaurer uniquement les objets de type Archive, Cold Archive et Deep Cold Archive.
Cette rubrique utilise le point de terminaison public de la région Chine (Hangzhou). Si vous souhaitez accéder à Object Storage Service (OSS) via d'autres services Alibaba Cloud situés dans la même région qu'OSS, utilisez un point de terminaison interne. Pour plus d'informations sur les régions et les points de terminaison pris en charge par OSS, consultez Régions et points de terminaison.
Dans cette rubrique, les identifiants d'accès sont récupérés depuis des variables d'environnement. Pour savoir comment configurer les identifiants d'accès, consultez Configurer les identifiants d'accès.
Cette rubrique illustre la création d'une instance OSSClient avec un endpoint OSS. Pour d'autres configurations, telles que l'utilisation d'un domaine personnalisé ou l'authentification via des identifiants du Security Token Service (STS), consultez Configurer un client (Go SDK V1).
Pour restaurer des objets, vous devez disposer de l'autorisation
oss:RestoreObject. Pour plus d'informations, consultez Accorder une politique personnalisée.
Restaurer un objet Archive
L'exemple de code suivant montre comment restaurer un objet Archive :
package main
import (
"log"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
log.Fatalf("Failed to create credentials provider: %v", err)
}
// 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.
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou. Specify the actual region.
clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
clientOptions = append(clientOptions, oss.Region("yourRegion"))
// Specify the version of the signature algorithm.
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)
}
// Specify the name of the bucket. Example: examplebucket.
bucketName := "examplebucket"
// Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt.
objectName := "exampledir/exampleobject.txt"
// Create a bucket.
bucket, err := client.Bucket(bucketName)
if err != nil {
log.Fatalf("Failed to get bucket '%s': %v", bucketName, err)
}
// Restore the Archive object.
err = bucket.RestoreObject(objectName)
if err != nil {
log.Fatalf("Failed to restore object '%s': %v", objectName, err)
}
log.Println("ArchiveSample completed")
}
Restaurer un objet Cold Archive ou Deep Cold Archive
L'exemple de code suivant montre comment restaurer un objet Cold Archive ou Deep Cold Archive :
package main
import (
"log"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
log.Fatalf("Failed to create credentials provider: %v", err)
}
// 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.
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou. Specify the actual region.
clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
clientOptions = append(clientOptions, oss.Region("yourRegion"))
// Specify the version of the signature algorithm.
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)
}
// Specify the name of the bucket. Example: examplebucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
log.Fatalf("Failed to get bucket '%s': %v", bucketName, err)
}
// Configure restoration parameters.
var restoreConfig oss.RestoreConfiguration
// Specify the restoration mode.
// Specify that the object is restored within 1 hour.
// restoreConfig.Tier = string(oss.RestoreExpedited)
// Specify that the object is restored within 2 to 5 hours.
// restoreConfig.Tier = string(oss.RestoreStandard)
// Specify that the object is restored within 5 to 12 hours.
restoreConfig.Tier = string(oss.RestoreBulk)
// Specify the duration for which the object remains in the restored state. Unit: days. Valid values: 1 to 365.
restoreConfig.Days = 1
// Restore the Cold Archive or Deep Cold Archive object.
// Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt.
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")
}
Référence
Pour plus d'informations sur l'opération API permettant de restaurer les objets de type Archive, Cold Archive et Deep Cold Archive, consultez RestoreObject.