Ejemplo n.º 1
0
 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::setup()
  * @param  array $config
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function setup(array $config)
 {
     if (!class_exists('\\Barracuda\\Copy\\API')) {
         throw new Exception('Copy api not loaded: use composer "barracuda/copy": "1.1.*" to install');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'app.key')) {
         throw new Exception('API access key is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'app.secret')) {
         throw new Exception('API access secret is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'user.key')) {
         throw new Exception('User access key is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'user.secret')) {
         throw new Exception('User access secret is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'path')) {
         throw new Exception('copy.com path is mandatory');
     }
     $this->appKey = $config['app.key'];
     $this->appSecret = $config['app.secret'];
     $this->userKey = $config['user.key'];
     $this->userSecret = $config['user.secret'];
     $this->path = Str::withTrailingSlash(Str::replaceDatePlaceholders($config['path']));
 }
Ejemplo n.º 2
0
 /**
  * @see    \phpbu\App\Backup\Check::pass()
  * @param  \phpbu\App\Backup\Target    $target
  * @param  string                      $value
  * @param  \phpbu\App\Backup\Collector $collector
  * @param  \phpbu\App\Result           $result
  * @return boolean
  * @throws \phpbu\App\Exception
  */
 public function pass(Target $target, $value, Collector $collector, Result $result)
 {
     // throws App\Exception if file doesn't exist
     $actualSize = $target->getSize();
     $testSize = Str::toBytes($value);
     return $testSize <= $actualSize;
 }
Ejemplo n.º 3
0
 /**
  * Setup.
  *
  * @see    \phpbu\App\Backup\Source
  * @param  array $conf
  * @throws \phpbu\App\Exception
  */
 public function setup(array $conf = array())
 {
     $this->pathToTar = Util\Arr::getValue($conf, 'pathToTar');
     $this->showStdErr = Util\Str::toBoolean(Util\Arr::getValue($conf, 'showStdErr', ''), false);
     $this->path = Util\Arr::getValue($conf, 'path');
     $this->removeDir = Util\Str::toBoolean(Util\Arr::getValue($conf, 'removeDir', ''), false);
     if (empty($this->path)) {
         throw new Exception('path option is mandatory');
     }
 }
Ejemplo n.º 4
0
 /**
  * Setup.
  *
  * @see    \phpbu\App\Backup\Source
  * @param  array $conf
  * @throws \phpbu\App\Exception
  */
 public function setup(array $conf = array())
 {
     $this->setupSourceData($conf);
     // environment settings
     $this->pathToElasticdump = Util\Arr::getValue($conf, 'pathToElasticdump');
     $this->host = Util\Arr::getValue($conf, 'host', 'http://localhost:9200');
     $this->user = Util\Arr::getValue($conf, 'user');
     $this->password = Util\Arr::getValue($conf, 'password');
     $this->showStdErr = Util\Str::toBoolean(Util\Arr::getValue($conf, 'showStdErr', ''), false);
 }
Ejemplo n.º 5
0
 /**
  * Setup the Cleaner.
  *
  * @see    \phpbu\App\Backup\Cleanup::setup()
  * @param  array $options
  * @throws \phpbu\App\Backup\Cleaner\Exception
  */
 public function setup(array $options)
 {
     if (!isset($options['older'])) {
         throw new Exception('option \'older\' is missing');
     }
     try {
         $seconds = Str::toTime($options['older']);
     } catch (RuntimeException $e) {
         throw new Exception($e->getMessage());
     }
     $this->offsetRaw = $options['older'];
     $this->offsetSeconds = $seconds;
 }
Ejemplo n.º 6
0
 /**
  * Setup.
  *
  * @see    \phpbu\App\Backup\Source
  * @param  array $conf
  * @throws \phpbu\App\Exception
  */
 public function setup(array $conf = array())
 {
     $this->pathToRedisCli = Util\Arr::getValue($conf, 'pathToRedisCli');
     $this->showStdErr = Util\Str::toBoolean(Util\Arr::getValue($conf, 'showStdErr', ''), false);
     $this->pathToRedisData = Util\Arr::getValue($conf, 'pathToRedisData');
     $this->timeout = Util\Arr::getValue($conf, 'timeout', 45);
     $this->host = Util\Arr::getValue($conf, 'host');
     $this->port = Util\Arr::getValue($conf, 'port');
     $this->password = Util\Arr::getValue($conf, 'password');
     if (empty($this->pathToRedisData)) {
         throw new Exception('pathToRedisData option is mandatory');
     }
 }
Ejemplo n.º 7
0
 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::setup()
  * @param  array $config
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function setup(array $config)
 {
     if (!class_exists('\\Mackey\\Yandex\\Client')) {
         throw new Exception('Yandex.Disk sdk not loaded: use composer to install "arhitector/yandex"');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'token')) {
         throw new Exception('API access token is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'path')) {
         throw new Exception('yandex.disk path is mandatory');
     }
     $this->token = $config['token'];
     $this->path = Str::withTrailingSlash(Str::replaceDatePlaceholders($config['path']));
 }
Ejemplo n.º 8
0
 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::setup()
  * @param  array $config
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function setup(array $config)
 {
     if (!class_exists('\\Dropbox\\Client')) {
         throw new Exception('Dropbox sdk not loaded: use composer "dropbox/dropbox-sdk": "1.1.*" to install');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'token')) {
         throw new Exception('API access token is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'path')) {
         throw new Exception('dropbox path is mandatory');
     }
     $this->token = $config['token'];
     $this->path = Str::withTrailingSlash(Str::replaceDatePlaceholders($config['path']));
 }
Ejemplo n.º 9
0
 /**
  * Setup the the Cleaner.
  *
  * @see    \phpbu\App\Backup\Cleanup::setup()
  * @param  array $options
  * @throws \phpbu\App\Backup\Cleaner\Exception
  */
 public function setup(array $options)
 {
     if (!isset($options['size'])) {
         throw new Exception('option \'size\' is missing');
     }
     try {
         $bytes = Str::toBytes($options['size']);
     } catch (RuntimeException $e) {
         throw new Exception($e->getMessage());
     }
     $this->deleteTarget = isset($options['deleteTarget']) ? Str::toBoolean($options['deleteTarget'], false) : false;
     $this->capacityRaw = $options['size'];
     $this->capacityBytes = $bytes;
 }
Ejemplo n.º 10
0
 /**
  * Setup.
  *
  * @see    \phpbu\App\Backup\Crypter
  * @param  array $options
  * @throws Exception
  */
 public function setup(array $options = array())
 {
     if (!Util\Arr::isSetAndNotEmptyString($options, 'algorithm')) {
         throw new Exception('openssl expects \'algorithm\'');
     }
     if (!Util\Arr::isSetAndNotEmptyString($options, 'password') && !Util\Arr::isSetAndNotEmptyString($options, 'certFile')) {
         throw new Exception('openssl expects \'key\' or \'password\'');
     }
     $this->pathToOpenSSL = Util\Arr::getValue($options, 'pathToOpenSSL');
     $this->showStdErr = Util\Str::toBoolean(Util\Arr::getValue($options, 'showStdErr', ''), false);
     $this->keepUncrypted = Util\Str::toBoolean(Util\Arr::getValue($options, 'keepUncrypted', ''), false);
     $this->certFile = $this->toAbsolutePath(Util\Arr::getValue($options, 'certFile'));
     $this->algorithm = Util\Arr::getValue($options, 'algorithm');
     $this->password = Util\Arr::getValue($options, 'password');
 }
Ejemplo n.º 11
0
 /**
  * Setup.
  *
  * @see    \phpbu\App\Backup\Crypter
  * @param  array $options
  * @throws Exception
  */
 public function setup(array $options = array())
 {
     if (!Util\Arr::isSetAndNotEmptyString($options, 'algorithm')) {
         throw new Exception('mcrypt \'algorithm\' is mandatory');
     }
     $this->pathToMcrypt = Util\Arr::getValue($options, 'pathToMcrypt');
     $this->showStdErr = Util\Str::toBoolean(Util\Arr::getValue($options, 'showStdErr', ''), false);
     $this->keepUncrypted = Util\Str::toBoolean(Util\Arr::getValue($options, 'keepUncrypted', ''), false);
     $this->key = Util\Arr::getValue($options, 'key');
     $this->keyFile = $this->toAbsolutePath(Util\Arr::getValue($options, 'keyFile'));
     $this->algorithm = $options['algorithm'];
     $this->hash = Util\Arr::getValue($options, 'hash');
     $this->config = $this->toAbsolutePath(Util\Arr::getValue($options, 'config'));
     if (empty($this->key) && empty($this->keyFile)) {
         throw new Exception('one of \'key\' or \'keyFile\' is mandatory');
     }
 }
Ejemplo n.º 12
0
 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::setup()
  * @param  array $config
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function setup(array $config)
 {
     if (!class_exists('\\phpseclib\\Net\\SFTP')) {
         throw new Exception('phpseclib not installed - use composer to install "phpseclib/phpseclib" version 2.x');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'host')) {
         throw new Exception('option \'host\' is missing');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'user')) {
         throw new Exception('option \'user\' is missing');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'password')) {
         throw new Exception('option \'password\' is missing');
     }
     $path = Arr::getValue($config, 'path', '');
     if ('/' === substr($path, 0, 1)) {
         throw new Exception('absolute path is not allowed');
     }
     $this->host = $config['host'];
     $this->user = $config['user'];
     $this->password = $config['password'];
     $this->remotePath = Str::withoutTrailingSlash(Str::replaceDatePlaceholders($path));
 }
Ejemplo n.º 13
0
 public function setup(array $config)
 {
     if (!function_exists('ftp_connect')) {
         throw new Exception('ftp functions not enabled');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'host')) {
         throw new Exception('option \'host\' is missing');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'user')) {
         throw new Exception('option \'user\' is missing');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'password')) {
         throw new Exception('option \'password\' is missing');
     }
     $path = Arr::getValue($config, 'path', '');
     if ('/' === substr($path, 0, 1)) {
         throw new Exception('absolute path is not allowed');
     }
     $this->host = $config['host'];
     $this->user = $config['user'];
     $this->password = $config['password'];
     $this->remotePath = Str::withoutTrailingSlash(Str::replaceDatePlaceholders($path));
 }
Ejemplo n.º 14
0
 /**
  * Recursive backup collecting.
  *
  * @param string  $path
  * @param integer $depth
  */
 protected function collect($path, $depth)
 {
     $dItter = new DirectoryIterator($path);
     // collect all matching subdirs and get all the backup files
     if ($depth < $this->target->countChangingPathElements()) {
         foreach ($dItter as $i => $file) {
             if ($file->isDot()) {
                 continue;
             }
             // TODO: match directory against dir-regex Target::getChangingPathElements
             if ($file->isDir()) {
                 $this->collect($file->getPathname(), $depth + 1);
             }
         }
     } else {
         // create regex to match only created backup files
         $fileRegex = Str::datePlaceholdersToRegex($this->target->getFilenameRaw());
         if ($this->target->shouldBeCompressed()) {
             $fileRegex .= '.' . $this->target->getCompressor()->getSuffix();
         }
         /** @var \SplFileInfo $file */
         foreach ($dItter as $i => $file) {
             if ($file->isDir()) {
                 continue;
             }
             // skip currently created backup
             if ($file->getPathname() == $this->target->getPathname()) {
                 continue;
             }
             if (preg_match('#' . $fileRegex . '#i', $file->getFilename())) {
                 $index = date('YmdHis', $file->getMTime()) . '-' . $i . '-' . $file->getPathname();
                 $this->files[$index] = new File($file->getFileInfo());
             }
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Fetch databases and collections to backup.
  *
  * @param array $conf
  */
 protected function setupSourceData(array $conf)
 {
     $this->databases = Util\Str::toList(Util\Arr::getValue($conf, 'databases'));
     $this->collections = Util\Str::toList(Util\Arr::getValue($conf, 'collections'));
     $this->excludeCollections = Util\Str::toList(Util\Arr::getValue($conf, 'excludeCollections'));
     $this->excludeCollectionsWithPrefix = Util\Str::toList(Util\Arr::getValue($conf, 'excludeCollectionsWithPrefix'));
 }
Ejemplo n.º 16
0
 /**
  * Filename setter.
  *
  * @param string  $file
  * @param integer $time
  */
 public function setFile($file, $time = null)
 {
     $this->filenameRaw = $file;
     if (false !== strpos($file, '%')) {
         $this->filenameIsChanging = true;
         $file = Str::replaceDatePlaceholders($file, $time);
     }
     $this->filename = $file;
 }
Ejemplo n.º 17
0
 /**
  * Set the cleanup configuration.
  *
  * @param  \phpbu\App\Configuration\Backup $backup
  * @param  \DOMElement                     $node
  * @throws \phpbu\App\Exception
  */
 protected function setCleanup(Configuration\Backup $backup, DOMElement $node)
 {
     /** @var \DOMNodeList $cleanupNodes */
     $cleanupNodes = $node->getElementsByTagName('cleanup');
     if ($cleanupNodes->length > 0) {
         /** @var \DOMElement $cleanupNode */
         $cleanupNode = $cleanupNodes->item(0);
         $type = $cleanupNode->getAttribute('type');
         if (!$type) {
             throw new Exception('invalid cleanup configuration: attribute type missing');
         }
         $skip = Str::toBoolean($cleanupNode->getAttribute('skipOnFailure'), true);
         $options = $this->getOptions($cleanupNode);
         $backup->setCleanup(new Configuration\Backup\Cleanup($type, $skip, $options));
     }
 }
Ejemplo n.º 18
0
 /**
  * Prints 'OK' or 'FAILURE' footer.
  *
  * @param Result $result
  */
 protected function printFooter(Result $result)
 {
     if (count($result->getBackups()) === 0) {
         $this->writeWithColor('fg-black, bg-yellow', 'No backups executed!');
     } elseif ($result->allOk()) {
         $this->writeWithColor('fg-black, bg-green', sprintf('OK (%d %s, %d %s, %d %s, %d %s, %d %s)' . PHP_EOL, count($result->getBackups()), Util\Str::appendPluralS('backup', count($result->getBackups())), $this->numChecks, Util\Str::appendPluralS('check', $this->numChecks), $this->numCrypts, Util\Str::appendPluralS('crypt', $this->numCrypts), $this->numSyncs, Util\Str::appendPluralS('sync', $this->numSyncs), $this->numCleanups, Util\Str::appendPluralS('cleanup', $this->numCleanups)));
     } elseif ($result->backupOkButSkipsOrFails()) {
         $this->writeWithColor('fg-black, bg-yellow', sprintf("OK, but skipped|failed Crypts, Syncs or Cleanups!\n" . 'Backups: %d, Crypts: %d|%d, Syncs: %d|%d, Cleanups: %d|%d.' . PHP_EOL, count($result->getBackups()), $result->cryptsSkippedCount(), $result->cryptsFailedCount(), $result->syncsSkippedCount(), $result->syncsFailedCount(), $result->cleanupsSkippedCount(), $result->cleanupsFailedCount()));
     } else {
         $this->writeWithColor('fg-white, bg-red', sprintf("FAILURE!\n" . 'Backups: %d, failed Checks: %d, failed Crypts: %d, failed Syncs: %d, failed Cleanups: %d.' . PHP_EOL, count($result->getBackups()), $result->checksFailedCount(), $result->cryptsFailedCount(), $result->syncsFailedCount(), $result->cleanupsFailedCount()));
     }
 }
Ejemplo n.º 19
0
 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::setup()
  * @param  array $config
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function setup(array $config)
 {
     if (!class_exists('\\ObjectStorage')) {
         throw new Exception('SoftLayer SDK not loaded: use composer "softlayer/objectstorage": "dev-master" to install');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'user')) {
         throw new Exception('SoftLayer user is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'secret')) {
         throw new Exception('SoftLayer password is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'container')) {
         throw new Exception('SoftLayer container name is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'host')) {
         throw new Exception('SoftLayer host is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'path')) {
         throw new Exception('SoftLayer path is mandatory');
     }
     $this->user = $config['user'];
     $this->secret = $config['secret'];
     $this->container = $config['container'];
     $this->host = $config['host'];
     $this->path = Str::withLeadingSlash(Str::withTrailingSlash(Str::replaceDatePlaceholders($config['path'])));
 }
Ejemplo n.º 20
0
 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::setup()
  * @param  array $config
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function setup(array $config)
 {
     if (!class_exists('\\Aws\\S3\\S3Client')) {
         throw new Exception('Amazon SDK not loaded: use composer "aws/aws-sdk-php": "2.7.*" to install');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'key')) {
         throw new Exception('AWS key is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'secret')) {
         throw new Exception('AWS secret is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'bucket')) {
         throw new Exception('AWS S3 bucket name is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'region')) {
         throw new Exception('AWS S3 region is mandatory');
     }
     if (!Arr::isSetAndNotEmptyString($config, 'path')) {
         throw new Exception('AWS S3 path / object-key is mandatory');
     }
     $this->key = $config['key'];
     $this->secret = $config['secret'];
     $this->bucket = $config['bucket'];
     $this->region = $config['region'];
     $this->path = Str::withTrailingSlash(Str::replaceDatePlaceholders($config['path']));
     $this->acl = Arr::getValue($config, 'acl', 'private');
 }
Ejemplo n.º 21
0
 /**
  * Get collections and data to backup.
  *
  * @param array $conf
  */
 protected function setupSourceData(array $conf)
 {
     $this->dumpData = Util\Str::toBoolean(Util\Arr::getValue($conf, 'dumpData'), false);
     $this->includeSystemCollections = Util\Str::toBoolean(Util\Arr::getValue($conf, 'includeSystemCollections'), false);
     $this->collections = Util\Str::toList(Util\Arr::getValue($conf, 'collections'));
 }
Ejemplo n.º 22
0
 /**
  * Create the Exec to run the 'rsync' command.
  *
  * @param  \phpbu\App\Backup\Target $target
  * @return \phpbu\App\Cli\Executable
  */
 public function getExecutable(Target $target)
 {
     if (null == $this->executable) {
         $this->executable = new Executable\Rsync($this->pathToRsync);
         if (!empty($this->args)) {
             $this->executable->useArgs(Util\Str::replaceTargetPlaceholders($this->args, $target->getPathname()));
         } else {
             $this->executable->syncFrom($this->getSyncSource($target))->toHost($this->host)->toPath($this->path)->asUser($this->user)->compressed(!$target->shouldBeCompressed())->removeDeleted($this->delete)->exclude($this->excludes);
         }
     }
     return $this->executable;
 }
Ejemplo n.º 23
0
 /**
  * Return mail status html
  *
  * @param  \phpbu\App\Result $result
  * @return string
  */
 protected function getStatusHtml(Result $result)
 {
     if (count($result->getBackups()) === 0) {
         $color = TPL::getSnippet('cStatusWARN');
         $status = 'WARNING';
     } elseif ($result->allOk()) {
         $color = TPL::getSnippet('cStatusOK');
         $status = 'OK';
     } elseif ($result->backupOkButSkipsOrFails()) {
         $color = TPL::getSnippet('cStatusWARN');
         $status = 'WARNING';
     } else {
         $color = TPL::getSnippet('cStatusFAIL');
         $status = 'FAILURE';
     }
     $info = sprintf('(%d %s, %d %s, %d %s, %d %s, %d %s)', count($result->getBackups()), Str::appendPluralS('backup', count($result->getBackups())), $this->numChecks, Str::appendPluralS('check', $this->numChecks), $this->numCrypts, Str::appendPluralS('crypt', $this->numCrypts), $this->numSyncs, Str::appendPluralS('sync', $this->numSyncs), $this->numCleanups, Str::appendPluralS('cleanup', $this->numCleanups));
     $html = '<table ' . sprintf(TPL::getSnippet('sTableStatus'), $color) . '>' . '<tr><td>' . '<span ' . TPL::getSnippet('sTableStatusText') . '>' . date('Y-m-d H:i') . '</span>' . '<h1 ' . TPL::getSnippet('sTableStatusHead') . '>' . $status . '</h1>' . '<span ' . TPL::getSnippet('sTableStatusText') . '>' . $info . '</span>' . '</td></tr>' . '</table>';
     return $html;
 }
Ejemplo n.º 24
0
 /**
  * Get a fake last modified date.
  *
  * @param  string $offset
  * @return integer
  */
 protected function getMTime($offset)
 {
     return $this->getTime() - Str::toTime($offset);
 }
Ejemplo n.º 25
0
 /**
  * Get tables and databases to backup.
  *
  * @param array $conf
  */
 protected function setupSourceData(array $conf)
 {
     $this->tables = Util\Str::toList(Util\Arr::getValue($conf, 'tables'));
     $this->databases = Util\Str::toList(Util\Arr::getValue($conf, 'databases'));
     $this->ignoreTables = Util\Str::toList(Util\Arr::getValue($conf, 'ignoreTables'));
     $this->structureOnly = Util\Str::toList(Util\Arr::getValue($conf, 'structureOnly'));
 }
Ejemplo n.º 26
0
 /**
  * Get tables and databases to backup.
  *
  * @param array $conf
  */
 protected function setupSourceData(array $conf)
 {
     $this->include = Util\Arr::getValue($conf, 'include');
     $this->databases = Util\Str::toList(Util\Arr::getValue($conf, 'databases'));
 }