/** * (non-PHPDoc) * * @see \phpbu\App\Backup\Sync::sync() * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @throws \phpbu\App\Backup\Sync\Exception */ public function sync(Target $target, Result $result) { $sourcePath = $target->getPathname(); $dropboxPath = $this->path . $target->getFilename(); $client = new DropboxApi\Client($this->token, "phpbu/1.1.0"); $pathError = DropboxApi\Path::findErrorNonRoot($dropboxPath); if (substr(__FILE__, 0, 7) == 'phar://') { DropboxApi\RootCertificates::useExternalPaths(); } if ($pathError !== null) { throw new Exception(sprintf('Invalid \'dropbox-path\': %s', $pathError)); } $size = null; if (stream_is_local($sourcePath)) { $size = filesize($sourcePath); } try { $fp = fopen($sourcePath, 'rb'); $res = $client->uploadFile($dropboxPath, DropboxApi\WriteMode::add(), $fp, $size); fclose($fp); } catch (\Exception $e) { throw new Exception($e->getMessage(), null, $e); } $result->debug('upload: done (' . $res['size'] . ')'); }
/** * (non-PHPDoc) * * @see \phpbu\App\Backup\Sync::sync() * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @throws \phpbu\App\Backup\Sync\Exception */ public function sync(Target $target, Result $result) { $sourcePath = $target->getPathname(); $yandexDiskPath = $this->path . $target->getFilename(); $this->disk = new Disk($this->token); $size = null; if (stream_is_local($sourcePath)) { $size = filesize($sourcePath); } $file = $this->disk->resource(); $this->createFolders(); try { $file = $this->disk->resource($yandexDiskPath); $file->getContents(); } catch (NotFoundException $exc) { $file->upload($sourcePath, true); } if ($file->has()) { $result->debug('upload: done (' . $size . ')'); } else { $result->debug('upload: error while uploading file'); } }
/** * (non-PHPDoc) * * @see \phpbu\App\Backup\Sync::sync() * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @throws \phpbu\App\Backup\Sync\Exception */ public function sync(Target $target, Result $result) { // silence phpseclib $old = error_reporting(0); $sftp = new phpseclib\Net\SFTP($this->host); if (!$sftp->login($this->user, $this->password)) { error_reporting($old); throw new Exception(sprintf('authentication failed for %s@%s%s', $this->user, $this->host, empty($this->password) ? '' : ' with password ****')); } error_reporting($old); $remoteFilename = $target->getFilename(); $localFile = $target->getPathname(); if ('' !== $this->remotePath) { $remoteDirs = explode('/', $this->remotePath); foreach ($remoteDirs as $dir) { if (!$sftp->is_dir($dir)) { $result->debug(sprintf('creating remote dir \'%s\'', $dir)); $sftp->mkdir($dir); } $result->debug(sprintf('change to remote dir \'%s\'', $dir)); $sftp->chdir($dir); } } $result->debug(sprintf('store file \'%s\' as \'%s\'', $localFile, $remoteFilename)); $result->debug(sprintf('last error \'%s\'', $sftp->getLastSFTPError())); /** @noinspection PhpInternalEntityUsedInspection */ if (!$sftp->put($remoteFilename, $localFile, phpseclib\Net\SFTP::SOURCE_LOCAL_FILE)) { throw new Exception(sprintf('error uploading file: %s - %s', $localFile, $sftp->getLastSFTPError())); } }
/** * (non-PHPDoc) * * @see \phpbu\App\Backup\Sync::sync() * @param \phpbu\App\backup\Target $target * @param \phpbu\App\Result $result * @throws \phpbu\App\Backup\Sync\Exception */ public function sync(Target $target, Result $result) { $sourcePath = $target->getPathname(); $targetPath = $this->path . $target->getFilename(); $options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 20); $objectStorage = new ObjectStorage($this->host, $this->user, $this->secret, $options); $result->debug('softlayer source: ' . $sourcePath); $result->debug('softlayer target: ' . $targetPath); try { /** @var \ObjectStorage_Container $container */ $container = $objectStorage->with($this->container . $targetPath)->setLocalFile($sourcePath)->setMeta('description', 'PHPBU Backup: ' . date('r', time()))->setHeader('Content-Type', $target->getMimeType()); $container->create(); } catch (\Exception $e) { throw new Exception($e->getMessage(), null, $e); } $result->debug('upload: done'); }
/** * Execute the sync * * @see \phpbu\App\Backup\Sync::sync() * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @throws \phpbu\App\Backup\Sync\Exception */ public function sync(Target $target, Result $result) { $sourcePath = $target->getPathname(); $targetPath = $this->path . $target->getFilename(); $s3 = S3Client::factory(array('signature' => 'v4', 'region' => $this->region, 'credentials' => array('key' => $this->key, 'secret' => $this->secret))); try { $fh = fopen($sourcePath, 'r'); $s3->upload($this->bucket, $targetPath, $fh, $this->acl); } catch (\Exception $e) { throw new Exception($e->getMessage(), null, $e); } $result->debug('upload: done'); }
/** * (non-PHPDoc) * * @see \phpbu\App\Backup\Sync::sync() * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @throws \phpbu\App\Backup\Sync\Exception */ public function sync(Target $target, Result $result) { // silence ftp errors $old = error_reporting(0); if (!($ftpConnection = ftp_connect($this->host))) { throw new Exception(sprintf('Unable to connect to ftp server %s', $this->host)); } if (!ftp_login($ftpConnection, $this->user, $this->password)) { error_reporting($old); throw new Exception(sprintf('authentication failed for %s@%s%s', $this->user, $this->host, empty($this->password) ? '' : ' with password ****')); } $remoteFilename = $target->getFilename(); $localFile = $target->getPathname(); if ('' !== $this->remotePath) { $remoteDirs = explode('/', $this->remotePath); foreach ($remoteDirs as $dir) { if (!ftp_chdir($ftpConnection, $dir)) { $result->debug(sprintf('creating remote dir \'%s\'', $dir)); ftp_mkdir($ftpConnection, $dir); ftp_chdir($ftpConnection, $dir); } else { $result->debug(sprintf('change to remote dir \'%s\'', $dir)); } } } $result->debug(sprintf('store file \'%s\' as \'%s\'', $localFile, $remoteFilename)); if (!ftp_put($ftpConnection, $remoteFilename, $localFile, FTP_BINARY)) { $error = error_get_last(); $message = $error['message']; throw new Exception(sprintf('error uploading file: %s - %s', $localFile, $message)); } error_reporting($old); }
/** * (non-PHPDoc) * * @see \phpbu\App\Backup\Sync::sync() * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @throws \phpbu\App\Backup\Sync\Exception */ public function sync(Target $target, Result $result) { $sourcePath = $target->getPathname(); $targetPath = $this->path . $target->getFilename(); $copy = new CopycomApi($this->appKey, $this->appSecret, $this->userKey, $this->userSecret); try { // open a file to upload $fh = fopen($sourcePath, 'rb'); // upload the file in 1MB chunks $parts = array(); while ($data = fread($fh, 1024 * 1024)) { $part = $copy->sendData($data); array_push($parts, $part); } fclose($fh); // finalize the file $copy->createFile($targetPath, $parts); } catch (\Exception $e) { throw new Exception($e->getMessage(), null, $e); } $result->debug('upload: done'); }