Добавлен функционал резервного копирования баз данных

- Кнопка "Бэкап" в toolbar открывает диалог выбора БД
- Можно скачать дамп одной БД или всех сразу
- Дамп создаётся через mysqldump и сразу стримится пользователю (gzip)
- Без сохранения на сервере

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-23 22:20:32 +03:00
parent 3cd138cd2d
commit b76402694a
4 changed files with 204 additions and 0 deletions

View File

@@ -356,4 +356,44 @@ $app->post('/api/table/delete-batch', function (Request $request, Response $resp
});
// === BACKUP API ===
// Скачать дамп всех баз данных
$app->get('/api/backup/all', function (Request $request, Response $response) use ($container) {
try {
$pdo = $container->get('db');
$backup = new \App\BackupService($_SESSION['db_user'], $_SESSION['db_pass']);
$data = $backup->dumpAllDatabases($pdo);
$filename = 'backup_all_' . date('Y-m-d_H-i-s') . '.sql.gz';
$response->getBody()->write($data);
return $response
->withHeader('Content-Type', 'application/gzip')
->withHeader('Content-Disposition', 'attachment; filename="' . $filename . '"')
->withHeader('Content-Length', strlen($data));
} catch (\Exception $e) {
$response->getBody()->write(json_encode(['error' => $e->getMessage()]));
return $response->withHeader('Content-Type', 'application/json')->withStatus(500);
}
});
// Скачать дамп конкретной базы
$app->get('/api/backup/database/{name}', function (Request $request, Response $response, array $args) {
try {
$database = $args['name'];
$backup = new \App\BackupService($_SESSION['db_user'], $_SESSION['db_pass']);
$data = $backup->dumpDatabase($database);
$filename = $database . '_' . date('Y-m-d_H-i-s') . '.sql.gz';
$response->getBody()->write($data);
return $response
->withHeader('Content-Type', 'application/gzip')
->withHeader('Content-Disposition', 'attachment; filename="' . $filename . '"')
->withHeader('Content-Length', strlen($data));
} catch (\Exception $e) {
$response->getBody()->write(json_encode(['error' => $e->getMessage()]));
return $response->withHeader('Content-Type', 'application/json')->withStatus(500);
}
});
$app->run();