feat: add scheduled daily backup, stored backup listing and download
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -38,4 +38,29 @@ class BackupController extends Controller
|
||||
'Content-Disposition' => "attachment; filename=\"{$filename}\"",
|
||||
]);
|
||||
}
|
||||
|
||||
public function listBackups()
|
||||
{
|
||||
$dir = storage_path('app/backups');
|
||||
$files = is_dir($dir) ? glob($dir . '/backup-webgis-*.sql') : [];
|
||||
usort($files, fn($a, $b) => filemtime($b) - filemtime($a));
|
||||
|
||||
$list = array_map(fn($f) => [
|
||||
'name' => basename($f),
|
||||
'size_kb' => round(filesize($f) / 1024, 1),
|
||||
'created_at' => date('d/m/Y H:i', filemtime($f)),
|
||||
], $files);
|
||||
|
||||
return response()->json($list);
|
||||
}
|
||||
|
||||
public function downloadStored(string $filename)
|
||||
{
|
||||
if (!preg_match('/^backup-webgis-[\d-]+\.sql$/', $filename)) {
|
||||
abort(400, 'Nama file tidak valid');
|
||||
}
|
||||
$path = storage_path('app/backups/' . $filename);
|
||||
if (!file_exists($path)) abort(404);
|
||||
return response()->download($path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user