Esempio n. 1
0
 /**
  * Returns the executable for this action.
  *
  * @param  \phpbu\App\Backup\Target $target
  * @return \phpbu\App\Cli\Executable
  */
 public function getExecutable(Target $target)
 {
     if (null === $this->executable) {
         $this->executable = new Tar($this->pathToCommand);
         $this->executable->archiveDirectory($this->path);
         $archiveName = Tar::isCompressorValid($target->getCompressor()->getCommand()) ? $target->getPathname() : $target->getPathnamePlain();
         $this->executable->archiveTo($archiveName)->useCompression($target->getCompressor()->getCommand())->removeSourceDirectory(true);
     }
     return $this->executable;
 }
Esempio n. 2
0
 /**
  * Returns the executable for this action.
  *
  * @param  \phpbu\App\Backup\Target $target
  * @return \phpbu\App\Cli\Executable
  */
 public function getExecutable(Target $target)
 {
     if (null === $this->executable) {
         $this->executable = new Compressor($target->getCompressor()->getCommand(), $this->pathToCommand);
         $this->executable->force(true)->compressFile($this->path);
     }
     return $this->executable;
 }
Esempio n. 3
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());
             }
         }
     }
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * If 'tar' can't compress with the requested compressor this will return false.
  *
  * @param  \phpbu\App\Backup\Target $target
  * @return bool
  */
 public function canCompress(Target $target)
 {
     return Tar::isCompressorValid($target->getCompressor()->getCommand());
 }