function drush_prepare_backup_dir

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

Prepare a backup directory

Related topics

2 calls to drush_prepare_backup_dir()
drush_pm_download in commands/pm/pm.drush.inc
Command callback. Download Drupal core or any project.
drush_pm_version_control_backup::prepare_backup_dir in commands/pm/version_control/backup.inc

File

includes/drush.inc, line 1960
The drush API implementation and helpers.

Code

function drush_prepare_backup_dir($subdir = NULL) {
  $backup_dir = drush_preflight_backup_dir($subdir);
  $backup_parent = dirname($backup_dir);

  $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
  $drupal_root .= '/';

  if ((!empty($drupal_root)) && (strpos($backup_parent, $drupal_root) === 0)) {
    return drush_set_error('DRUSH_PM_BACKUP_FAILED', dt('It\'s not allowed to store backups inside the Drupal root directory.'));
  }
  if (!file_exists($backup_parent)) {
    if (!drush_mkdir($backup_parent)) {
      return drush_set_error('DRUSH_PM_BACKUP_FAILED', dt('Unable to create backup directory !dir.', array('!dir' => $backup_parent)));
    }
  }
  if (!is_writable($backup_parent)) {
    return drush_set_error('DRUSH_PM_BACKUP_FAILED', dt('Backup directory !dir is not writable.', array('!dir' => $backup_parent)));
  }

  drush_mkdir($backup_dir);
  return $backup_dir;
}