Ejemplo n.º 1
0
 /**
  *
  * @param string $restoreConfig
  *        	JSON-Encoded
  */
 public function scheduleRestoreJob($restoreConfig)
 {
     $c = json_decode($restoreConfig, true);
     $dataDir = $this->configService->getDataDir();
     // Get the parent of data directory
     $dataDir = substr($dataDir, 0, strrpos($dataDir, DIRECTORY_SEPARATOR));
     $logfileName = $this->configService->getLogfileName();
     $restoreHostName = $c['backupuser'] . '@' . $c['backupserver'];
     $keyFileName = $this->configService->getPrivateKeyFilename();
     $knownHostsFileName = $this->configService->getKnownHostsFileName();
     $restoreTargetFolder = $this->configService->getDataDir();
     $sshCommand = "ssh -q -i \"{$keyFileName}\" -o StrictHostKeyChecking=no -o UserKnownHostsFile={$knownHostsFileName}";
     $rsyncOptions = "-rtgov -e '{$sshCommand}' --numeric-ids --omit-dir-times";
     foreach ($c['include'] as $include) {
         $rsyncOptions .= " --include='{$include}'";
     }
     foreach ($c['exclude'] as $exclude) {
         $rsyncOptions .= " --exclude='{$exclude}'";
     }
     $rsyncCommand = "rsync {$rsyncOptions} {$restoreHostName}:" . $c['restorebase'] . "  {$dataDir} ";
     $command = "{$rsyncCommand} >> {$logfileName} 2>&1";
     $this->configService->setRestoreCommand($command);
     $this->configService->register($this->runOnceJob, '\\OCA\\EasyBackup\\RestoreCommandHandler');
     $date = date('Y-m-d H:i:s e');
     file_put_contents($logfileName, "[{$date}] " . $this->trans->t('Restore job will be executed with next CRON') . "\n", FILE_APPEND);
 }
 public function testRegisteredClassOfWrongType()
 {
     $this->setExpectedException('\\OCA\\EasyBackup\\EasyBackupException');
     $this->cut->register($this->runOnceJobMock, '\\OCA\\EasyBackup\\Service\\ConfigServiceTest');
 }