コード例 #1
0
 /**
  * {@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)));
 }
コード例 #2
0
 /**
  * {@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)));
     }
 }
コード例 #3
0
ファイル: FilenameTest.php プロジェクト: runopencode/backup
 /**
  * @test
  */
 public function temporaryFile()
 {
     $filename = Filename::temporaryFile('some_test_name');
     $this->assertTrue(file_exists($filename));
     $this->assertNotFalse(strpos($filename, 'some_test_name'));
 }
コード例 #4
0
ファイル: Backup.php プロジェクト: runopencode/backup
 /**
  * {@inheritdoc}
  */
 public function setName($name)
 {
     $this->name = Filename::sanitize($name);
     return $this;
 }