function drush_preflight_backup_dir

8.0.x filesystem.inc drush_preflight_backup_dir($subdir = NULL)
6.x filesystem.inc drush_preflight_backup_dir($subdir = NULL)
7.x filesystem.inc drush_preflight_backup_dir($subdir = NULL)
4.x drush.inc drush_preflight_backup_dir($subdir = NULL)
5.x filesystem.inc drush_preflight_backup_dir($subdir = NULL)
master filesystem.inc drush_preflight_backup_dir($subdir = NULL)

Decide where our backup directory should go

Parameters

string $subdir: The name of the desired subdirectory(s) under drush-backups. Usually a database name.

Related topics

1 call to drush_preflight_backup_dir()
drush_prepare_backup_dir in includes/filesystem.inc
Prepare a backup directory

File

includes/filesystem.inc, line 569
Filesystem utilities.

Code

function drush_preflight_backup_dir($subdir = NULL) {
  $backup_dir = drush_get_context('DRUSH_BACKUP_DIR', drush_get_option('backup-location'));

  if (empty($backup_dir)) {

    // Try to use db name as subdir if none was provided.
    if (empty($subdir)) {
      $subdir = 'unknown';
      if ($sql = drush_sql_get_class()) {
        $db_spec = $sql->db_spec();
        $subdir = $db_spec['database'];
      }
    }

    // Save the date to be used in the backup directory's path name.
    $date = gmdate('YmdHis', $_SERVER['REQUEST_TIME']);

    $backup_dir = drush_get_option('backup-dir', drush_server_home() . '/' . 'drush-backups');
    $backup_dir = drush_trim_path($backup_dir) . '/' . $subdir . '/' . $date;
    drush_set_context('DRUSH_BACKUP_DIR', $backup_dir);
  }
  return $backup_dir;
}