2

我正在尝试在 php 中创建一个存档和检索系统。当用户点击存档按钮时,特定文件将从标准存储移动到冰川存储,当点击恢复按钮时,冰川存储中的文件将检索到标准存储。

使用 AWS php SDK 3.0 api,我已成功将文件移动到 glacier vault 并为检索启动了存档检索作业,我在 3-5 小时后获得了作业 ID,并在 5 小时后使用该作业 ID,我尝试了 getJobOutput 函数。我得到的响应与 api 文档中提到的相同,但我没有在我的 s3 存储桶中获得恢复的文件。

这是我上传到冰川并从冰川恢复的代码

public function archiveAndRestore() {

$this->s3Client = new S3Client(Configure::read('AWScredentials'));
$this->glacier = GlacierClient::factory(Configure::read('AWScredentials'));

// Upload to glacier
$this->s3Client->registerStreamWrapper();
$context = stream_context_create([
    's3' => ['seekable' => true]
]);
$result = $this->glacier->uploadArchive(array(
    'vaultName' => 'archiveTest',
    'archiveDescription' => 'File Name is archiveTest.txt ',
    'body' => fopen('s3://storage-bucket/Videos/archiveTest.txt', 'r', false, $context),
));

$archiveid = $result->get('archiveId');
$jobId = $this->glacier->initiateJob([
    'accountId' => '-',
    'vaultName' => 'archiveTest',
    'jobParameters' => [
        'Type' => 'archive-retrieval',
        'ArchiveId' => 'ORgyyyqsKwoopp110EvFoyqj3G-csmOKLyy3IJnWF9Dpd8BJfwerEhg241nxHf6y6kNUUyhUHOaY4y8QvWBGESmAopa80f6GZ9C05tyyKANhY-qfBUB6YkfTABg',
    ],
]);   


$this->s3Client->registerStreamWrapper();
$context = stream_context_create([
    's3' => ['seekable' => true]
]);
$stream = fopen('s3://storage-bucket/RetrivedFiles/test1.txt', 'w');  
$result = $this->glacier->getJobOutput([
    'accountId' => '-',
    'jobId' => '2dddfffffff9SwZIOPWxcB7TLm_3apNx--2rIiD7SgjOJjjkrerrcN1YCtivh_zsmpLyczY4br-bhyyX0Ev5B7e6-D1',
    'vaultName' => 'archiveTest',
    'saveAs' => $stream,
]);
fclose($stream);    

}

根据文档(aws GetJobOutput 操作文档),getJobOutput 函数的 saveAs 属性是指定应该下载操作内容的位置。可以是文件的路径、fopen 返回的资源或 Guzzle\Http\EntityBodyInterface 对象。因为我也在 s3 中给出了文件的路径。会有什么问题。非常感谢任何帮助。提前致谢。

这是响应 $result 中包含的结果,与文档中提到的完全相同

Aws\Result 对象 ( [data:Aws\Result:private] => 数组 ( [body] => GuzzleHttp\Psr7\Stream 对象 ( [stream:GuzzleHttp\Psr7\Stream:private] => 资源 id #25 [大小: GuzzleHttp\Psr7\Stream:private] => [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [可读:GuzzleHttp\Psr7\Stream:private] => 1 [可写:GuzzleHttp\Psr7\Stream:private] = > 1 [uri:GuzzleHttp\Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => 数组 ()) [校验和] => c176c1843fd0c0fc662lh9bb8de916540e6f9dpk9b22020bbb8388jk6f81d01c2 [2状态] => contentRange] => [acceptRanges] => bytes [contentType] => application/octet-stream [archiveDescription] => 文件名是 children-wide.jpg [@metadata] => Array ([statusCode] => 200 [effectiveUri] =>https://glacier.region-name.amazonaws.com/-/vaults/vaultname/jobs/gFdjAl4xhTAVEnmffgfg-Ao3-xmmjghfmqkCLOR1m34gHLQpMd0a3WKCiRRrItv2bklawwZnq9KeIch3LKs8suZoJwk2_/output [headers] => Array ( [x-amzn-requestid] => NzAiVAfrMQbpSjj-2228iiKWK_VteDwNyFTUR7Kyu0duno [x -amz-sha256-tree-hash] => c176c1843khfullc662f09bb8de916540e6f9dcc9b22020bbb8388de6f81d1c2 [accept-ranges] => bytes [x-amz-archive-description] => 文件名是 children-wide.jpg [content-type] => application/octet-流 [内容长度] => 1452770 [日期] => 格林威治标准时间 2017 年 1 月 31 日星期二 03:34:26 [连接] => 关闭) [transferStats] => 数组 ([http] => 数组 ([0] = > 数组 ( ) ) ) ) )

4

1 回答 1

2

当您从 Glacier 恢复文件时,它不会再将 Standard 作为存储类。它仍然会显示冰川。确定文件是否从 Glacier 下来,

请改用 GetObject,并查看结果的恢复值。并将范围设置为“bytes=0-0”以跳过检索文件本身的内容。并确保捕获异常

如果对象在 Glacier 中且未恢复,AWS 将抛出 InvalidObjectStateError,如果未捕获错误,脚本将终止。

这就是您将看到的项目 resored。

["Restore"] => string(68)"ongoing-request="false", expiry-date="2017 年 10 月 12 日星期四 00:00:00 GMT ""

如果物品仍在冰川中,这就是您将得到的

致命错误:未捕获的异常“Aws\S3\Exception\S3Exception”,消息“在“OBJ PATH”上执行“GetObject”时出错;AWS HTTP 错误:客户端错误:GET OBJ PATH 导致403 Forbidden响应:InvalidObjectStateThe operation is not valid for the (truncated...) InvalidObjectState (client): The operation is not valid for the object's storage class - InvalidObjectStateThe operation is not valid for the object' s 存储类879A42BDC3939282VjgBNmLxhqesAaOnnUKkIahdr9OlUnTPASmjh8zZNVzLeYEDz+QooqoFjyaeoyXGeAa/IPxTBrA='GuzzleHttp\ Exception\ ClientException:客户端错误:`GET OBJ PATH in C:\inetpub\wwwroot\cruisecheap.com\php_aws\aws-s-dk-php_includes\awsSDK第 192 行的 src\WrappedHttpHandler.php

我希望这可以帮助你和其他有同样问题的人。

于 2017-10-27T18:12:56.873 回答