Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?php namespace App\Backups;
  2.  
  3. use BackupManager\Databases\Database;
  4.  
  5. /**
  6. * Class MysqlDatabase
  7. * @package BackupManager\Databases
  8. */
  9. class MysqlDatabase implements Database {
  10.  
  11. /** @var array */
  12. private $config;
  13.  
  14. /**
  15. * @param $type
  16. * @return bool
  17. */
  18. public function handles($type) {
  19. return strtolower($type) == 'mysql';
  20. }
  21.  
  22. /**
  23. * @param array $config
  24. * @return null
  25. */
  26. public function setConfig(array $config) {
  27. $this->config = $config;
  28. }
  29.  
  30. /**
  31. * @param $outputPath
  32. * @return string
  33. */
  34. public function getDumpCommandLine($outputPath) {
  35.  
  36. $database = $this->config['database'];
  37.  
  38. /**
  39. * Note, this was hastily written and can certainly be improved upon.
  40. */
  41. $tables = '';
  42. if(isset($this->config['include_tables'])) {
  43. $tables = implode(' ', $this->config['include_tables']);
  44. $tables = str_replace("'", "", escapeshellarg($tables));
  45. } elseif(isset($this->config['exclude_tables'])) {
  46. $tables = implode(' ', array_map(function($table) use ($database) { return "--ignore-table=$database.". $table; }, $this->config['exclude_tables']));
  47. $tables = str_replace("'", "", escapeshellarg($tables));
  48. }
  49.  
  50. $command = sprintf('mysqldump --routines --host=%s --port=%s --user=%s --password=%s %s %s > %s',
  51. escapeshellarg($this->config['host']),
  52. escapeshellarg($this->config['port']),
  53. escapeshellarg($this->config['user']),
  54. escapeshellarg($this->config['pass']),
  55. escapeshellarg($database),
  56. $tables,
  57. escapeshellarg($outputPath)
  58. );
  59.  
  60. return $command;
  61. }
  62.  
  63. /**
  64. * @param $inputPath
  65. * @return string
  66. */
  67. public function getRestoreCommandLine($inputPath) {
  68. return sprintf('mysql --host=%s --port=%s --user=%s --password=%s %s -e "source %s"',
  69. escapeshellarg($this->config['host']),
  70. escapeshellarg($this->config['port']),
  71. escapeshellarg($this->config['user']),
  72. escapeshellarg($this->config['pass']),
  73. escapeshellarg($this->config['database']),
  74. $inputPath
  75. );
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement