add backup database task

Dieser Commit ist enthalten in:
Daniel Seifert 2024-11-01 23:49:52 +01:00
Ursprung 1a3508d765
Commit e1de358e91
Signiert von: DanielS
GPG-Schlüssel-ID: 6A513E13AEE66170
2 geänderte Dateien mit 22 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -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

Datei anzeigen

@ -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');
}
});