Database Backups
The Database Backup system allows administrators to create, list, download, and delete full MySQL database backups. Backups are created using mysqldump piped to gzip and stored in the application's local storage. The system auto-prunes old backups to keep only the last 10.
Purpose
- Create on-demand full database backups (mysqldump + gzip)
- Download backup files for off-site storage
- Auto-prune old backups to prevent disk exhaustion (max 10 retained)
- Track backup metadata (size, creator, timestamp)
Entity Attributes
| Field | Type | Description |
|---|---|---|
id | integer | Primary key |
filename | string | Backup filename (e.g., backup_2026-02-23_143000.sql.gz) |
disk | string | Laravel filesystem disk (default: local) |
path | string | Storage path (e.g., backups/backup_2026-02-23_143000.sql.gz) |
size_bytes | integer | File size in bytes |
created_by | integer? | Foreign key to the user who created the backup |
created_at | datetime | Creation timestamp |
updated_at | datetime | Last update timestamp |
Relationships
API Endpoints
| Method | Path | Permission | Description |
|---|---|---|---|
GET | /api/core/backups | core.backups.view | List backups (paginated) |
POST | /api/core/backups | core.backups.create | Create new backup |
GET | /api/core/backups/{id}/download | core.backups.download | Download backup file |
DELETE | /api/core/backups/{id} | core.backups.delete | Delete backup file + record |
Query Parameters (List)
| Parameter | Type | Description |
|---|---|---|
per_page | integer | Items per page (1-100, default 25) |
Examples
Create a backup
bash
curl -X POST https://moon-erp.test/api/core/backups \
-H "Authorization: Bearer {token}"dart
final response = await dio.post('/api/core/backups');Response (201):
json
{
"data": {
"id": 1,
"filename": "backup_2026-02-23_143000.sql.gz",
"disk": "local",
"path": "backups/backup_2026-02-23_143000.sql.gz",
"size_bytes": 5242880,
"size_human": "5 MB",
"created_by": 1,
"creator": { "id": 1, "name": "Admin" },
"created_at": "2026-02-23T14:30:00.000000Z",
"updated_at": "2026-02-23T14:30:00.000000Z"
},
"message": "Backup created successfully"
}List backups
bash
curl https://moon-erp.test/api/core/backups?per_page=10 \
-H "Authorization: Bearer {token}"dart
final response = await dio.get('/api/core/backups', queryParameters: {'per_page': 10});Download a backup
bash
curl -OJ https://moon-erp.test/api/core/backups/1/download \
-H "Authorization: Bearer {token}"dart
await dio.download('/api/core/backups/1/download', './backup.sql.gz');Delete a backup
bash
curl -X DELETE https://moon-erp.test/api/core/backups/1 \
-H "Authorization: Bearer {token}"dart
await dio.delete('/api/core/backups/1');Business Rules
- Auto-prune: After each backup creation, the system keeps only the last 10 backups. Older backups and their files are deleted automatically.
- Global table:
database_backupsis not company-scoped since it represents a full database dump. - Storage: Files are stored at
storage/app/private/backups/via Laravel'slocaldisk. - mysqldump flags:
--single-transaction --routines --triggersfor a consistent snapshot without locking tables. - Permissions: Separate permissions for view, create, download, and delete operations.