public function Sqlmysql::dumpCmd

8.0.x Sqlmysql.php public Sqlmysql::dumpCmd($table_selection)
7.x Sqlmysql.php public Sqlmysql::dumpCmd($table_selection)
master Sqlmysql.php public Sqlmysql::dumpCmd($table_selection)

Overrides SqlBase::dumpCmd

File

lib/Drush/Sql/Sqlmysql.php, line 90

Namespace

Drush\Sql

Class

Sqlmysql

Code

public function dumpCmd($table_selection) {
  $parens = FALSE;
  $skip_tables = $table_selection['skip'];
  $structure_tables = $table_selection['structure'];
  $tables = $table_selection['tables'];

  $ignores = array();
  $skip_tables = array_merge($structure_tables, $skip_tables);
  $data_only = drush_get_option('data-only');
  // The ordered-dump option is only supported by MySQL for now.
  // @todo add documention once a hook for drush_get_option_help() is available.
  // @see drush_get_option_help() in drush.inc
  $ordered_dump = drush_get_option('ordered-dump');

  $exec = 'mysqldump ';
  // mysqldump wants 'databasename' instead of 'database=databasename' for no good reason.
  $only_db_name = str_replace('--database=', ' ', $this->creds());
  $exec .= $only_db_name;

  // We had --skip-add-locks here for a while to help people with insufficient permissions,
  // but removed it because it slows down the import a lot.  See http://drupal.org/node/1283978
  $extra = ' --no-autocommit --single-transaction --opt -Q';
  if (isset($data_only)) {
    $extra .= ' --no-create-info';
  }
  if (isset($ordered_dump)) {
    $extra .= ' --skip-extended-insert --order-by-primary';
  }
  $exec .= $extra;

  if (!empty($tables)) {
    $exec .= ' ' . implode(' ', $tables);
  }
  else {
    // Append the ignore-table options.
    foreach ($skip_tables as $table) {
      $ignores[] = '--ignore-table=' . $this->db_spec['database'] . '.' . $table;
      $parens = TRUE;
    }
    $exec .= ' ' . implode(' ', $ignores);

    // Run mysqldump again and append output if we need some structure only tables.
    if (!empty($structure_tables)) {
      $exec .= " && mysqldump " . $only_db_name . " --no-data $extra " . implode(' ', $structure_tables);
      $parens = TRUE;
    }
  }
  return $parens ? "($exec)" : $exec;
}