Arşiv veya Soğuk Arşiv nesnelerini okumadan önce bunları geri yüklemeniz gerekir. Bu konuda, Arşiv ve Soğuk Arşiv nesnelerinin nasıl geri yükleneceği açıklanmaktadır.
Notlar
Yalnızca Arşiv ve Soğuk Arşiv nesneleri RestoreObject yöntemini destekler.
Bu konuda Çin (Hangzhou) bölgesinin genel uç noktası kullanılmaktadır. OSS ile aynı bölgedeki diğer Alibaba Cloud hizmetlerinden OSS'e erişmek için dahili bir uç nokta kullanın. OSS bölgeleri ve uç noktaları hakkında daha fazla bilgi için bkz. Bölgeler ve uç noktalar.
Bu konuda, bir OSS uç noktası kullanarak bir OssClient örneği oluşturma işlemi gösterilmektedir. Özel etki alanı kullanma veya Security Token Service (STS) kimlik bilgileriyle kimlik doğrulama gibi alternatif yapılandırmalar için bkz. Bir OssClient örneği oluşturun.
Bir nesneyi geri yüklemek için
oss:RestoreObjectiznine sahip olmanız gerekir. Daha fazla bilgi için bkz. RAM kullanıcıya özel erişim ilkeleri atama.
Bir Arşiv nesnesini geri yükleme
Aşağıdaki kod, bir Arşiv nesnesinin nasıl geri yükleneceğini göstermektedir:
#include <alibabacloud/oss/OssClient.h>
#include <thread>
#include <chrono>
#include <algorithm>
using namespace AlibabaCloud::OSS;
int main(void)
{
/* Initialize OSS account information. */
/* Set yourEndpoint to the Endpoint of the region where the bucket is located. For example, for the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
std::string Endpoint = "yourEndpoint";
/* Set yourRegion to the region where the bucket is located. For example, for the China (Hangzhou) region, set the Region to cn-hangzhou. */
std::string Region = "yourRegion";
/* Set BucketName to the name of your bucket, for example, examplebucket. */
std::string BucketName = "examplebucket";
/* Set ObjectName to the full path of the Archive object. The path does not include the bucket name. */
std::string ObjectName = "yourObjectName";
/* Initialize network resources. */
InitializeSdk();
ClientConfiguration conf;
conf.signatureVersion = SignatureVersionType::V4;
/* Obtain access credentials from environment variables. Before you run this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set. */
auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
OssClient client(Endpoint, credentialsProvider, conf);
client.SetRegion(Region);
/* Restore the Archive object. */
auto outcome = client.RestoreObject(BucketName, ObjectName);
/* Objects that are not in the Archive storage class cannot be restored. */
if (!outcome.isSuccess()) {
/* Handle exceptions. */
std::cout << "RestoreObject fail, code: " << outcome.error().Code() <<
", message: " << outcome.error().Message() <<
", requestId: " << outcome.error().RequestId() << std::endl;
return -1;
}
std::string onGoingRestore("ongoing-request=\"false\"");
int maxWaitTimeInSeconds = 600;
while (maxWaitTimeInSeconds > 0)
{
auto meta = client.HeadObject(BucketName, ObjectName);
std::string restoreStatus = meta.result().HttpMetaData()["x-oss-restore"];
std::transform(restoreStatus.begin(), restoreStatus.end(), restoreStatus.begin(), ::tolower);
if (!restoreStatus.empty() &&
restoreStatus.compare(0, onGoingRestore.size(), onGoingRestore)==0) {
std::cout << " success, restore status:" << restoreStatus << std::endl;
/* The Archive object is successfully restored. */
break;
}
std::cout << " info, WaitTime:" << maxWaitTimeInSeconds
<< "; restore status:" << restoreStatus << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(10));
maxWaitTimeInSeconds--;
}
if (maxWaitTimeInSeconds == 0)
{
std::cout << "RestoreObject fail, TimeoutException" << std::endl;
}
/* Release network resources. */
ShutdownSdk();
return 0;
}
Bir Soğuk Arşiv nesnesini geri yükleme
Aşağıdaki kod, bir Soğuk Arşiv nesnesinin nasıl geri yükleneceğini göstermektedir:
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;
int main(void)
{
/* Initialize OSS account information. */
/* Set yourEndpoint to the Endpoint of the region where the bucket is located. For example, for the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
std::string Endpoint = "yourEndpoint";
/* Set yourRegion to the region where the bucket is located. For example, for the China (Hangzhou) region, set the Region to cn-hangzhou. */
std::string Region = "yourRegion";
/* Set BucketName to the name of your bucket, for example, examplebucket. */
std::string BucketName = "examplebucket";
/* Set ObjectName to the full path of the Cold Archive object. The path does not include the bucket name. */
std::string ObjectName = "yourObjectName";
/* Initialize network resources. */
InitializeSdk();
ClientConfiguration conf;
conf.signatureVersion = SignatureVersionType::V4;
/* Obtain access credentials from environment variables. Before you run this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set. */
auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
OssClient client(Endpoint, credentialsProvider, conf);
client.SetRegion(Region);
/* To specify the storage class as Cold Archive when you upload a file, see the following code. */
//auto content = std::make_shared<std::stringstream>("test");
//PutObjectRequest putRequest(BucketName, ObjectName, content);
//putRequest.MetaData().addHeader("x-oss-storage-class", "ColdArchive");
//auto putOutcome = client.PutObject(putRequest);
RestoreObjectRequest request(BucketName, ObjectName);
/* Set the number of days that the object remains in the restored state. The default value is 1. */
request.setDays(2);
/* Set the restoration priority for the Cold Archive object. TierType::Bulk indicates that the restoration is complete within 5 to 12 hours. */
request.setTierType(TierType::Bulk);
auto outcome = client.RestoreObject(request);
if (!outcome.isSuccess()) {
/* Handle exceptions. */
std::cout << "Delete Bucket Inventory fail" <<
",code:" << outcome.error().Code() <<
",message:" << outcome.error().Message() <<
",requestId:" << outcome.error().RequestId() << std::endl;
}
/* Release network resources. */
ShutdownSdk();
return 0;
}
İlgili bilgiler
Arşiv ve Soğuk Arşiv nesnelerinin nasıl geri yükleneceğini gösteren tam örnek kod için GitHub örneğine bakın.
Nesneleri geri yüklemek için çağırabileceğiniz API işlemi hakkında daha fazla bilgi için bkz. RestoreObject.