function drush_core_rsync

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

A command callback.


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

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).


commands/core/, line 27


function drush_core_rsync($source, $destination, $additional_options = array()) {
  // Preflight source in case it defines aliases used by the destination
  // After preflight, evaluate file paths.  We evaluate destination paths first, because
  // there is a first-one-wins policy with --exclude-paths, and we want --target-command-specific
  // to take precedence over --source-command-specific.
  $destination_settings = drush_sitealias_evaluate_path($destination, $additional_options, FALSE, "rsync", 'target-');
  $source_settings = drush_sitealias_evaluate_path($source, $additional_options, FALSE, "rsync", 'source-');
  $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)));

  // 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 destination, 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 delete files in !target and replace with data from !source", array('!source' => $source_path, '!target' => $destination_path)));
    if (!drush_confirm(dt('Do you really want to continue?'))) {
      return drush_user_abort();

  // Next, check to see if both the source and the destination are remote.
  // If so, then we'll process this as an rsync from source to local,
  // followed by an rsync from local to the destination.
  if (drush_sitealias_is_remote_site($source_settings) && drush_sitealias_is_remote_site($destination_settings)) {
    return _drush_core_rsync_both_remote($source, $destination, $additional_options, $source_path);

  // 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);

  $options = _drush_build_rsync_options($additional_options, $include_settings_is_default);

  // Get all of the args and options that appear after the command name.
  $original_args = drush_get_original_cli_args_and_options();
  foreach ($original_args as $original_option) {
    if ($original_option{0} == '-') {
      $options .= ' ' . $original_option;

  // Go ahead and call rsync with the paths we determined
  return drush_core_exec_rsync($source_path, $destination_path, $options);