Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

drush_sql_dump

Definition

drush_sql_dump($db_url = NULL, $execute = TRUE, $skip = NULL)
contributions/drush/drush_sql/drush_sql.module, line 109

Description

Command callback. Outputs the entire Drupal database in SQL format using mysqldump or pg_dump.

Parameters

db_url

execute

skip A key in the sql_skip array which specifies a list of tables to ignore when migrating.

Code

<?php
function drush_sql_dump($db_url = NULL, $execute = TRUE, $skip = NULL) {
  if (is_null($db_url)) {
    $db_url = $GLOBALS['db_url'];
  }

  switch (_drush_sql_get_scheme($db_url)) {
    case 'mysql':
    case 'mysqli':
      $exec = 'mysqldump' . (DRUSH_VERBOSE ? ' -v' : '');
      $exec .= ' --opt -Q' . _drush_sql_get_credentials($db_url);
      break;
    case 'pgsql':
      drush_die(t('Sorry, pg_dump support not implemented yet.')); // TODO: pg_dump command.
      break;
    default:
      drush_die(_drush_sql_get_invalid_url_msg($db_url));
  }

  // Get any arguments to be passed through to the SQL client program.
  if (func_num_args() > 3 && ($args = func_get_args())) {
    $args = ' ' . implode(' ', array_slice($args, 3)); // skip standard arguments
  }
  
  // Skip large core tables if instructed.  Used by 'sql load' command.
    if ($skip && strpos($exec, '--ignore-table') === FALSE) {
      $all_skip_tables = (array)drush_get_option('skip-tables');
      $skip_tables = $all_skip_tables[$skip];
      $database = _drush_sql_get_database($db_url);
      foreach ($skip_tables as $table) {
        $ignores[] = "--ignore-table=$database.$table";
      }
      $exec .= ' '. implode(' ', $ignores);
    }
  
  if (!$execute) {
    return $exec;
  }
  
  if (DRUSH_VERBOSE) {
    drush_print(t('Executing: !cmd', array('!cmd' => $exec)));
  }

  return drush_op('system', $exec) !== FALSE;
}
?>