@@ -0,0 +1,5 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <buildpath> | |||
|
3 | <buildpathentry kind="src" path=""/> | |||
|
4 | <buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/> | |||
|
5 | </buildpath> |
@@ -0,0 +1,28 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <projectDescription> | |||
|
3 | <name>markei-dbmigrate</name> | |||
|
4 | <comment></comment> | |||
|
5 | <projects> | |||
|
6 | </projects> | |||
|
7 | <buildSpec> | |||
|
8 | <buildCommand> | |||
|
9 | <name>org.eclipse.wst.common.project.facet.core.builder</name> | |||
|
10 | <arguments> | |||
|
11 | </arguments> | |||
|
12 | </buildCommand> | |||
|
13 | <buildCommand> | |||
|
14 | <name>org.eclipse.wst.validation.validationbuilder</name> | |||
|
15 | <arguments> | |||
|
16 | </arguments> | |||
|
17 | </buildCommand> | |||
|
18 | <buildCommand> | |||
|
19 | <name>org.eclipse.dltk.core.scriptbuilder</name> | |||
|
20 | <arguments> | |||
|
21 | </arguments> | |||
|
22 | </buildCommand> | |||
|
23 | </buildSpec> | |||
|
24 | <natures> | |||
|
25 | <nature>org.eclipse.php.core.PHPNature</nature> | |||
|
26 | <nature>org.eclipse.wst.common.project.facet.core.nature</nature> | |||
|
27 | </natures> | |||
|
28 | </projectDescription> |
@@ -0,0 +1,7 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <faceted-project> | |||
|
3 | <fixed facet="php.component"/> | |||
|
4 | <fixed facet="php.core.component"/> | |||
|
5 | <installed facet="php.core.component" version="1"/> | |||
|
6 | <installed facet="php.component" version="5.4"/> | |||
|
7 | </faceted-project> |
@@ -0,0 +1,22 | |||||
|
1 | Copyright (c) 2014 Markei.nl | |||
|
2 | ||||
|
3 | Permission is hereby granted, free of charge, to any person | |||
|
4 | obtaining a copy of this software and associated documentation | |||
|
5 | files (the "Software"), to deal in the Software without | |||
|
6 | restriction, including without limitation the rights to use, | |||
|
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
|
8 | copies of the Software, and to permit persons to whom the | |||
|
9 | Software is furnished to do so, subject to the following | |||
|
10 | conditions: | |||
|
11 | ||||
|
12 | The above copyright notice and this permission notice shall be | |||
|
13 | included in all copies or substantial portions of the Software. | |||
|
14 | ||||
|
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
|
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |||
|
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
|
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |||
|
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
|
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
|
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |||
|
22 | OTHER DEALINGS IN THE SOFTWARE. No newline at end of file |
@@ -0,0 +1,69 | |||||
|
1 | <?php | |||
|
2 | ||||
|
3 | $base_dir = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); | |||
|
4 | $config_file = $base_dir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'dbmigrate' . DIRECTORY_SEPARATOR . 'env.ini'; | |||
|
5 | ||||
|
6 | $config = parse_ini_file($config_file, true); | |||
|
7 | $envs = array(); | |||
|
8 | foreach ($config as $name => $section) | |||
|
9 | { | |||
|
10 | if (substr($name, 0, strlen('env_')) === 'env_') | |||
|
11 | { | |||
|
12 | $envs[substr($name, strlen('env_'))] = $section; | |||
|
13 | } | |||
|
14 | } | |||
|
15 | ||||
|
16 | echo 'Available environments:' . PHP_EOL; | |||
|
17 | foreach ($envs as $name => $env_config) | |||
|
18 | echo '* ' . $name . PHP_EOL; | |||
|
19 | echo PHP_EOL; | |||
|
20 | ||||
|
21 | echo 'Select the source env:' . PHP_EOL; | |||
|
22 | $source = trim(fgets(STDIN)); | |||
|
23 | echo PHP_EOL; | |||
|
24 | ||||
|
25 | echo 'Select the destination env:' . PHP_EOL; | |||
|
26 | $dest = trim(fgets(STDIN)); | |||
|
27 | echo PHP_EOL; | |||
|
28 | ||||
|
29 | echo 'Please make sure: You want to export the ' . $source . ' database to ' . $dest . '? Y|N' . PHP_EOL; | |||
|
30 | $confirm = strtolower(trim(fgets(STDIN))); | |||
|
31 | echo PHP_EOL; | |||
|
32 | if (in_array($confirm, array('y', 'yes', 'j', 'ja', 'ok')) === false) | |||
|
33 | exit('Okay, exit!'); | |||
|
34 | ||||
|
35 | if (file_exists($base_dir . DIRECTORY_SEPARATOR . 'backup') === false) | |||
|
36 | mkdir($base_dir . DIRECTORY_SEPARATOR . 'backup'); | |||
|
37 | ||||
|
38 | echo 'Dump source database:' . PHP_EOL; | |||
|
39 | $source_dump = $file = $base_dir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'dbbackup_' . $source . '_' . date('YmdHis') . '.sql'; | |||
|
40 | $command = 'mysqldump --add-drop-table --comments --host=' . $envs[$source]['host'] . ' --no-create-db --password=' . $envs[$source]['password'] . ' --port=' . $envs[$source]['port'] . ' --result-file=' . $file . ' --default-character-set=utf8 --user=' . $envs[$source]['user'] . ' ' . $envs[$source]['name']; | |||
|
41 | echo ' target file: ' . $file . PHP_EOL; | |||
|
42 | echo ' command: ' . $command . PHP_EOL; | |||
|
43 | system($command); | |||
|
44 | echo PHP_EOL . 'Complete' . PHP_EOL . PHP_EOL; | |||
|
45 | ||||
|
46 | echo 'Dump source database:' . PHP_EOL; | |||
|
47 | $dest_dump = $file = $base_dir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'dbbackup_' . $dest . '_' . date('YmdHis') . '.sql'; | |||
|
48 | $command = 'mysqldump --add-drop-table --comments --host=' . $envs[$dest]['host'] . ' --no-create-db --password=' . $envs[$dest]['password'] . ' --port=' . $envs[$dest]['port'] . ' --result-file=' . $file . ' --default-character-set=utf8 --user=' . $envs[$dest]['user'] . ' ' . $envs[$dest]['name']; | |||
|
49 | echo ' target file: ' . $file . PHP_EOL; | |||
|
50 | echo ' command: ' . $command . PHP_EOL; | |||
|
51 | system($command); | |||
|
52 | echo PHP_EOL . 'Complete' . PHP_EOL . PHP_EOL; | |||
|
53 | ||||
|
54 | echo 'Load data on destination database:' . PHP_EOL; | |||
|
55 | $command = 'mysql --host=' . $envs[$dest]['host'] . ' --password=' . $envs[$dest]['password'] . ' --port=' . $envs[$dest]['port'] . ' --default-character-set=utf8 --user=' . $envs[$dest]['user'] . ' --database=' . $envs[$dest]['name'] . ' < ' . $source_dump; | |||
|
56 | echo ' load sql: ' . $source_dump . PHP_EOL; | |||
|
57 | echo ' command: ' . $command . PHP_EOL; | |||
|
58 | system($command); | |||
|
59 | echo PHP_EOL . 'Complete' . PHP_EOL . PHP_EOL; | |||
|
60 | ||||
|
61 | echo 'Replace domain information in database:' . PHP_EOL; | |||
|
62 | $command = 'php vendor\dvdgiessen\dbsr\index.php --host ' . $envs[$dest]['host'] . ' --user ' . $envs[$dest]['user'] . ' --password ' . $envs[$dest]['password'] . ' --database ' . $envs[$dest]['name'] . ' --charset utf8 -- ' . $envs[$source]['domain'] . ' ' . $envs[$dest]['domain']; | |||
|
63 | echo ' search for: ' . $envs[$source]['domain'] . PHP_EOL; | |||
|
64 | echo ' replace with: ' . $envs[$dest]['domain'] . PHP_EOL; | |||
|
65 | echo ' command: ' . $command . PHP_EOL; | |||
|
66 | system($command); | |||
|
67 | echo PHP_EOL . 'Complete' . PHP_EOL . PHP_EOL; | |||
|
68 | ||||
|
69 | echo PHP_EOL . 'Done!' . PHP_EOL . PHP_EOL; No newline at end of file |
@@ -0,0 +1,14 | |||||
|
1 | { | |||
|
2 | "name": "markei/dbmigrate", | |||
|
3 | "version": "1", | |||
|
4 | "description": "Script for migrating databases between environments, easy for use in a situation of Wordpress and DTAP", | |||
|
5 | "license": "MIT", | |||
|
6 | "authors": [ | |||
|
7 | { | |||
|
8 | "name": "Maarten de Keizer", | |||
|
9 | "email": "m.de.keizer@markei.nl", | |||
|
10 | "role": "Lead Developer" | |||
|
11 | } | |||
|
12 | ], | |||
|
13 | "bin": ["bin/dbmigratie.php"] | |||
|
14 | } |
General Comments 0
You need to be logged in to leave comments.
Login now