Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Restore objects (OSS SDK for Go 1.0)

Son Güncelleme:Oct 01, 2026

Arşiv, Soğuk Arşiv ve Derin Soğuk Arşiv nesnelerini okuyabilmek için öncelikle bu nesneleri geri yüklemeniz gerekir.

Notlar

  • Yalnızca Arşiv, Soğuk Arşiv ve Derin Soğuk Arşiv nesnelerini geri yüklemek için RestoreObject işlemini çağırın.

  • Bu konuda Çin (Hangzhou) bölgesinin genel uç noktası kullanılmıştır. OSS ile aynı bölgedeki diğer Alibaba Cloud hizmetlerini kullanarak Object Storage Service (OSS) erişimi sağlamak istiyorsanız dahili bir uç nokta kullanın. OSS tarafından desteklenen bölgeler ve uç noktalar hakkında daha fazla bilgi için bkz. Bölgeler ve uç noktalar.

  • Bu konuda erişim kimlik bilgileri ortam değişkenlerinden alınmaktadır. Erişim kimlik bilgilerinin nasıl yapılandırılacağı hakkında daha fazla bilgi için bkz. Erişim kimlik bilgilerini yapılandırma.

  • Bu konu, bir OSS uç noktası kullanarak bir OSSClient örneği oluşturmayı göstermektedir. Özel bir alan adı kullanma veya Security Token Service (STS) kimlik bilgileriyle kimlik doğrulama gibi alternatif yapılandırmalar için bkz. İstemciyi yapılandırma (Go SDK V1).

  • Nesneleri geri yüklemek için oss:RestoreObject iznine sahip olmanız gerekir. Daha fazla bilgi için bkz. Özel ilke atama.

Arşiv nesnesini geri yükleme

Aşağıdaki örnek kod, bir Arşiv nesnesinin nasıl geri yükleneceğini gösterir:

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")
}

Soğuk Arşiv veya Derin Soğuk Arşiv nesnesini geri yükleme

Aşağıdaki örnek kod, bir Soğuk Arşiv veya Derin Soğuk Arşiv nesnesinin nasıl geri yükleneceğini gösterir:

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")
}

Başvuru Kaynakları

Arşiv, Soğuk Arşiv ve Derin Soğuk Arşiv nesnelerini geri yüklemek için çağırabileceğiniz API işlemi hakkında daha fazla bilgi için bkz. RestoreObject.