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

1 call to drush_prepare_backup_dir()

File

includes/filesystem.inc, line 596
Filesystem utilities.

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, TRUE)) {
      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)));
  }

  if (!drush_mkdir($backup_dir, TRUE)) {
    return FALSE;
  }
  return $backup_dir;
}