add backup database task

This commit is contained in:
Daniel Seifert 2024-11-01 23:49:52 +01:00
bovenliggende 1a3508d765
commit e1de358e91
Getekend door: DanielS
GPG sleutel-ID: 6A513E13AEE66170
2 gewijzigde bestanden met toevoegingen van 22 en 1 verwijderingen

Bestand weergeven

@ -11,6 +11,7 @@ See Deployer OXID recipe project for further instructions.
## available tasks
- dep `shop:getVersion` [stage] - show version of current OXID installation
- dep `shop:backupDatabase` [stage] - rotate old database backups and create a new one
- dep `shop:cloneDatabase` [stage] - dump contents from source to destination database
- dep `shop:runMigration` [stage] - run all database migrations
- dep `setup:createDbConfig` [stage] - generate database configuration file
- dep `setup:createDbConfig` [stage] - generate database configuration file

Bestand weergeven

@ -82,3 +82,23 @@ task('shop:cloneDatabase', function () {
warning('missing config, task skipped');
}
});
desc('rotate old database backups and create a new one');
task('shop:backupDatabase', function () {
if (get('mysql_configured') && get('mysqldump_configured')) {
if (!test("[ -f {{deploy_path}}/database/rotatemap.conf ]")) {
run('printf "{{deploy_path}}/database/backup/backup.sql {\n rotate 5\n}" > {{deploy_path}}/database/rotatemap.conf');
}
if (!test("[ -d {{deploy_path}}/database/backup ]")) {
run("mkdir -p {{deploy_path}}/database/backup");
}
$source_name = parse_ini_file(get('db_conf_path'))['database'];
if (test("[ -f {{deploy_path}}/database/backup/backup.sql ]")) {
run("logrotate -f -s {{deploy_path}}/database/rotatemap.state {{deploy_path}}/database/rotatemap.conf");
}
run("{{bin/mysqldump}} --defaults-extra-file={{db_conf_path}} --opt --no-create-db -f ".$source_name." $({{bin/mysql}} --defaults-extra-file={{db_conf_path}} -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;\") > {{deploy_path}}/database/backup/backup.sql");
info('successfully dumped to {{deploy_path}}/database/backup/backup.sql');
} else {
warning('missing config, task skipped');
}
});