sebastianfeldmann /
phpbu
| 1 | <?php |
||
| 2 | namespace phpbu\App\Backup\Sync; |
||
| 3 | |||
| 4 | use Aws\S3\S3Client; |
||
| 5 | use phpbu\App\Result; |
||
| 6 | use phpbu\App\Backup\Target; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Amazon S3 Sync |
||
| 10 | * |
||
| 11 | * @package phpbu |
||
| 12 | * @subpackage Backup |
||
| 13 | * @author Sebastian Feldmann <[email protected]> |
||
| 14 | * @copyright Sebastian Feldmann <[email protected]> |
||
| 15 | * @license https://opensource.org/licenses/MIT The MIT License (MIT) |
||
| 16 | * @link http://phpbu.de/ |
||
| 17 | * @since Class available since Release 1.1.4 |
||
| 18 | */ |
||
| 19 | class AmazonS3v2 extends AmazonS3 |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Execute the sync. |
||
| 23 | * |
||
| 24 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 25 | * @param \phpbu\App\Backup\Target $target |
||
| 26 | * @param \phpbu\App\Result $result |
||
| 27 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 28 | */ |
||
| 29 | public function sync(Target $target, Result $result) |
||
| 30 | { |
||
| 31 | $sourcePath = $target->getPathname(); |
||
| 32 | $targetPath = $this->path . '/' . $target->getFilename(); |
||
| 33 | |||
| 34 | $s3 = S3Client::factory( |
||
|
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
| 35 | [ |
||
| 36 | 'signature' => 'v4', |
||
| 37 | 'region' => $this->region, |
||
| 38 | 'credentials' => [ |
||
| 39 | 'key' => $this->key, |
||
| 40 | 'secret' => $this->secret, |
||
| 41 | ] |
||
| 42 | ] |
||
| 43 | ); |
||
| 44 | |||
| 45 | try { |
||
| 46 | $fh = fopen($sourcePath, 'r'); |
||
| 47 | $s3->upload($this->bucket, $targetPath, $fh, $this->acl); |
||
| 48 | } catch (\Exception $e) { |
||
| 49 | throw new Exception($e->getMessage(), null, $e); |
||
| 50 | } |
||
| 51 | |||
| 52 | $result->debug('upload: done'); |
||
| 53 | } |
||
| 54 | } |
||
| 55 |