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:
GuavaPopper
2026-06-04 14:51:07 +07:00
parent 1535c75138
commit f77fc725a8
6 changed files with 146 additions and 2 deletions
+25
View File
@@ -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);
}
}