Skip to content

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

FieldTypeDescription
idintegerPrimary key
filenamestringBackup filename (e.g., backup_2026-02-23_143000.sql.gz)
diskstringLaravel filesystem disk (default: local)
pathstringStorage path (e.g., backups/backup_2026-02-23_143000.sql.gz)
size_bytesintegerFile size in bytes
created_byinteger?Foreign key to the user who created the backup
created_atdatetimeCreation timestamp
updated_atdatetimeLast update timestamp

Relationships

API Endpoints

MethodPathPermissionDescription
GET/api/core/backupscore.backups.viewList backups (paginated)
POST/api/core/backupscore.backups.createCreate new backup
GET/api/core/backups/{id}/downloadcore.backups.downloadDownload backup file
DELETE/api/core/backups/{id}core.backups.deleteDelete backup file + record

Query Parameters (List)

ParameterTypeDescription
per_pageintegerItems 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

  1. Auto-prune: After each backup creation, the system keeps only the last 10 backups. Older backups and their files are deleted automatically.
  2. Global table: database_backups is not company-scoped since it represents a full database dump.
  3. Storage: Files are stored at storage/app/private/backups/ via Laravel's local disk.
  4. mysqldump flags: --single-transaction --routines --triggers for a consistent snapshot without locking tables.
  5. Permissions: Separate permissions for view, create, download, and delete operations.

Workflow

Moon ERP API Documentation