コード例 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = $this->getContainer()->get('BnvWebLogger');
     $context = array('source' => 'DeleteJobBackupsCommand');
     $backupsDir = Globals::getSnapshotRoot($input->getArgument('client'), $input->getArgument('job'));
     if (Globals::delTree($backupsDir)) {
         $logger->info('Directory deleted: ' . $backupsDir, array('source' => 'DeleteJobBackupsCommand'));
         return 0;
     } else {
         $logger->err('Error deleting directory: ' . $backupsDir, array('source' => 'DeleteJobBackupsCommand'));
         return 1;
     }
 }
コード例 #2
0
 public function up(Schema $schema)
 {
     // this up() migration is autogenerated, please modify it to your needs
     $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
     $scripts = scandir(Globals::getUploadDir());
     $this->abortIf(false == $scripts);
     $this->addSql("CREATE TABLE Script (id INT AUTO_INCREMENT NOT NULL, description LONGTEXT DEFAULT NULL, name VARCHAR(255) NOT NULL, isClientPre TINYINT(1) NOT NULL, isJobPre TINYINT(1) NOT NULL, isClientPost TINYINT(1) NOT NULL, isJobPost TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_1B2D820C5E237E06 (name), PRIMARY KEY(id)) ENGINE = InnoDB");
     $this->addSql("ALTER TABLE Client ADD postScript_id INT DEFAULT NULL, ADD preScript_id INT DEFAULT NULL, DROP postScript, DROP preScript");
     $this->addSql("ALTER TABLE Client ADD CONSTRAINT FK_C0E80163B21C5632 FOREIGN KEY (postScript_id) REFERENCES Script (id)");
     $this->addSql("ALTER TABLE Client ADD CONSTRAINT FK_C0E80163B27EDC0 FOREIGN KEY (preScript_id) REFERENCES Script (id)");
     $this->addSql("CREATE INDEX IDX_C0E80163B21C5632 ON Client (postScript_id)");
     $this->addSql("CREATE INDEX IDX_C0E80163B27EDC0 ON Client (preScript_id)");
     $this->addSql("ALTER TABLE Job ADD postScript_id INT DEFAULT NULL, ADD preScript_id INT DEFAULT NULL, DROP postScript, DROP preScript");
     $this->addSql("ALTER TABLE Job ADD CONSTRAINT FK_C395A618B21C5632 FOREIGN KEY (postScript_id) REFERENCES Script (id)");
     $this->addSql("ALTER TABLE Job ADD CONSTRAINT FK_C395A618B27EDC0 FOREIGN KEY (preScript_id) REFERENCES Script (id)");
     $this->addSql("CREATE INDEX IDX_C395A618B21C5632 ON Job (postScript_id)");
     $this->addSql("CREATE INDEX IDX_C395A618B27EDC0 ON Job (preScript_id)");
     $idScript = 1;
     foreach ($scripts as $script) {
         $matches = array();
         if (preg_match('/^([0-9]{4})(?:_([0-9]{4}))?[.](pre|post)$/', $script, $matches)) {
             list($name, $clientId, $jobId, $preOrPost) = $matches;
             $clientId = (int) $clientId;
             $isPost = $preOrPost == 'post';
             $isPre = $preOrPost == 'pre';
             $jobId = $jobId ? (int) $jobId : null;
             $isClientPost = !$jobId && $isPost ? 1 : 0;
             $isClientPre = !$jobId && $isPre ? 1 : 0;
             $isJobPost = $jobId && $isPost ? 1 : 0;
             $isJobPre = $jobId && $isPre ? 1 : 0;
             $this->addSql("INSERT IGNORE INTO Script (id, description, name, isClientPre, isJobPre, isClientPost, isJobPost) VALUES ({$idScript}, '', '{$name}', {$isClientPre}, {$isJobPre}, {$isClientPost}, {$isJobPost})");
             if ($isClientPost) {
                 $this->addSql("UPDATE Client SET postScript_id = {$idScript} WHERE id = {$clientId}");
             }
             if ($isClientPre) {
                 $this->addSql("UPDATE Client SET preScript_id = {$idScript} WHERE id = {$clientId}");
             }
             if ($isJobPost) {
                 $this->addSql("UPDATE Job SET postScript_id = {$idScript} WHERE id = {$jobId}");
             }
             if ($isJobPre) {
                 $this->addSql("UPDATE Job SET preScript_id = {$idScript} WHERE id = {$jobId}");
             }
             ++$idScript;
             copy(sprintf('%s/%s', Globals::getUploadDir(), $name), sprintf('%s/%04d.script', Globals::getUploadDir(), $idScript));
             chmod(sprintf('%s/%04d.script', Globals::getUploadDir(), $idScript), 0755);
         }
     }
 }
コード例 #3
0
    public function up(Schema $schema)
    {
        // this up() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
        $maxId = 0;
        foreach (scandir(Globals::getUploadDir()) as $script) {
            $matches = array();
            if (preg_match('/^([0-9]{4})[.]script$/', $script, $matches)) {
                $maxId = max($maxId, (int) $matches[1]);
            }
        }
        $nextId = $maxId + 1;
        $description = <<<EOF
Use this script as pre client and post client script (yes, both) if you want to trigger snapshot creation on Windows machines.

In order for this script to work you will have to install the contents of the /usr/share/elkarbackup/extra/windows (this is the default path, might be some other in your system) in the Windows machine.

You will find more information regarding the Windows-side configuration of this feature in the aforementioned directory.
EOF;
        $this->addSql("INSERT INTO Script VALUES (?, ?, 'TriggerSnapshotGenerateOrDelete.sh', 1, 0, 1, 0, NULL)", array($nextId, $description));
        $this->abortIf(!copy("/usr/share/elkarbackup/extra/windows/TriggerSnapshotGenerateOrDelete.sh", Globals::getUploadDir() . "/" . sprintf("%04d.script", $nextId)));
        $this->abortIf(!chmod(Globals::getUploadDir() . "/" . sprintf("%04d.script", $nextId), 0755));
    }
コード例 #4
0
 /**
  * @Route("/clients", name="showClients")
  * @Template()
  */
 public function showClientsAction(Request $request)
 {
     $fsDiskUsage = (int) round($this->getFsUsed(Globals::getBackupDir()) * 100 / $this->getFsSize(Globals::getBackupDir()), 0, PHP_ROUND_HALF_UP);
     $repository = $this->getDoctrine()->getRepository('BinovoElkarBackupBundle:Client');
     $query = $repository->createQueryBuilder('c')->addOrderBy('c.id', 'ASC')->getQuery();
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($query, $request->query->get('page', 1), $request->get('lines', $this->container->getParameter('pagination_lines_per_page')));
     foreach ($pagination as $i => $client) {
         $client->setLogEntry($this->getLastLogForLink('%/client/' . $client->getId()));
         foreach ($client->getJobs() as $job) {
             $job->setLogEntry($this->getLastLogForLink('%/client/' . $client->getId() . '/job/' . $job->getId()));
         }
     }
     $this->info('View clients', array(), array('link' => $this->generateUrl('showClients')));
     $this->getDoctrine()->getManager()->flush();
     return $this->render('BinovoElkarBackupBundle:Default:clients.html.twig', array('pagination' => $pagination, 'fsDiskUsage' => $fsDiskUsage));
 }
コード例 #5
0
ファイル: Client.php プロジェクト: adrianles/elkarbackup
 /**
  * Returns the full path of the snapshot directory
  */
 public function getSnapshotRoot()
 {
     return Globals::getSnapshotRoot($this->getId());
 }
コード例 #6
0
 /**
  * @Route("/clients", name="showClients")
  * @Template()
  */
 public function showClientsAction(Request $request)
 {
     $user = $this->get('security.context')->getToken()->getUser();
     $actualuserid = $user->getId();
     $fsDiskUsage = (int) round($this->getFsUsed(Globals::getBackupDir()) * 100 / $this->getFsSize(Globals::getBackupDir()), 0, PHP_ROUND_HALF_UP);
     $repository = $this->getDoctrine()->getRepository('BinovoElkarBackupBundle:Client');
     $query = $repository->createQueryBuilder('c')->addOrderBy('c.id', 'ASC');
     if (!$this->get('security.context')->isGranted('ROLE_ADMIN')) {
         // Limited view for non-admin users
         $query->where('c.owner = ?1');
         //adding users and roles
         $query->setParameter(1, $actualuserid);
     }
     $query->getQuery();
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($query, $request->query->get('page', 1), $request->get('lines', $this->getUserPreference($request, 'linesperpage')));
     foreach ($pagination as $i => $client) {
         $client->setLogEntry($this->getLastLogForLink('%/client/' . $client->getId()));
         foreach ($client->getJobs() as $job) {
             $job->setLogEntry($this->getLastLogForLink('%/client/' . $client->getId() . '/job/' . $job->getId()));
         }
     }
     $this->info('View clients', array(), array('link' => $this->generateUrl('showClients')));
     $this->getDoctrine()->getManager()->flush();
     return $this->render('BinovoElkarBackupBundle:Default:clients.html.twig', array('pagination' => $pagination, 'fsDiskUsage' => $fsDiskUsage));
 }
コード例 #7
0
 public function boot()
 {
     // Set some static globals
     Globals::setBackupDir($this->container->getParameter('backup_dir'));
     Globals::setUploadDir($this->container->getParameter('upload_dir'));
 }
コード例 #8
0
ファイル: Script.php プロジェクト: xezpeleta/elkarbackup
 public function getScriptDirectory()
 {
     return Globals::getUploadDir();
 }