function drush_core_rsync

8.0.x rsync.core.inc drush_core_rsync($source, $destination, $additional_options = array())
6.x rsync.core.inc drush_core_rsync($source, $destination, $additional_options = array())
7.x rsync.core.inc drush_core_rsync($source, $destination, $additional_options = array())
3.x rsync.core.inc drush_core_rsync($source, $destination, $additional_options = array())
4.x rsync.core.inc drush_core_rsync($source, $destination, $additional_options = array())
5.x rsync.core.inc drush_core_rsync($source, $destination, $additional_options = array())
master rsync.core.inc drush_core_rsync($source, $destination, $additional_options = array())

Entrypoint for drush rsync.

Parameters

source: A site alias ("@dev") or site specification ("/path/to/drupal#mysite.com") followed by an optional path (":path/to/sync"), or any path that could be passed to rsync ("user@server.com:/path/to/dir/").

destination: Same format as source.

additional_options: An array of options that overrides whatever was passed in on the command line (like the 'process' context, but only for the scope of this one call).

File

commands/core/rsync.core.inc, line 17

Code

function drush_core_rsync($source, $destination, $additional_options = array()) {
  // Preflight destination in case it defines aliases used by the source
  _drush_sitealias_preflight_path($destination);
  // After preflight, evaluate file paths
  $source_settings = drush_sitealias_evaluate_path($source, $additional_options);
  $destination_settings = drush_sitealias_evaluate_path($destination, $additional_options);
  $source_path = $source_settings['evaluated-path'];
  $destination_path = $destination_settings['evaluated-path'];

  if (!isset($source_settings)) {
    return drush_set_error('DRUSH_BAD_PATH', dt('Could not evaluate source path !path.', array('!path' => $source)));
  }
  if (!isset($destination_settings)) {
    return drush_set_error('DRUSH_BAD_PATH', dt('Could not evaluate destination path !path.', array('!path' => $destination)));
  }

  // Check to see if this is an rsync multiple command (multiple sources and multiple destinations)
  $is_multiple = drush_do_multiple_command('rsync', $source_settings, $destination_settings, TRUE);

  if ($is_multiple === FALSE) {
    // If the user path is the same for the source and the destination, then
    // always add a slash to the end of the source.  If the user path is not
    // the same in the source and the destinaiton, then you need to know how
    // rsync paths work, and put on the trailing '/' if you want it.
    if ($source_settings['user-path'] == $destination_settings['user-path']) {
      $source_path .= '/';
    }
    // Prompt for confirmation. This is destructive.
    if (!drush_get_context('DRUSH_SIMULATE')) {
      drush_print(dt("You will destroy data from !target and replace with data from !source", array('!source' => $source_path, '!target' => $destination_path)));
      if (!drush_confirm(dt('Do you really want to continue?'))) {
        // was: return drush_set_error('CORE_SYNC_ABORT', 'Aborting.');
        drush_die('Aborting.');
      }
    }

    // Exclude settings is the default only when both the source and
    // the destination are aliases or site names.  Therefore, include
    // settings will be the default whenever either the source or the
    // destination contains a : or a /.
    $include_settings_is_default = (strpos($source . $destination, ':') !== FALSE) || (strpos($source . $destination, '/') !== FALSE);

    // Go ahead and call rsync with the paths we determined
    drush_core_call_rsync($source_path, $destination_path, $additional_options, $include_settings_is_default);
  }
}