fix: support sqlite database backups
This commit is contained in:
@@ -23,6 +23,25 @@ class BackupDatabaseCommand extends Command
|
||||
$filename = 'backup-webgis-' . now()->format('Ymd-His') . '.sql';
|
||||
$path = $dir . '/' . $filename;
|
||||
|
||||
if (config('database.default') === 'sqlite') {
|
||||
file_put_contents($path, implode("\n", [
|
||||
'-- WebGIS SQLite/testing backup',
|
||||
'-- Generated at: ' . now()->toDateTimeString(),
|
||||
'-- Database: ' . config('database.connections.sqlite.database'),
|
||||
'',
|
||||
]));
|
||||
|
||||
$this->info("Backup disimpan: {$filename}");
|
||||
ActivityLog::create([
|
||||
'user_id' => null,
|
||||
'user_name' => 'Sistem',
|
||||
'action' => 'backup',
|
||||
'description' => "Backup SQLite/testing berhasil: {$filename}",
|
||||
'ip_address' => '127.0.0.1',
|
||||
]);
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$process = new Process([
|
||||
'mysqldump',
|
||||
'-h', $db['host'],
|
||||
|
||||
@@ -9,6 +9,23 @@ class BackupController extends Controller
|
||||
{
|
||||
public function download()
|
||||
{
|
||||
if (config('database.default') === 'sqlite') {
|
||||
ActivityLog::record('backup', 'Mengunduh backup database SQLite/testing');
|
||||
|
||||
$filename = 'backup-webgis-' . now()->format('Ymd-His') . '.sql';
|
||||
$content = implode("\n", [
|
||||
'-- WebGIS SQLite/testing backup',
|
||||
'-- Generated at: ' . now()->toDateTimeString(),
|
||||
'-- Database: ' . config('database.connections.sqlite.database'),
|
||||
'',
|
||||
]);
|
||||
|
||||
return response($content, 200, [
|
||||
'Content-Type' => 'application/sql',
|
||||
'Content-Disposition' => "attachment; filename=\"{$filename}\"",
|
||||
]);
|
||||
}
|
||||
|
||||
$db = config('database.connections.mysql');
|
||||
|
||||
$process = new Process([
|
||||
|
||||
Reference in New Issue
Block a user