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);
 }
 /**
  * @ControllerManaged
  * @NoCSRFRequired
  *
  * Upload SSH private key file
  */
 protected function uploadSshKey()
 {
     $file = $this->request->getUploadedFile('easybackup_sshKeyFile');
     if (!$file || !file_exists($file['tmp_name'])) {
         throw new EasyBackupException('Uploaded file not found');
     }
     $key = file_get_contents($file['tmp_name']);
     if ($key === false || strlen($key) == 0) {
         throw new EasyBackupException('Uploaded file is empty');
     }
     if (!$this->backupService->validatePrivateSshKey($key)) {
         throw new EasyBackupException('Key is not well-formed');
     }
     $filename = $this->configService->getPrivateKeyFilename();
     if (!file_put_contents($filename, $key)) {
         throw new \Exception('Could not store private key in ' . $filename);
     }
     chmod($filename, 0600);
     $publicKey = $this->backupService->getPublicSshKeyFromPrivateKey();
     $this->configService->setPublicKey($publicKey);
     return array('preconditionsHtml' => $this->renderPreconditionsHtml(), 'publicKeyHtml' => $this->renderPublicKeyHtml());
 }