add clone database task

This commit is contained in:
Daniel Seifert 2024-10-29 11:28:04 +01:00
parent 3ad03731ed
commit 5b4a66a5f0
2 changed files with 30 additions and 3 deletions

View File

@ -35,7 +35,7 @@ task('shop:setShopsOffline', function() {
$query = "UPDATE oxshops SET oxactive = '0', OXREGISTERSUBJECT = CONCAT('..', OXREGISTERSUBJECT) WHERE oxactive = '1';"; $query = "UPDATE oxshops SET oxactive = '0', OXREGISTERSUBJECT = CONCAT('..', OXREGISTERSUBJECT) WHERE oxactive = '1';";
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"'); run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"');
} else { } else {
info('missing config, task skipped'); warning('missing config, task skipped');
} }
}); });
@ -61,7 +61,7 @@ task('shop:setShopsOnline', function() {
$query = "UPDATE oxshops SET oxactive = '1', OXREGISTERSUBJECT = SUBSTR(OXREGISTERSUBJECT, 3) WHERE oxactive = '0' AND OXREGISTERSUBJECT LIKE '..%';"; $query = "UPDATE oxshops SET oxactive = '1', OXREGISTERSUBJECT = SUBSTR(OXREGISTERSUBJECT, 3) WHERE oxactive = '0' AND OXREGISTERSUBJECT LIKE '..%';";
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"'); run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"');
} else { } else {
info('missing config, task skipped'); warning('missing config, task skipped');
} }
}); });
@ -95,7 +95,7 @@ task('setup:createDbConfig', function () {
} }
}); });
desc('show OXID shop version'); desc('show version of current OXID installation');
task('shop:getVersion', function () { task('shop:getVersion', function () {
if (test("[ -f {{current_path}}/composer.lock ]")) { if (test("[ -f {{current_path}}/composer.lock ]")) {
cd('{{current_path}}'); cd('{{current_path}}');
@ -106,3 +106,29 @@ task('shop:getVersion', function () {
); );
} }
}); });
desc('dump contents from source to destination database');
task('shop:cloneDatabase', function () {
if (has('bin/mysql') && strlen(get('bin/mysql')) &&
has('bin/mysqldump') && strlen(get('bin/mysqldump')) &&
has('db_name') && strlen(get('db_name')) &&
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
) {
info('Note: Use a dedicated read only user for accessing the source database.');
info('Using the following source database:');
$source_host = ask('source database host', 'localhost');
$source_port = ask('source database port', '3306');
$source_name = ask('source database name');
$source_user = ask('source database user');
$source_pass = askHiddenResponse('source database password');
if (askConfirmation('Do you really want to clone from "'.$source_name.'" to "{{db_name}}"? The target database "{{db_name}}" will be overwritten!')) {
info('cloning database');
$auth = "-h".$source_host." -P".$source_port." -u".$source_user." -p'".$source_pass."'";
run("{{bin/mysqldump}} ".$auth." --opt --no-create-db -f ".$source_name." $({{bin/mysql}} ".$auth." -ANe\"SET group_concat_max_len = 10485760; SELECT GROUP_CONCAT(table_name SEPARATOR ' ') FROM information_schema.tables WHERE table_schema='".$source_name."' AND engine IS NOT NULL;\") | {{bin/mysql}} --defaults-extra-file={{db_conf_path}} -f {{db_name}}");
} else {
info('abborted');
}
} else {
warning('missing config, task skipped');
}
});

View File

@ -4,6 +4,7 @@ config:
repository: gitfhfac@git.d3data.de:Customers/my.shop.com.git repository: gitfhfac@git.d3data.de:Customers/my.shop.com.git
bin/php: /usr/local/php8.2/bin/php bin/php: /usr/local/php8.2/bin/php
bin/mysql: /usr/local/mysql/bin/mysql bin/mysql: /usr/local/mysql/bin/mysql
bin/mysqldump: /usr/local/mysql/bin/mysqldump
# bin/composer: /usr/local/php8.1/bin/php /home/phfhcwoc/bin/composer.phar # optional for custom composer version # bin/composer: /usr/local/php8.1/bin/php /home/phfhcwoc/bin/composer.phar # optional for custom composer version
.base: &base .base: &base