/** * In here you should create your backup. * * @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) { $status = Status::create(); // use these methods to store the backup at the configured location // $target->getPath() // $target->getPathname() // $target->getFilename() // to know if the backup should be compressed use // $target->shouldBeCompressed() // to get the compression settings use // $target->getCompressor() // if you want to log some debug information use // $result->debug('some message'); // anything bad happens throw a \phpbu\App\Exception // Clone target class for the archiving part // $tarTarget = clone $target; // Rsync to a temporary directory // $date = new \DateTime(); // $target->setPath('/tmp/phpbu-rsync-' . $date->format('Ymd-His')); // Execute the sync $rsync = $this->execute($target); $result->debug($rsync->getCmd()); // if (!$rsync->wasSuccessful()) { throw new Exception('rsync failed: ' . PHP_EOL . $rsync->getOutputAsString()); } // Archive the synced files // $tarOptions = [ // 'path' => $target->getPath(), // // FIXME: removeDir boolean doesn't work. Value in Source/Tar class is not used or passed along to the executable // 'removeDir' => true, // 'showStdErr' => true, // ]; // // $tar = new Source\Tar(); // $tar->setup($tarOptions); // $tarResult = $tar->backup($tarTarget, $result); // // // If tar doesn't handle the compression mark status // // uncompressed so the app can take care of compression // if (!$tarResult->handledCompression()) { // $status->uncompressed()->dataPath($target->getPathnamePlain()); // } return $status; }
/** * (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) { $elasticdump = $this->execute($target); $result->debug($elasticdump->getCmd()); if (!$elasticdump->wasSuccessful()) { throw new Exception('elasticdump failed'); } return Status::create()->uncompressed($target->getPathnamePlain()); }
/** * (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) { // set uncompressed default MIME type $target->setMimeType('application/x-tar'); $status = Status::create(); $tar = $this->execute($target); // if tar doesn't handle the compression mark status uncompressed so the app can take care of compression if (!$this->executable->handlesCompression()) { $status->uncompressed($target->getPathnamePlain()); } $result->debug($tar->getCmd()); if (!$tar->wasSuccessful()) { throw new Exception('tar failed'); } return $status; }
/** * Execute the backup. * * @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) { // set uncompressed default MIME type $target->setMimeType('application/octet-stream'); $redisSave = $this->getExecutable($target); $redisLast = $this->getRedisLastSave($redisSave); $lastBackupTimestamp = $this->getLastBackupTime($redisLast); $saveResult = $redisSave->run(); $result->debug($saveResult->getCmd()); if (!$saveResult->wasSuccessful()) { throw new Exception('redis-cli BGSAVE failed'); } $this->isDumpCreatedYet($lastBackupTimestamp, $redisLast); $pathToDump = $this->copyDumpToTargetDir($target); return Status::create()->uncompressed($pathToDump); }
/** * (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 $mongodump = $this->execute($target); $result->debug($mongodump->getCmd()); if (!$mongodump->wasSuccessful()) { throw new Exception('Mongodump failed'); } return Status::create()->uncompressed($this->getDumpDir($target)); }
/** * (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) { $innobackupex = $this->execute($target); $result->debug($innobackupex->getCmd()); if (!$innobackupex->wasSuccessful()) { throw new Exception('XtraBackup failed'); } return Status::create()->uncompressed()->dataPath($this->getDumpDir($target)); }
/** * (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); }