-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate2shield.php
352 lines (291 loc) · 12.4 KB
/
migrate2shield.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/acquia_helper.php';
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
$app = new Silly\Application();
$acquia = new AcquiaHelper();
$app->command('getdb [name]', function ($name, OutputInterface $output) use ($acquia) {
if ($name) {
$output->writeln("{$name}\n");
$response = $acquia->getSiteDb($name);
$output->writeln(print_r($response, true));
}
});
$app->command('setenvfromyaml', function (InputInterface $input, OutputInterface $output) use ($acquia) {
$src = $input->getArgument('src');
$dst = $input->getArgument('dst');
$acquia->importEnviromentalVariables($src, $dst);
});
$app->command('exportDB file src dst', function (InputInterface $input, OutputInterface $output) use ($acquia) {
$file = $input->getArgument('file');
$src = $input->getArgument('src');
$dst = $input->getArgument('dst');
// $yell = $input->getOption('source');
// $acquia->setOutput ( $output );
$valid_env = array(
'prod',
'test',
'dev',
'oldprod',
'oldtest',
'olddev'
);
if (! in_array($dst, $valid_env)) {
$output->writeln('destination environment is invalid, please use dev, test, prod');
return false;
}
if (! in_array($src, $valid_env)) {
$output->writeln('Source environment is invalid, please use dev, test, prod');
return false;
}
if (is_file($file) && ($file = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))) {
foreach ($file as $index => $site) {
$site = trim($site);
$acquia->importEnviromentalVariables($src, $dst);
$dbinfo = $acquia->getCurrentDB($site, $src, $dst);
if (! is_object($dbinfo)) {
$output->writeln("Failed to get DB because \$dbinfo is not an object.");
continue;
}
$dbvalues['ACQUIA_DB'] = $dbinfo->name;
$dbvalues['SRC_DB_SETTING_NAME'] = $dbinfo->name;
$dbvalues['SRC_DB_USER'] = $dbinfo->username;
$dbvalues['SRC_DB_HOST'] = $dbinfo->host;
$dbvalues['SRC_DB_NAME'] = $dbinfo->instance_name;
$dbvalues['SRC_DB_PASS'] = $dbinfo->password;
$dbvalues['MIGRATION_SITE_NAME'] = $site;
$acquia->setEnvironmentals($dbvalues);
$acquia->executeShellScript('./bashes/source_db.sh');
}
// should then move the export_progress.csv file to the destination server using shell.
} else {
$output->writeln('Invalid source file.');
return false;
}
})
->descriptions('Will export the Database for each site given and copy them to the destination server. ', array(
// $site, $acquia_db, $dbname, $db_import_file
'file' => 'File containing each site to export on one line.',
'src' => 'Source server as defined in YAML',
'dst' => 'Destination server as defined in YAML'
));
/**
* This script should run all the exports for the given source and destination
* based on the sites file given.
* The sites file should be single column
* delimited list, with each site we plan to move matching its site folder
* in the /docroot/sites/* directory.
* Tasks:
* 1) Create the database for the current site in the export file
* 2) import the databases from the exported DB file, the file created from export should
* include the site name, the exported database name and other information.
* 2) run the rync for each site /docroot/sites/site.ucsf.edu/files/ directory
* 3) setup the domain through the Acquia API
*/
$app->command('dbImport file src dst', function (InputInterface $input, OutputInterface $output) use ($acquia) {
// $acquia->setOutput ( $output );
$file = $input->getArgument('file');
$src = $input->getArgument('src');
$dst = $input->getArgument('dst');
// $yell = $input->getOption('source');
// drupal.ucsf.edu|ucsf_drupal|ucsfpdevdb8948|ucsfpdevdb8948.2016-02-17-1455672135.sql.gz
$env_set = false;
$valid_env = array(
'prod',
'test',
'dev',
'oldprod',
'oldtest',
'olddev'
);
if (! in_array($dst, $valid_env)) {
$output->writeln('destination environment is invalid, please use dev, test, prod');
return false;
}
if (! in_array($src, $valid_env)) {
$output->writeln('Source environment is invalid, please use dev, test, prod');
return false;
}
if (is_file($file) && ($file = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))) {
foreach ($file as $index => $row) {
list ($site, $acquia_db, $dbname, $db_import_file) = explode('|', $row);
$acquia->importEnviromentalVariables($src, $dst, false);
// $acquia->createDatabase($acquia_db, $dst);
putenv("MIGRATION_SITE_NAME={$site}");
putenv("SRC_DB_SETTING_NAME={$acquia_db}");
putenv("ACQUIA_DB={$acquia_db}");
putenv("RAW_DB_NAME={$dbname}");
putenv("RAW_DB_FILE={$db_import_file}");
$acquia->executeShellScript('bashes/import_db.sh');
}
} else {
$output->writeln('Invalid source file.');
return false;
}
})
->descriptions('Import each database into Acquia', array(
// $site, $acquia_db, $dbname, $db_import_file
'file' => 'Pipe delimited file which includes the Site name, Acquia DB name, Real DB Name and DB Source file (MySQL dump file).',
'src' => 'Source server as defined in YAML',
'dst' => 'Destination server as defined in YAML'
));
// , then Rync the files directories for files and files-private of each site.
$app->command('fileImport file src dst', function (InputInterface $input, OutputInterface $output) use ($acquia) {
// $acquia->setOutput ( $output );
$env_set = false;
$file = $input->getArgument('file');
$src = $input->getArgument('src');
$dst = $input->getArgument('dst');
$valid_env = array(
'prod',
'test',
'dev',
'oldprod',
'oldtest',
'olddev'
);
if (! in_array($dst, $valid_env)) {
$output->writeln('destination environment is invalid, please use dev, test, prod');
return false;
}
if (! in_array($src, $valid_env)) {
$output->writeln('Source environment is invalid, please use dev, test, prod');
return false;
}
if (is_file($file) && ($file = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))) {
foreach ($file as $index => $row) {
list ($site, $acquia_db, $dbname, $db_import_file) = explode('|', $row);
// we determine the site directory here, so we can't have www. or preview. or test.
$site = trim($site);
$needle = array(
'preview.',
'test.',
'www.'
);
$site = str_replace($needle, '', filter_var($site, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE));
$acquia->importEnviromentalVariables($src, $dst, false);
putenv("MIGRATION_SITE_NAME={$site}");
putenv("SRC_DB_SETTING_NAME={$acquia_db}");
putenv("ACQUIA_DB={$acquia_db}");
putenv("RAW_DB_NAME={$dbname}");
putenv("RAW_DB_FILE={$db_import_file}");
$acquia->executeShellScript('bashes/copy_resources.sh');
// $acquia->executeShellScript('bashes/copy_resources.sh', $output);
}
} else {
$output->writeln('Invalid source file.');
return false;
}
})
->descriptions('Import the files and file-private into the source website.');
$app->command('makeDatabases file src dst', function (InputInterface $input, OutputInterface $output) use ($acquia) {
// $acquia->setOutput ( $output );
$file = $input->getArgument('file');
$src = $input->getArgument('src');
$dst = $input->getArgument('dst');
$acquia->importEnviromentalVariables($src, $dst, false);
if (is_file($file) && ($file = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))) {
foreach ($file as $index => $row) {
list ($site, $acquia_db, $dbname, $db_import_file) = explode('|', $row);
$output->writeln('Creating database for: ' . $site . ' ACQUIA_DB: ' . $acquia_db);
$output->writeln("\n");
$response = $acquia->createDatabase($acquia_db, $dst);
if (isset($response->description)) {
$output->writeln($response->description);
}
}
}
});
$app->command('moveDomain [--delete] [--shield] [--preview] [--delay] file src dst', function (InputInterface $input, OutputInterface $output) use ($acquia) {
// $acquia->setOutput ( $output );
$file = $input->getArgument('file');
$src = $input->getArgument('src');
$dst = $input->getArgument('dst');
$delete = $input->getOption('delete');
$shield = $input->getOption('shield');
$preview = $input->getOption('preview');
$delay = $input->getOption('delay');
// drupal.ucsf.edu|ucsf_drupal|ucsfpdevdb8948|ucsfpdevdb8948.2016-02-17-1455672135.sql.gz
$valid_env = array(
'prod',
'test',
'dev',
'oldprod',
'oldtest',
'olddev'
);
if (!in_array($dst, $valid_env)) {
$output->writeln('destination environment is invalid, please use dev, test, prod');
return false;
}
if (!in_array($src, $valid_env)) {
$output->writeln('Source environment is invalid, please use dev, test, prod');
return false;
}
$acquia->importEnviromentalVariables($src, $dst, false);
$cloudAPIIterator = 0;
if (is_file($file) && ($file = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))) {
foreach ($file as $index => $row) {
list ($site) = explode('|', $row);
if ($shield || $preview) {
$prefix = ($shield) ? 'shield.' : 'preview.';
$site = $prefix . $site;
} else {
if ($dst == 'test') {
$site = 'test.' . $site;
}
if ($dst == 'dev') {
$site = 'dev.' . $site;
}
}
// I think we only need to change one environmental value, but not 100% sure yet.
putenv("MIGRATION_SITE_NAME={$site}");
$acquia->yaml['MIGRATION_SITE_NAME'] = $site;
// remove the old server instance
$result = $acquia->setDomain($site, $acquia->yaml['SRC_ENV'], $acquia->yaml['ACQUIA_SITEGROUP'], true);
if ($result) {
$output->writeln(print_r($result, true));
}
$result = false;
// add domain to new Destination Acquia Server
$result = $acquia->setDomain($site, $acquia->yaml['DST_ENV'], $acquia->yaml['ACQUIA_SITEGROUP_DST'], $delete);
if ($result) {
$output->writeln(print_r($result, true));
if (!$result->message == 'Resource not found') {
$cloudAPIIterator++;
}
}
//Acquia API has some major performance issues, too many consecutive requests and you start getting failures
if ($delay) {
if (($cloudAPIIterator % 10) == 0 && $cloudAPIIterator>0) {
sleep(600);
} else {
sleep(15);
}
}
}
} else {
$output->writeln('Invalid source file.');
return false;
}
})
->descriptions('Import each database into Acquia', array(
// $site, $acquia_db, $dbname, $db_import_file
'file' => 'Pipe delimited file which includes the Site name, Acquia DB name, Real DB Name and DB Source file (MySQL dump file).',
'src' => 'Source server as defined in YAML',
'dst' => 'Destination server as defined in YAML'
));
/**
* This was to confirm the streaming of the bash output was working via PHP.
* If working the pings should be displayed one at a time just like if you
* were working on the command line.
*/
$app->command('pingtest', function (InputInterface $input, OutputInterface $output) use ($acquia) {
// $acquia->setOutput ( $output );
// $argument = $input->getArgument('name');
// $option = $input->getOption('source');
$acquia->runScriptRealtime('ping -c 10 127.0.0.1');
})
->descriptions('Test realtime updating of the PHP to BASH shell.');
$app->run();