Ejemplo n.º 1
0
 /**
  * Run phpbu
  *
  * @param  \phpbu\App\Configuration $configuration
  * @param  \phpbu\App\Factory
  * @return \phpbu\App\Result
  */
 public function run(Configuration $configuration)
 {
     // TODO: don't rely on static/global settings this is ugly
     Util\Cli::registerBase('configuration', $configuration->getWorkingDirectory());
     $stop = false;
     $this->result = new Result();
     $this->configuration = $configuration;
     $this->setupEnvironment($configuration);
     $this->setupLoggers($configuration);
     $this->result->phpbuStart($configuration);
     // create backups
     /** @var \phpbu\App\Configuration\Backup $backup */
     foreach ($configuration->getBackups() as $backup) {
         if ($stop) {
             break;
         }
         // setup target and collector, reset failure state
         $target = $this->createTarget($backup->getTarget());
         $collector = new Collector($target);
         $this->failure = false;
         try {
             /*      ___  ___  _______ ____  _____
              *     / _ )/ _ |/ ___/ //_/ / / / _ \
              *    / _  / __ / /__/ ,< / /_/ / ___/
              *   /____/_/ |_\___/_/|_|\____/_/
              */
             $this->executeSource($backup, $target);
             /*     _______ _____________ ______
              *    / ___/ // / __/ ___/ //_/ __/
              *   / /__/ _  / _// /__/ ,< _\ \
              *   \___/_//_/___/\___/_/|_/___/
              */
             $this->executeChecks($backup, $target, $collector);
             /*     __________  _____  ______
              *    / ___/ _ \ \/ / _ \/_  __/
              *   / /__/ , _/\  / ___/ / /
              *   \___/_/|_| /_/_/    /_/
              */
             $this->executeCrypt($backup, $target);
             /*      ______  ___  ___________
              *     / __/\ \/ / |/ / ___/ __/
              *    _\ \   \  /    / /___\ \
              *   /___/   /_/_/|_/\___/___/
              */
             $this->executeSyncs($backup, $target);
             /*     _______   _______   _  ____  _____
              *    / ___/ /  / __/ _ | / |/ / / / / _ \
              *   / /__/ /__/ _// __ |/    / /_/ / ___/
              *   \___/____/___/_/ |_/_/|_/\____/_/
              */
             $this->executeCleanup($backup, $target, $collector);
         } catch (\Exception $e) {
             $this->result->debug('exception: ' . $e->getMessage());
             $this->result->addError($e);
             $this->result->backupFailed($backup);
             if ($backup->stopOnFailure()) {
                 $stop = true;
             }
         }
     }
     $this->result->phpbuEnd();
     return $this->result;
 }
Ejemplo n.º 2
0
 /**
  * Tests Check failed.
  */
 public function testBackupFailedOnFailedCheck()
 {
     $conf = new Configuration('/tmp/foo.xml');
     $backup = new Configuration\Backup('test-backup', false);
     $check = new Configuration\Backup\Check('sizemin', '10M');
     $result = new Result();
     $result->phpbuStart($conf);
     $result->backupStart($backup);
     $result->backupEnd($backup);
     $result->checkStart($check);
     $result->addError(new Exception('failed'));
     $result->checkFailed($check);
     $result->backupFailed($backup);
     $result->backupEnd($backup);
     $result->phpbuEnd();
     $this->assertFalse($result->wasSuccessful(), 'should be successful');
     $this->assertFalse($result->allOk(), 'should be ok');
     $this->assertEquals(1, $result->backupsFailedCount());
     $this->assertEquals(1, $result->checksFailedCount());
     $this->assertEquals(1, $result->errorCount());
     $this->assertEquals(1, count($result->getErrors()));
     $this->assertEquals(1, count($result->getBackups()));
 }