-
Notifications
You must be signed in to change notification settings - Fork 2
/
downsync.drush.inc
52 lines (45 loc) · 1.5 KB
/
downsync.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @file
* Downsync command for Drush
*/
/**
* Implements hook_drush_command().
*/
function downsync_drush_command() {
$items = array();
$items['downsync'] = array(
'description' => "Sync one environment's db and files to another.",
'arguments' => array(
'source-alias' => 'Alias of the source site to copy from.',
'destination-alias' => 'Alias of the destination site to copy to.',
),
'examples' => array(
'drush downsync @prod @local' => 'sql-sync the database and rsync the files from @prod to @local',
),
'aliases' => array('dsync'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'drush dependencies' => array('sql', 'core'),
);
return $items;
}
/**
* Actual function run by the downsync command.
*/
function drush_downsync($source = NULL, $destination = NULL) {
// Make sure we have the source-dump and target-dump options.
$source_dump = drush_get_option('source-dump');
if (!isset($source_dump)) {
drush_set_option('source-dump', '/tmp/dump.sql');
}
$target_dump = drush_get_option('target-dump');
if (!isset($target_dump)) {
drush_set_option('target-dump', '/tmp/dump.sql');
}
// Execute a drush sql-sync
print dt('SQL Sync running... NOTE: if you do not have ssh passwordless logins setup, you may be asked for your password multiple times.');
drush_invoke('sql-sync', $source, $destination);
// Rsync the files.
print dt('Rsync-ing files...');
drush_invoke('rsync', $source .':%files', $destination .':%files');
}