/** * 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; }
/** * Create the Executable to run the elasticdump command. * * @param \phpbu\App\Backup\Target $target * @return \phpbu\App\Cli\Executable * @throws \phpbu\App\Exception */ public function getExecutable(Target $target) { if (null == $this->executable) { $this->executable = new Executable\Elasticdump($this->pathToElasticdump); $this->executable->useHost($this->host)->credentials($this->user, $this->password)->dumpIndex($this->index)->dumpType($this->type)->dumpTo($target->getPathnamePlain())->showStdErr($this->showStdErr); } return $this->executable; }
/** * 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; }
/** * Copy the redis RDB file to its backup location. * * @param \phpbu\App\Backup\Target $target * @return string * @throws \phpbu\App\Exception */ private function copyDumpToTargetDir(Target $target) { if (!file_exists($this->pathToRedisData)) { throw new Exception('Redis data not found at: \'' . $this->pathToRedisCli . '\''); } $targetFile = $target->getPathnamePlain(); copy($this->pathToRedisData, $targetFile); return $targetFile; }
/** * (non-PHPDoc) * * @see \phpbu\App\Backup\Source * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @return \phpbu\App\Backup\Source\Status * @throws \phpbu\App\Exception */ public function backup(Target $target, Result $result) { // setup dump location and execute the dump $this->dumpPathname = $target->getPathnamePlain(); $mysqldump = $this->execute($target); $result->debug($mysqldump->getCmd()); if (!$mysqldump->wasSuccessful()) { throw new Exception('mysqldump failed'); } return Status::create()->uncompressed()->dataPath($this->dumpPathname); }