Exemple #1
0
 /**
  * Add mysqldump filter to command
  *
  * @param CommandBuilderInterface $commandDump  Command
  * @param string                  $database     Database
  * @param boolean                 $isRemote     Remote filter
  *
  * @return CommandBuilderInterface
  */
 protected function addMysqlDumpFilterArguments(CommandBuilderInterface $commandDump, $database, $isRemote = true)
 {
     $command = $commandDump;
     $filter = $this->contextConfig->get('mysql.filter');
     // get filter
     if (is_array($filter)) {
         $filterList = (array) $filter;
         $filter = 'custom table filter';
     } else {
         $filterList = $this->getApplication()->getConfigValue('mysql-backup-filter', $filter);
     }
     if (empty($filterList)) {
         throw new \RuntimeException('MySQL dump filters "' . $filter . '" not available"');
     }
     $this->output->writeln('<p>Using filter "' . $filter . '"</p>');
     // Get table list (from cloned mysqldump command)
     if ($isRemote) {
         $tableListDumper = $this->createRemoteMySqlCommand($database);
     } else {
         $tableListDumper = $this->createLocalMySqlCommand($database);
     }
     $tableListDumper->addArgumentTemplate('-e %s', 'show tables;');
     // wrap with ssh (for remote execution)
     if ($isRemote) {
         $tableListDumper = $this->wrapRemoteCommand($tableListDumper);
     }
     $tableList = $tableListDumper->execute()->getOutput();
     // Filter table list
     $ignoredTableList = FilterUtility::mysqlIgnoredTableFilter($tableList, $filterList, $database);
     // Dump only structure
     $commandStructure = clone $command;
     $commandStructure->addArgument('--no-data')->clearPipes();
     // Dump only data (only filtered tables)
     $commandData = clone $command;
     $commandData->addArgument('--no-create-info')->clearPipes();
     if (!empty($ignoredTableList)) {
         $commandData->addArgumentTemplateMultiple('--ignore-table=%s', $ignoredTableList);
     }
     $commandPipeList = $command->getPipeList();
     // Combine both commands to one
     $command = new OutputCombineCommandBuilder();
     $command->addCommandForCombinedOutput($commandStructure)->addCommandForCombinedOutput($commandData);
     // Read compression pipe
     if (!empty($commandPipeList)) {
         $command->setPipeList($commandPipeList);
     }
     return $command;
 }
Exemple #2
0
 /**
  * Sync database
  */
 protected function runTaskMysql()
 {
     // ##################
     // Sync databases
     // ##################
     foreach ($this->contextConfig->getArray('mysql.database') as $database) {
         // make sure we don't have any leading whitespaces
         $database = trim($database);
         // dump database
         $dumpFile = $this->tempDir . '/mysql/' . $database . '.dump';
         // ##########
         // Dump from server
         // ##########
         $this->output->writeln('<p>Dumping database "' . $database . '"</p>');
         $mysqldump = $this->createLocalMySqlDumpCommand($database);
         if ($this->contextConfig->exists('mysql.filter')) {
             $mysqldump = $this->addMysqlDumpFilterArguments($mysqldump, $database, false);
         }
         $command = new OutputCombineCommandBuilder();
         $command->addCommandForCombinedOutput($mysqldump);
         $command->setOutputRedirectToFile($dumpFile)->executeInteractive();
     }
     // ##################
     // Backup mysql dump
     // ##################
     $source = $this->tempDir;
     $target = $this->getRsyncPathFromConfig() . self::PATH_DUMP;
     $command = $this->createRsyncCommand($source, $target);
     $command->executeInteractive();
 }