public function SqlBase::dump

8.0.x SqlBase.php public SqlBase::dump($file = '')
7.x SqlBase.php public SqlBase::dump($file = '')
master SqlBase.php public SqlBase::dump($file = '')

File

lib/Drush/Sql/SqlBase.php, line 59

Namespace

Drush\Sql

Class

SqlBase

Code

public function dump($file = '') {
  $file_suffix = '';
  $table_selection = $this->get_expanded_table_selection();
  $file = $this->dumpFile($file);
  $cmd = $this->dumpCmd($table_selection);
  // Gzip the output from dump command(s) if requested.
  if (drush_get_option('gzip')) {
    $cmd .= ' | gzip -f';
    $file_suffix .= '.gz';
  }
  if ($file) {
    $file .= $file_suffix;
    $cmd .= ' > ' . drush_escapeshellarg($file);
  }

  // Avoid the php memory of the $output array in drush_shell_exec().
  if (!$return = drush_op_system($cmd)) {
    if ($file) {
      drush_log(dt('Database dump saved to !path', array('!path' => $file)), LogLevel::SUCCESS);
      drush_backend_set_result($file);
    }
  }
  else {
    return drush_set_error('DRUSH_SQL_DUMP_FAIL', 'Database dump failed');
  }
}