Restoring Archive Objects
Function
To download an object in the Archive storage class, you need to restore it first. After it is restored, a copy of the object is saved in the Standard storage class. By doing so, the object in the Archive storage class and its copy in the Standard storage class co-exist in the bucket. The copy will be automatically deleted once its retention period expires.
This API is used to restore Archive objects in a specified bucket.
To extend the validity period of the Archive data restored, you can repeatedly restore the data, but you will be billed for each restoration. After a second restore, the validity period of Standard object copies will be prolonged, and you need to pay for storing these copies during the prolonged period.
Restrictions
- To restore an Archive object, you must be the bucket owner or have the required permission (obs:object:RestoreObject granted using IAM or RestoreObject granted using a bucket policy.) For details, see Introduction to OBS Access Control, IAM Custom Policies, and Configuring an Object Policy.
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
- To prolong the validity period of the Archive data restored, you can repeatedly restore the data, but you will be billed for each restore. After a second restore, the validity period of Standard object copies will be extended. You need to pay for storing these copies during the extended period.
Method
ObsClient.restoreObject(params)
Request Parameters
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| Bucket | str | Yes | Explanation: Bucket name Restrictions:
Default value: None |
| Key | str | Yes | Explanation: Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. For example, if the address for accessing the object is examplebucket.obs.ap-southeast-1.myhuaweicloud.com/folder/test.txt, the object name is folder/test.txt. Value range: The value must contain 1 to 1,024 characters. Default value: None |
| VersionId | str | No | Explanation: Default value: None. If this parameter is not specified, the latest version of the object is specified. |
| Days | int | Yes | Explanation: After an object is restored, a Standard copy is generated for the object. This parameter specifies how long the Standard copy can be retained, that is, the validity period of the restored object. Value range: The value ranges from 1 to 30, in days. Default value: None |
| Tier | str | No | Explanation: Tier of the restoration speed. You can select a suitable tier based on your needs. Value range:
Default value: None |
Responses
| Type | Description |
|---|---|
| Explanation: SDK common results |
| Parameter | Type | Description |
|---|---|---|
| status | int | Explanation: HTTP status code Value range: A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For more information, see Status Code. Default value: None |
| reason | str | Explanation: Reason description Default value: None |
| errorCode | str | Explanation: Error code returned by the OBS server. If the value of status is less than 300, this parameter is left blank. Default value: None |
| errorMessage | str | Explanation: Error message returned by the OBS server. If the value of status is less than 300, this parameter is left blank. Default value: None |
| requestId | str | Explanation: Request ID returned by the OBS server Default value: None |
| indicator | str | Explanation: Error indicator returned by the OBS server Default value: None |
| hostId | str | Explanation: Requested server ID. If the value of status is less than 300, this parameter is left blank. Default value: None |
| resource | str | Explanation: Error source (a bucket or an object). If the value of status is less than 300, this parameter is left blank. Default value: None |
| header | list | Explanation: Response header list, composed of tuples. Each tuple consists of two elements, respectively corresponding to the key and value of a response header. Default value: None |
| body | object | Explanation: Result content returned after the operation is successful. If the value of status is larger than 300, this parameter is left blank. The value varies with the API being called. For details, see the sections "Bucket-Related APIs" and "Object-Related APIs". Default value: None |
Sample Code
This example restores the Archive object objectname.
// Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK before storing them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables. Before running the code in this example, configure environment variables AccessKeyID and SecretAccessKey.
// The front-end code does not have the process environment variable, so you need to use a module bundler like webpack to define the process variable.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
const AK = process.env.AccessKeyID
const SK = process.env.SecretAccessKey
// (Optional) If you use a temporary AK and SK pair and a security token to access OBS, obtain them using environment variables.
const security_token= process.env.SecurityToken
// Set server to the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
const server = "https://obs.ap-southeast-1.myhuaweicloud.com"
// Create an ObsClient instance.
var obsClient = new ObsClient({
access_key_id: AK,
secret_access_key: SK,
server: server
});
async function restoreObject() {
try {
const params = {
Bucket: 'examplebucket',
Key: 'objectname',
// Specify an object version when versioning is enabled.
// VersionId: '',
// Specify the restoration validity period, which is the retention period of Standard copies. The value ranges from 1 to 30, in days.
Days: 1,
// Restore data at an expedited speed. If you want to restore data at a standard speed, set this parameter to Standard.
Tier: "Expedited"
};
// Restore the object.
const result = await obsClient.restoreObject(params);
if (result.CommonMsg.Status <= 300) {
console.log("Restore object(%s)'s tagging successful!", params.Key);
console.log("RequestId: %s", result.CommonMsg.RequestId);
return;
};
console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
console.log("Status: %d", result.CommonMsg.Status);
console.log("Code: %s", result.CommonMsg.Code);
console.log("Message: %s", result.CommonMsg.Message);
console.log("RequestId: %s", result.CommonMsg.RequestId);
} catch (error) {
console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
console.log(error);
};
};
restoreObject() Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot