Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php namespace App\Backups;
- use BackupManager\Databases\Database;
- /**
- * Class MysqlDatabase
- * @package BackupManager\Databases
- */
- class MysqlDatabase implements Database {
- /** @var array */
- private $config;
- /**
- * @param $type
- * @return bool
- */
- public function handles($type) {
- return strtolower($type) == 'mysql';
- }
- /**
- * @param array $config
- * @return null
- */
- public function setConfig(array $config) {
- $this->config = $config;
- }
- /**
- * @param $outputPath
- * @return string
- */
- public function getDumpCommandLine($outputPath) {
- $database = $this->config['database'];
- /**
- * Note, this was hastily written and can certainly be improved upon.
- */
- $tables = '';
- if(isset($this->config['include_tables'])) {
- $tables = implode(' ', $this->config['include_tables']);
- $tables = str_replace("'", "", escapeshellarg($tables));
- } elseif(isset($this->config['exclude_tables'])) {
- $tables = implode(' ', array_map(function($table) use ($database) { return "--ignore-table=$database.". $table; }, $this->config['exclude_tables']));
- $tables = str_replace("'", "", escapeshellarg($tables));
- }
- $command = sprintf('mysqldump --routines --host=%s --port=%s --user=%s --password=%s %s %s > %s',
- escapeshellarg($this->config['host']),
- escapeshellarg($this->config['port']),
- escapeshellarg($this->config['user']),
- escapeshellarg($this->config['pass']),
- escapeshellarg($database),
- $tables,
- escapeshellarg($outputPath)
- );
- return $command;
- }
- /**
- * @param $inputPath
- * @return string
- */
- public function getRestoreCommandLine($inputPath) {
- return sprintf('mysql --host=%s --port=%s --user=%s --password=%s %s -e "source %s"',
- escapeshellarg($this->config['host']),
- escapeshellarg($this->config['port']),
- escapeshellarg($this->config['user']),
- escapeshellarg($this->config['pass']),
- escapeshellarg($this->config['database']),
- $inputPath
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement