Skip to content

Instantly share code, notes, and snippets.

@weitzman
Created October 17, 2014 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weitzman/b5de6ab86ac1ff07e9ae to your computer and use it in GitHub Desktop.
Save weitzman/b5de6ab86ac1ff07e9ae to your computer and use it in GitHub Desktop.
config-rsync - not yet tested
/*
* Command callback.
*/
function drush_config_rsync() {
// Some boring option init stuff.
$backend_options = array('integrate' => TRUE);
$global_options = drush_redispatch_get_options() + array(
'strict' => 0,
);
if (drush_get_context('DRUSH_SIMULATE')) {
$backend_options['backend-simulate'] = TRUE;
}
$alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');
$site_record = drush_sitealias_get_record($alias);
$target_destination_dir = drush_config_destination_dir();
if (drush_sitealias_is_remote_site($alias)) {
// Get a temp dir on Source. The Staging dir might be read-only, esp in Production.
$status_options = array('fields' => 'temp', 'field-labels' => 0);
$return = drush_invoke_process($site_record, 'core-status', array(), $global_options + $status_options, $backend_options);
if ($return['error_status']) {
return drush_set_error('Unable to execute core-status command on the Source.');
}
else {
$dir_export = $return['object']['temp'] . '/staging';
}
//Perform export on the Source
$export_options = array('destination' => $dir_export);
$return = drush_invoke_process($site_record, 'config-export', array(), $global_options + $export_options, $backend_options);
if ($return['error_status']) {
return drush_set_error('Unable to execute config-export command on remote alias.');
}
// Rsync config files to staging dir on Local.
$rsync_options = array('remove-source-files' => TRUE);
$return = drush_invoke_process('@self', 'core-rsync', array("$alias:$dir_export", "@self:$target_destination_dir"), $global_options + $rsync_options, $backend_options);
if ($return['error_status']) {
return drush_set_error('Unable to execute core-rsync command on remote alias.');
}
}
else {
// Two local sites so we skip the rsync.
$export_options = array('destination' => $target_destination_dir);
$return = drush_invoke_process($site_record, 'config-export', array(), $global_options + $export_options, $backend_options);
if ($return['error_status']) {
return drush_set_error('Unable to execute config-export command on remote alias.');
}
}
if (drush_get_option('add')) {
drush_shell_exec_interactive('git add -p %s', $target_destination_dir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment