Inheritance: extends Aws\Common\Client\AbstractClient
コード例 #1
0
 public function testUploadAndDeleteArchives()
 {
     self::log('Create a 6MB+ string of test data to upload.');
     $length = 6 * Size::MB + 425;
     $content = EntityBody::factory(str_repeat('x', $length));
     $partSize = 4 * Size::MB;
     self::log('Perform a single upload.');
     $archiveId = $this->client->uploadArchive(array('vaultName' => self::TEST_VAULT, 'archiveDescription' => 'Foo   bar', 'body' => $content))->get('archiveId');
     $this->assertNotEmpty($archiveId);
     self::log('Delete the archive that was just uploaded.');
     $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $archiveId));
     sleep(3);
     self::log('Initiate a multipart upload with a part size of ' . $partSize . ' bytes.');
     $generator = UploadPartGenerator::factory($content, $partSize);
     $this->assertEquals($length, $generator->getArchiveSize());
     $uploadId = $this->client->initiateMultipartUpload(array('vaultName' => self::TEST_VAULT, 'partSize' => $partSize))->get('uploadId');
     /** @var $part UploadPart */
     foreach ($generator as $part) {
         self::log('Upload bytes ' . join('-', $part->getRange()) . '.');
         $this->client->uploadMultipartPart(array('vaultName' => self::TEST_VAULT, 'uploadId' => $uploadId, 'range' => $part->getFormattedRange(), 'checksum' => $part->getChecksum(), 'ContentSHA256' => $part->getContentHash(), 'body' => new ReadLimitEntityBody($content, $part->getSize(), $part->getOffset())));
         sleep(3);
     }
     self::log('Complete the multipart upload.');
     $archiveId = $this->client->completeMultipartUpload(array('vaultName' => self::TEST_VAULT, 'uploadId' => $uploadId, 'archiveSize' => $generator->getArchiveSize(), 'checksum' => $generator->getRootChecksum()))->get('archiveId');
     $this->assertNotEmpty($archiveId);
     self::log('Delete the archive that was just uploaded in parts.');
     $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $archiveId));
 }
コード例 #2
0
 public function testUploadAndDeleteArchives()
 {
     $length = 6 * Size::MB + 425;
     $content = EntityBody::factory(str_repeat('x', $length));
     $partSize = 2 * Size::MB;
     // Single upload
     $archiveId = $this->client->getCommand('UploadArchive', array('vaultName' => self::TEST_VAULT, 'archiveDescription' => 'Foo   bar', 'body' => $content))->getResult()->get('archiveId');
     $this->assertNotEmpty($archiveId);
     // Delete the archive
     $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $archiveId));
     sleep(3);
     // Multipart upload
     $generator = UploadPartGenerator::factory($content, $partSize);
     $this->assertEquals($length, $generator->getArchiveSize());
     $uploadId = $this->client->getCommand('InitiateMultipartUpload', array('vaultName' => self::TEST_VAULT, 'partSize' => (string) $partSize))->getResult()->get('uploadId');
     /** @var $part UploadPart */
     foreach ($generator as $part) {
         $this->client->uploadMultipartPart(array('vaultName' => self::TEST_VAULT, 'uploadId' => $uploadId, 'range' => $part->getFormattedRange(), 'checksum' => $part->getChecksum(), 'ContentSHA256' => $part->getContentHash(), 'body' => new ReadLimitEntityBody($content, $part->getSize(), $part->getOffset())));
         sleep(3);
     }
     $archiveId = $this->client->getCommand('CompleteMultipartUpload', array('vaultName' => self::TEST_VAULT, 'uploadId' => $uploadId, 'archiveSize' => $generator->getArchiveSize(), 'checksum' => $generator->getRootChecksum()))->getResult()->get('archiveId');
     $this->assertNotEmpty($archiveId);
     // Delete the archive
     $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $archiveId));
 }
コード例 #3
0
 public function testCanCompleteMultipartUpload()
 {
     $this->prepareTransfer();
     $model = $this->getMockBuilder('Guzzle\\Service\\Resource\\Model')->disableOriginalConstructor()->getMock();
     $command = $this->getMockBuilder('Guzzle\\Service\\Command\\OperationCommand')->disableOriginalConstructor()->getMock();
     $command->expects($this->any())->method('getResult')->will($this->returnValue($model));
     $this->client->expects($this->any())->method('getCommand')->will($this->returnValue($command));
     $this->assertInstanceOf('Guzzle\\Service\\Resource\\Model', $this->callProtectedMethod($this->transfer, 'complete'));
 }
コード例 #4
0
 public function testMultipartUploadAbstractions()
 {
     $source = EntityBody::factory(str_repeat('x', 6 * Size::MB + 425));
     /** @var $transfer Transfer */
     $transfer = UploadBuilder::newInstance()->setClient($this->client)->setSource($source)->setVaultName(self::TEST_VAULT)->setPartSize(Size::MB)->setArchiveDescription('Foo   bar   3')->build();
     $transfer->getEventDispatcher()->addListener($transfer::BEFORE_PART_UPLOAD, function ($event) {
         static $count = 0;
         if ($count > 2) {
             throw new \Exception();
         }
         $count++;
     });
     try {
         $transfer->upload();
         $serializedState = null;
         $this->fail('Unexpected code execution - exit point 1');
     } catch (MultipartUploadException $e) {
         $serializedState = serialize($e->getState());
     }
     $state = unserialize($serializedState);
     $this->assertInstanceOf('Aws\\Glacier\\Model\\MultipartUpload\\TransferState', $state);
     /** @var $transfer Transfer */
     $transfer = UploadBuilder::newInstance()->setClient($this->client)->setSource($source)->setVaultName(self::TEST_VAULT)->resumeFrom($state)->build();
     try {
         $result = $transfer->upload();
     } catch (MultipartUploadException $e) {
         $result = null;
         $this->fail('Unexpected code execution - exit point 2');
     }
     $this->assertNotEmpty($result['archiveId']);
     $this->assertEquals($result['checksum'], $transfer->getState()->getPartGenerator()->getRootChecksum());
     $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $result['archiveId']));
 }
コード例 #5
0
function client()
{
    static $client;
    if (is_null($client)) {
        $client = GlacierClient::factory(array('profile' => 'default', 'region' => 'us-west-2'));
    }
    return $client;
}
コード例 #6
0
 /**
  * Instantiate a GlacierClient object.
  *
  * @param string $accessKey
  * @param string $secretKey
  * @param array $config
  * @throws \InvalidArgumentException
  */
 public function __construct($accessKey, $secretKey, array $config = array())
 {
     if (empty($config['vault'])) {
         throw new InvalidArgumentException('Please provide a Glacier vault');
     }
     parent::__construct($accessKey, $secretKey, $config);
     $this->_client = GlacierClient::factory($this->_config);
 }
コード例 #7
0
ファイル: GlacierClientTest.php プロジェクト: noahkim/kowop
 /**
  * @covers Aws\Glacier\GlacierClient::factory
  */
 public function testFactoryInitializesClient()
 {
     $client = GlacierClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-west-2'));
     $this->assertInstanceOf('Aws\\Common\\Signature\\SignatureV4', $this->readAttribute($client, 'signature'));
     $this->assertInstanceOf('Aws\\Common\\Credentials\\Credentials', $client->getCredentials());
     $this->assertEquals('https://glacier.us-west-2.amazonaws.com', $client->getBaseUrl());
     $this->assertEquals('-', $client->getCommand('ListVaults')->get('accountId'));
 }
コード例 #8
0
 /**
  * Creates an UploadState object for a multipart upload by querying the
  * service for the specified upload's information.
  *
  * @param GlacierClient $client    GlacierClient object to use.
  * @param string        $vaultName Vault name for the multipart upload.
  * @param string        $uploadId  Upload ID for the multipart upload.
  * @param string        $accountId Account ID for the multipart upload.
  *
  * @return UploadState
  */
 public static function getStateFromService(GlacierClient $client, $vaultName, $uploadId, $accountId = '-')
 {
     $state = new UploadState(['accountId' => $accountId, 'vaultName' => $vaultName, 'uploadId' => $uploadId]);
     foreach ($client->getPaginator('ListParts', $state->getId()) as $result) {
         // Get the part size from the first part in the first result.
         if (!$state->getPartSize()) {
             $state->setPartSize($result['PartSizeInBytes']);
         }
         // Mark all the parts returned by ListParts as uploaded.
         foreach ($result['Parts'] as $part) {
             list($rangeIndex, $rangeSize) = self::parseRange($part['RangeInBytes'], $state->getPartSize());
             $state->markPartAsUploaded($rangeIndex, ['size' => $rangeSize, 'checksum' => $part['SHA256TreeHash']]);
         }
     }
     $state->setStatus(UploadState::INITIATED);
     return $state;
 }
コード例 #9
0
<!DOCTYPE html>

<html>

<body>

<?php 
//Load the PHP SDK
require "aws.phar";
use Aws\Glacier\GlacierClient;
use Aws\Common\Enum\Region;
//This is where we connect to the Glacier Server
$aws = GlacierClient::factory(array('key' => 'your key', 'secret' => 'your secret key', 'region' => Region::US_EAST_1));
//Request an update on all of your jobs
$result = $aws->listJobs(array('vaultName' => 'new-vault'));
$array = $result->get('JobList');
//Creates an array with metadata regarding your jobs
print_r($array);
?>

</body>

</html>
コード例 #10
0
ファイル: Amazon.php プロジェクト: sb15/server-backup
 public function __construct($key, $secret, $region = Region::US_EAST_1)
 {
     $this->glacier = GlacierClient::factory(array('key' => $key, 'secret' => $secret, 'region' => $region, 'ssl.certificate_authority' => false));
 }
コード例 #11
0
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
require 'vendor/autoload.php';
use Aws\Glacier\GlacierClient;
use Symfony\Component\Yaml\Yaml;
$countFiles = 0;
$file = 'config/config.yml';
$date = new DateTime(null, new DateTimeZone('America/Toronto'));
if ($file && file_exists($file)) {
    $config = Yaml::parse(file_get_contents($file));
}
$toUploadFolder = $config['files']['toUploadFolder'];
$extensionToUpload = $config['files']['extensionToUpload'];
$mysqlDump = sprintf('mysqldump -h %s -u %s -p%s %s | gzip > %s/%s.gz', $config['mysql']['host'], $config['mysql']['user'], $config['mysql']['pass'], $config['mysql']['db'], $toUploadFolder, $date->format('Y-m-d_H.i'));
//  system($mysqlDump);
$client = GlacierClient::factory(array('key' => $config['amazon']['amazonKey'], 'secret' => $config['amazon']['amazonSecret'], 'region' => $config['amazon']['amazonRegion']));
/*
    try {
       $result = $client->initiateJob(array(
           'accountId' => '-',
           'vaultName' => $config['amazon']['amazonVault'],
           'Type' => 'inventory-retrieval'
       ));

//  var_dump($result);

   } catch (Exception $e) {
       echo 'ERROR: ' .$e->getMessage();
   }
*/
// Getting info from my Vault:
コード例 #12
0
<?php

require_once "/var/awsbackups/amazonaws/aws-autoloader.php";
use Aws\Glacier\GlacierClient;
$client = GlacierClient::factory(array('key' => 'yourAmazonKey', 'secret' => 'yourAmazonsecret', 'region' => 'us-east-1'));
$vaultName = 'yourVaultName';
$dir = "/var/awsbackups/";
$tdate = date('m_d_Y');
// Open a directory, and read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if (sizeof(explode($tdate, $file)) > 1) {
                echo $file . " Going to upload";
                $result = $client->uploadArchive(array('vaultName' => $vaultName, 'body' => fopen($file, 'r')));
                $archiveId = $result->get('archiveId');
                echo "\nFile Uploaded and ArchiveID:" . $archiveId . "\n\n";
            }
        }
        closedir($dh);
    }
}