/** * 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; }