Question

I'm trying to use the php sdk with Glacier to upload database backups, I was able to create and delete vaults using the following code.

<?php
require 'aws.phar';

use Aws\Glacier\GlacierClient;
use Aws\Common\Enum\Region;

$aws = GlacierClient::factory(array(
    'key'    => 'key',
    'secret' => 'secret',
    'region' => Region::US_WEST_2
));
$aws->createVault(array('vaultName'=>'newvault'));

I saw the function uploadArchive(), initiateMultiPartUpload() and uploadMultipartPart(). As I understand I have to intialize the upload and then start to upload the file but I'm not sure which are the parameters the function takes.

I know the methods because they are mentioned here https://github.com/aws/aws-sdk-php/blob/master/src/Aws/Glacier/GlacierClient.php, the parameters is an array of arguments I can't find what each method needs to properly works and the documentation about glacier and php sdk practically doesn't exists.

Does anyone make this work? or found good documentation?

Was it helpful?

Solution

There are published API docs available for SDK 2. The API docs for the GlacierClient lists the parameters for each operation if you click on the little hash symbols on the right.

EDIT: A recent post on the AWS PHP Development Blog shows how to upload archives to Amazon Glacier using both the single and multipart upload options.

There is also the Amazon Glacier Developer Guide that is published by AWS. It's not specific to PHP, but it does talk more about how to use the service and what the parameters mean.

Though not documented in the API docs, the PHP SDK does some work in the background to help you with uploads for Glacier. In most cases the accountId parameter should be set to "-", so the SDK will default to this if you don't set one. Also, the SDK calculates the SHA hashes for you if not provided.

So, simple UploadArchive example (building off what was provided in the question) could be:

<?php

require 'vendor/autoload.php'; // Include Composer autoloader

use Aws\Glacier\GlacierClient;
use Aws\Common\Enum\Region;

$glacier = GlacierClient::factory(array(
    'key'    => 'key',
    'secret' => 'secret',
    'region' => Region::US_WEST_2
));

$glacier->createVault(array('vaultName' => 'new-vault'));

$result = $glacier->uploadArchive(array(
    'vaultName'          => 'new-vault',
    'archiveDescription' => 'This is my new archive',
    'body'               => 'the contents of the archive',
));

$archiveId = $result->get('archiveId');

There is still a lack of examples available, but I'd expect that to improve over time. Also, the AWS SDK for PHP forum is a good place to post questions specifically about the SDK since the SDK team is constantly monitoring the posts there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top