/** * {@inheritdoc} */ public function process(array $files) { $tmpFile = Filename::temporaryFilename($this->filename); $processBuilder = new ProcessBuilder(); $processBuilder->add('tar'); if (!is_null($this->flags)) { $processBuilder->add($this->flags); } $processBuilder->add($tmpFile); /** * @var FileInterface $backup */ foreach ($files as $backup) { $processBuilder->add($backup->getPath()); } $process = $processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { throw new ProcessorException(sprintf('Unable to create gzip archive, reason: "%s".', $process->getErrorOutput())); } $this->getEventDispatcher()->addListener(BackupEvents::TERMINATE, function () use($tmpFile) { unlink($tmpFile); }); return array(File::fromLocal($tmpFile, dirname($tmpFile))); }
/** * {@inheritdoc} */ public function fetch() { $process = $this->buildProcess(); $process->run(); if (!$process->isSuccessful()) { throw new SourceException(sprintf('Unable to dump MySql database "%s", reason: "%s".', $this->database, $process->getErrorOutput())); } $mySqlDump = Filename::temporaryFile(sprintf('mysql-dump-%s-%s-%s.sql', $this->database, is_null($this->host) ? 'localhost' : $this->host, date('Y-m-d-H-i-s'))); if (file_put_contents($mySqlDump, $process->getOutput()) === false) { throw new \RuntimeException(sprintf('Unable to save MySql dump of database into "%s".', $mySqlDump)); } else { $this->getEventDispatcher()->addListener(BackupEvents::TERMINATE, function () use($mySqlDump) { unlink($mySqlDump); }); return array(File::fromLocal($mySqlDump, dirname($mySqlDump))); } }
/** * @test */ public function temporaryFile() { $filename = Filename::temporaryFile('some_test_name'); $this->assertTrue(file_exists($filename)); $this->assertNotFalse(strpos($filename, 'some_test_name')); }
/** * {@inheritdoc} */ public function setName($name) { $this->name = Filename::sanitize($name); return $this; }