コード例 #1
0
ファイル: Executor.php プロジェクト: kachkaev/php-backup
 /**
  * @param Profile $profile
  * @param bool    $clear
  *
  * @return Backup[]
  *
  * @throws \Exception
  */
 public function backup(Profile $profile, $clear = false)
 {
     $scratchDir = $profile->getScratchDir();
     $processor = $profile->getProcessor();
     $filesystem = new Filesystem();
     if ($clear) {
         $this->logger->info('Clearing scratch directory...');
         $filesystem->remove($scratchDir);
     }
     if (!is_dir($scratchDir)) {
         $filesystem->mkdir($scratchDir);
     }
     $this->logger->info('Beginning backup...');
     foreach ($profile->getSources() as $source) {
         $source->fetch($scratchDir, $this->logger);
     }
     $filename = $processor->process($scratchDir, $profile->getNamer(), $this->logger);
     try {
         $backups = $this->sendToDestinations($profile, $filename);
     } catch (\Exception $e) {
         $processor->cleanup($filename, $this->logger);
         throw $e;
     }
     $processor->cleanup($filename, $this->logger);
     $this->logger->info('Done.');
     return $backups;
 }