/** * Create new mysqldump command * * @param null|string $database Database name * * @return RemoteCommandBuilder */ protected function createLocalMySqlDumpCommand($database = null) { $command = new RemoteCommandBuilder('mysqldump'); // Add username if (DatabaseConnection::getDbUsername()) { $command->addArgumentTemplate('-u%s', DatabaseConnection::getDbUsername()); } // Add password if (DatabaseConnection::getDbPassword()) { $command->addArgumentTemplate('-p%s', DatabaseConnection::getDbPassword()); } // Add hostname if (DatabaseConnection::getDbHostname()) { $command->addArgumentTemplate('-h%s', DatabaseConnection::getDbHostname()); } // Add hostname if (DatabaseConnection::getDbPort()) { $command->addArgumentTemplate('-P%s', DatabaseConnection::getDbPort()); } // Add custom options if ($this->contextConfig->exists('mysql.mysqldump.option')) { $command->addArgumentRaw($this->contextConfig->get('mysql.mysqldump.option')); } if ($database !== null) { $command->addArgument($database); } // Transfer compression switch ($this->contextConfig->get('mysql.compression')) { case 'bzip2': // Add pipe compressor (bzip2 compressed transfer via ssh) $command->addPipeCommand(new CommandBuilder('bzip2', '--compress --stdout')); break; case 'gzip': // Add pipe compressor (gzip compressed transfer via ssh) $command->addPipeCommand(new CommandBuilder('gzip', '--stdout')); break; } return $command; }