💾 Backup System Guide

Easy database backup and restore functionality for your projects

✅ Simple & Reliable: The backup system is designed to be easy to use and works seamlessly with your projects.
📋 Two Backup Systems Available:

🚀 Quick Start

Create a Backup

POST /api/v1/backup
Authorization: Bearer YOUR_TOKEN

Creates a full database backup with timestamp.

List Backups

GET /api/v1/backup
Authorization: Bearer YOUR_TOKEN

Lists all available backups with details.

📋 Features

🔐 Secure

  • Authentication required
  • Superadmin-only for restore/delete
  • Safe backup creation for all users

🔄 Automatic

  • Timestamped filenames
  • Automatic cleanup (keeps last 20)
  • Full database backup

📊 Detailed

  • File sizes and timestamps
  • System status monitoring
  • Backup statistics

🔧 API Endpoints

POST /api/v1/backup - Create Database Backup
Description:

Creates a full database backup with automatic timestamping and cleanup.

Authentication:

Any authenticated user can create backups.

Response:
{
  "success": true,
  "message": "Database backup created successfully",
  "backup": {
    "filename": "backup_2025-08-23_22-56-27.sql",
    "filepath": "/home/la/backups/full/backup_2025-08-23_22-56-27.sql",
    "filesize": 2519105,
    "filesize_formatted": "2.4 MB",
    "created_at": "2025-08-23 22:56:27",
    "timestamp": "2025-08-23_22-56-27"
  }
}
Example:
curl -X POST 'https://la.deltascripts.com/api/v1/backup' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json'
GET /api/v1/backup - List Backups
Description:

Lists all available backup files with detailed information.

Authentication:

Any authenticated user can list backups.

Response:
{
  "backups": [
    {
      "filename": "backup_2025-08-23_22-56-27.sql",
      "filepath": "/home/la/backups/full/backup_2025-08-23_22-56-27.sql",
      "filesize": 2519105,
      "filesize_formatted": "2.4 MB",
      "created_at": "2025-08-23 22:56:27",
      "modified_at": "2025-08-23 22:56:27"
    }
  ],
  "total": 1,
  "backup_directory": "/home/la/backups/full/"
}
Example:
curl -X GET 'https://la.deltascripts.com/api/v1/backup' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json'
GET /api/v1/backup/status - System Status
Description:

Get backup system status and statistics.

Authentication:

Any authenticated user can check status.

Response:
{
  "system_status": {
    "backup_directory": "/home/la/backups/full/",
    "backup_directory_exists": true,
    "backup_directory_writable": true,
    "mysqldump_available": true,
    "max_backups_kept": 10
  },
  "backup_stats": {
    "total_backups": 2,
    "total_size": 4975230,
    "total_size_formatted": "4.74 MB",
    "oldest_backup": {
      "filename": "backup_2025-08-23_22-39-42.sql",
      "created_at": "2025-08-23 22:39:42"
    },
    "newest_backup": {
      "filename": "backup_2025-08-23_22-56-27.sql",
      "created_at": "2025-08-23 22:56:27"
    }
  }
}
POST /api/v1/backup/restore - Restore from Backup
Description:

Restore the database from a backup file.

Authentication:

Superadmin only - This is a destructive operation.

Request Body:
{
  "filename": "backup_2025-08-23_22-56-27.sql"
}
Response:
{
  "success": true,
  "message": "Database restored successfully from backup",
  "restore": {
    "filename": "backup_2025-08-23_22-56-27.sql",
    "filepath": "/home/la/backups/full/backup_2025-08-23_22-56-27.sql",
    "restored_at": "2025-08-23 22:56:27"
  }
}
POST /api/v1/backup/cleanup - Cleanup Old Backups
Description:

Manually trigger cleanup of old backup files, keeping only the 20 newest backups.

Authentication:

Admin users only - This deletes the oldest backup files.

Response:
{
  "success": true,
  "message": "Backup cleanup completed",
  "cleanup_stats": {
    "files_before": 25,
    "files_after": 20,
    "files_deleted": 5,
    "space_freed": 12582912,
    "space_freed_formatted": "12 MB",
    "max_backups_kept": 20
  }
}
Example:
curl -X POST 'https://la.deltascripts.com/api/v1/backup/cleanup' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json'
DELETE /api/v1/backup/{filename} - Delete Backup
Description:

Delete a specific backup file.

Authentication:

Superadmin only - This permanently deletes the backup.

Example:
curl -X DELETE 'https://la.deltascripts.com/api/v1/backup/backup_2025-08-23_22-56-27.sql' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json'

💡 Usage Examples

🔧 Development Workflow

  1. Before major changes: Create a backup
  2. Test your changes
  3. If something goes wrong: Restore from backup
  4. Clean up: Delete old backups when no longer needed

🔄 Production Safety

  1. Regular backups: Schedule daily/weekly backups
  2. Before updates: Always backup before deployments
  3. Monitor space: Check backup directory size
  4. Test restores: Periodically test restore functionality

🛡️ Security & Permissions

🔐 Permission Levels:
⚠️ Important Notes:

📊 Backup Information

File Naming Convention

Backups are named with the pattern:

backup_YYYY-MM-DD_HH-MM-SS.sql

Example: backup_2025-08-23_22-56-27.sql

Storage Details

  • Directory: /home/la/backups/full/
  • Max backups: 20 files
  • Format: Full SQL dump
  • Compression: None (raw SQL)

🗂️ Project Backup System

Project-specific backups: Create, manage, and restore individual project data including areas, sections, strings, and translations.

🚀 Project Backup Quick Start

Create Project Backup

POST /api/v1/projects/{id}/backup
Authorization: Bearer YOUR_TOKEN

Creates a project-specific backup with all project data.

List Project Backups

GET /api/v1/projects/{id}/backup
Authorization: Bearer YOUR_TOKEN

Lists all backups for a specific project.

🔧 Project Backup API Endpoints

POST /api/v1/projects/{id}/backup - Create Project Backup
Description:

Creates a project-specific backup containing all areas, sections, strings, and translations for the project.

Authentication:

Project admin role required.

Response:
{
  "success": true,
  "message": "Project backup created successfully",
  "backup": {
    "filename": "project_64_backup_2025-08-24_01-32-26.json",
    "filepath": "/home/la/backups/userbackups/64/project_64_backup_2025-08-24_01-32-26.json",
    "filesize": 23384,
    "filesize_formatted": "22.84 KB",
    "created_at": "2025-08-24 01:32:26",
    "project_id": 64,
    "project_name": "TestProjectStrings",
    "data_summary": {
      "areas": 3,
      "sections": 9,
      "strings": 21,
      "translations": 50
    }
  }
}
Example:
curl -X POST 'https://la.deltascripts.com/api/v1/projects/64/backup' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json'
GET /api/v1/projects/{id}/backup - List Project Backups
Description:

Lists project backup files with metadata, size, and creation details.

Authentication:

Project read access required.

Response:
{
  "backups": [
    {
      "filename": "project_64_backup_2025-08-24_01-32-26.json",
      "filepath": "/home/la/backups/userbackups/64/project_64_backup_2025-08-24_01-32-26.json",
      "filesize": 23384,
      "filesize_formatted": "22.84 KB",
      "created_at": "2025-08-24 01:32:26",
      "modified_at": "2025-08-24 01:32:26",
      "metadata": {
        "project_id": 64,
        "project_name": "TestProjectStrings",
        "created_at": "2025-08-24 01:32:26",
        "created_by": 1,
        "created_by_name": "Admin User",
        "backup_version": "1.0"
      }
    }
  ],
  "total": 1,
  "project_id": 64,
  "backup_directory": "/home/la/backups/userbackups/64/"
}
Example:
curl -X GET 'https://la.deltascripts.com/api/v1/projects/64/backup' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json'
POST /api/v1/projects/{id}/backup/restore - Restore Project from Backup
Description:

Restore project data from a backup file. This will replace all existing project data.

Authentication:

Project admin role required - This is a destructive operation.

Request Body:
{
  "filename": "project_64_backup_2025-08-24_01-32-26.json"
}
Response:
{
  "success": true,
  "message": "Project backup restored successfully",
  "restore_summary": {
    "backup_filename": "project_64_backup_2025-08-24_01-32-26.json",
    "backup_created_at": "2025-08-24 01:32:26",
    "backup_created_by": "Admin User",
    "restored_data": {
      "areas": 3,
      "sections": 9,
      "strings": 21,
      "translations": 50
    }
  }
}
Example:
curl -X POST 'https://la.deltascripts.com/api/v1/projects/64/backup/restore' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"filename": "project_64_backup_2025-08-24_01-32-26.json"}'
DELETE /api/v1/projects/{id}/backup/{filename} - Delete Project Backup
Description:

Delete a project backup file.

Authentication:

Project admin role required - This permanently deletes the backup.

Example:
curl -X DELETE 'https://la.deltascripts.com/api/v1/projects/64/backup/project_64_backup_2025-08-24_01-32-26.json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json'
GET /api/v1/projects/{id}/backup/status - Project Backup Status
Description:

Get project backup system status and statistics.

Authentication:

Project read access required.

Response:
{
  "system_status": {
    "backup_directory": "/home/la/backups/userbackups/64/",
    "backup_directory_exists": true,
    "backup_directory_writable": true,
    "max_backups_kept": 10,
    "project_id": 64
  },
  "backup_stats": {
    "total_backups": 1,
    "total_size": 23384,
    "total_size_formatted": "22.84 KB",
    "oldest_backup": {
      "filename": "project_64_backup_2025-08-24_01-32-26.json",
      "created_at": "2025-08-24 01:32:26"
    },
    "newest_backup": {
      "filename": "project_64_backup_2025-08-24_01-32-26.json",
      "created_at": "2025-08-24 01:32:26"
    }
  }
}
Example:
curl -X GET 'https://la.deltascripts.com/api/v1/projects/64/backup/status' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json'

📊 Project Backup Features

🗂️ Project Isolation

  • Each project has its own backup directory
  • Separate backup management per project
  • Project-specific access controls

📄 JSON Format

  • Human-readable backup files
  • Portable and easy to inspect
  • Complete project structure

🔒 Security

  • Project admin role required for backup/restore
  • Project read access for list/status
  • Directory isolation prevents cross-project access
⚠️ Project Backup Notes:

🔍 Troubleshooting

Common Issues
❌ Backup Creation Fails
  • Check permissions: Ensure backup directory is writable
  • Check disk space: Ensure sufficient space for backup
  • Check mysqldump: Ensure MySQL client tools are installed
❌ Restore Fails
  • Check file exists: Verify backup file is present
  • Check permissions: Ensure superadmin access
  • Check database connection: Verify database is accessible
❌ Permission Denied
  • Restore/Delete: Requires superadmin privileges
  • Authentication: Ensure valid Bearer token
  • Token expiry: Check if token has expired
❌ Wrong Date/Time Display
  • Timezone issue: All timestamps are in Norwegian time (Europe/Oslo)
  • Date parsing: Backup filenames contain timestamps in YYYY-MM-DD_HH-MM-SS format
  • Display format: Dates are shown in local server timezone

🎯 Best Practices

✅ Do's

  • Create backups before major changes
  • Test restore functionality periodically
  • Monitor backup directory size
  • Use descriptive backup names
  • Keep backups in a secure location

❌ Don'ts

  • Don't restore without testing first
  • Don't delete backups without verification
  • Don't ignore backup failures
  • Don't rely on single backup copy
  • Don't skip authentication checks
✅ Summary

The backup system is designed to be simple, secure, and reliable. It provides easy database backup and restore functionality with proper access controls and automatic management.


← Back to API Documentation