示例#1
0
 /**
  * Compress the configured directory.
  *
  * @param  \phpbu\App\Backup\Target $target
  * @param  \phpbu\App\Result        $result
  * @throws \phpbu\App\Exception
  */
 public function compress(Target $target, Result $result)
 {
     if (!$target->shouldBeCompressed()) {
         throw new Exception('target should not be compressed');
     }
     $res = $this->execute($target);
     $result->debug($res->getCmd());
     if (0 !== $res->getCode()) {
         throw new Exception('Failed to \'compress\' file: ' . $this->path);
     }
 }
示例#2
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());
             }
         }
     }
 }
示例#3
0
 /**
  * Compress the configured directory.
  *
  * @param  \phpbu\App\Backup\Target $target
  * @param  \phpbu\App\Result        $result
  * @return string
  * @throws \phpbu\App\Exception
  */
 public function compress(Target $target, Result $result)
 {
     if (!$target->shouldBeCompressed()) {
         throw new Exception('target should not be compressed');
     }
     if (!$this->isPathValid($this->path)) {
         throw new Exception('path to compress should be valid');
     }
     $res = $this->execute($target);
     $result->debug($res->getCmd());
     if (0 !== $res->getCode()) {
         throw new Exception('Failed to \'compress\' file: ' . $this->path);
     }
     return $this->getArchiveFile($target);
 }
 /**
  * Returns the executable for this action.
  *
  * @param \phpbu\App\Backup\Target $target
  *
  * @return \phpbu\App\Cli\Executable
  */
 public function getExecutable(Target $target)
 {
     if (!$this->executable) {
         $this->executable = new Rsync();
         $this->executable->setSourceUser($this->user)->setSourceHost($this->host)->setSourcePort($this->port)->setSourcePath($this->path)->exclude($this->excludes)->compressed($target->shouldBeCompressed())->setTargetPath($target->getPath());
     }
     return $this->executable;
 }
示例#5
0
文件: Tar.php 项目: imjerrybao/phpbu
 /**
  * Setup the Executable to run the 'tar' command.
  *
  * @param  \phpbu\App\Backup\Target
  * @return \phpbu\App\Cli\Executable
  */
 public function getExecutable(Target $target)
 {
     if (null == $this->executable) {
         // check if tar supports requested compression
         if ($target->shouldBeCompressed()) {
             if (!Executable\Tar::isCompressorValid($target->getCompressor()->getCommand())) {
                 $this->pathToArchive = $target->getPathnamePlain();
             } else {
                 // compression could be handled by the tar command
                 $this->pathToArchive = $target->getPathname();
                 $this->compression = $target->getCompressor()->getCommand();
             }
         } else {
             // no compression at all
             $this->pathToArchive = $target->getPathname();
         }
         $this->executable = new Executable\Tar($this->pathToTar);
         $this->executable->archiveDirectory($this->path)->useCompression($this->compression)->archiveTo($this->pathToArchive)->showStdErr($this->showStdErr);
     }
     return $this->executable;
 }
示例#6
0
 /**
  * Compress the backup if the source did not handle the compression.
  *
  * @param  \phpbu\App\Backup\Source\Status $status
  * @param  \phpbu\App\Backup\Target        $target
  * @param  \phpbu\App\Result               $result
  * @throws \phpbu\App\Exception
  */
 protected function compress(Status $status, Target $target, Result $result)
 {
     if ($target->shouldBeCompressed() && !$status->handledCompression()) {
         $this->handleCompression($target, $result, $status->getDataPath());
     }
 }