function drush_sql_dump_file

6.x sql.drush.inc drush_sql_dump_file(&$site_record)
3.x sql.drush.inc drush_sql_dump_file(&$db_spec)
4.x sql.drush.inc drush_sql_dump_file(&$db_spec, $prefix)
5.x sql.drush.inc drush_sql_dump_file(&$site_record)

Determine where to store an sql dump file. This function is called by sql-sync.

Parameters

array $site_record:

Return value

string Full path to the sql-dump file.

1 call to drush_sql_dump_file()
drush_sql_sync in commands/sql/sync.sql.inc

File

commands/sql/sql.drush.inc, line 1154
Drush sql commands

Code

function drush_sql_dump_file(&$site_record) {
  $site_record['dump-is-temp'] = FALSE;
  // If the user has set the --{prefix}-dump option, then
  // use the exact name provided.
  $dump_file = drush_sitealias_get_path_option($site_record, 'dump');
  if (!isset($dump_file)) {
    $databases = sitealias_get_databases_from_record($site_record);
    if (isset($databases)) {
      $db_spec = $databases['default']['default'];
      // Make a base filename pattern to use to name the dump file
      $filename_pattern = $db_spec['database'];
      if (isset($db_spec['remote-host'])) {
        $filename_pattern = $db_spec['remote-host'] . '_' . $filename_pattern;
      }
    }
    // If the user has set the --dump-dir option, then
    // store persistant sql dump files there.
    $dump_dir = drush_sitealias_get_path_option($site_record, 'dump-dir');
    $use_temp_file = drush_sitealias_get_path_option($site_record, 'temp') || !$dump_dir;
    $remote = isset($site_record['remote-host']);
    // If this is a remote site, try to find a writable tmpdir.
    if (!isset($dump_dir) && $remote) {
      // If the alias is remote, we'll add on the 'sql' suffix.
      // As mentioned in drush_tempnam, providing a suffix removes
      // the guarentee of tempnam to return a unique filename;
      // however, when the file is going to be used on a remote
      // system, there is no such guarentee anyway, so we might
      // as well include it.
      $suffix = '.sql';
      $remote_site = $site_record;
      unset($remote_site['root']);
      unset($remote_site['uri']);
      $result = drush_invoke_process($site_record, 'php-eval', array('return drush_find_tmp();'), array(), array('integrate' => FALSE, 'override-simulated' => TRUE));
      // If the call to invoke process does not work for some reason
      // (e.g. drush not installed on the target machine),
      // then we will just presume that the tmp dir is '/tmp'.
      if (!$result || !empty($result['error_status']) || empty($result['object'])) {
        $dump_dir = '/tmp';
      }
      else {
        $dump_dir = $result['object'];
      }
    }
    if ($use_temp_file) {
      $dump_file = drush_tempnam($filename_pattern, $dump_dir, $remote ? '.sql' : '');
      // If $dump_dir does not exist, tempname will use the system
      // directory instead.  That is the behavior we want on the local
      // system, but on remote systems, force the result back to the
      // specified directory.
      if ($remote) {
        $dump_file = $dump_dir . '/' . basename($dump_file);
      }
      $site_record['dump-is-temp'] = TRUE;
    }
    else {
      $dump_file = $dump_dir . '/' . $filename_pattern . '.sql';
    }
  }

  return $dump_file;
}