Пример #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()
 {
     $backupFiles = array();
     foreach ($this->globs as $glob => $rootPath) {
         $files = glob($glob, GLOB_ERR);
         if ($files === false) {
             throw new SourceException(sprintf('GlobSource expression "%s" is not correct and it fails getting list of files.', $glob));
         } elseif (count($files)) {
             foreach ($files as $file) {
                 $backupFiles[] = File::fromLocal($file, $rootPath);
             }
         }
     }
     return $backupFiles;
 }
Пример #3
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)));
     }
 }
 /**
  * @test
  */
 public function incrementalBackup()
 {
     $this->clearDestination();
     $files = $this->fetchSomeFiles();
     $testDestination = $this->getDestination();
     $controlDestination = $this->getDestination();
     $tmpFile = tempnam(sys_get_temp_dir(), 'some_file.txt');
     file_put_contents($tmpFile, 'some data');
     $testDestination->push(new Backup('test_backup', array($files[0], File::fromLocal($tmpFile))));
     $this->assertTrue($controlDestination->has('test_backup'), 'Destination has a backup.');
     $this->assertEquals(2, count($controlDestination->get('test_backup')->getFiles()), 'Destination has same number of files as source.');
     $testDestination->push(new Backup('test_backup', $files));
     $controlDestination = $this->getDestination();
     $this->assertTrue($controlDestination->has('test_backup'), 'Destination has same backup.');
     $this->assertEquals(1, $controlDestination->count(), 'Destination has only one backup.');
     $this->assertEquals(count($files), count($controlDestination->get('test_backup')->getFiles()), 'Destination has 2 new files of source, one old, one file is removed.');
     $this->assertFalse(in_array(basename($tmpFile), array_map(function ($item) {
         return $item->getRelativePath();
     }, $controlDestination->get('test_backup')->getFiles())), 'Removed file is file created in tmp dir.');
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 protected function getFiles($path)
 {
     $result = array();
     foreach (Finder::create()->in($path)->files() as $file) {
         $file = File::fromSplFileInfo($file, $path);
         $result[$file->getRelativePath()] = $file;
     }
     return $result;
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 protected function getFiles($path)
 {
     $result = array();
     /**
      * @var \SplFileInfo $file
      */
     foreach ($this->flysystem->listContents($path, true) as $file) {
         if ($file['type'] == 'file') {
             $file = File::fromFlysystemMetadata($file, $path);
             $result[$file->getRelativePath()] = $file;
         }
     }
     return $result;
 }