Skip to main content

System Backup

Module for System Backup Management.

Overview

The System Backup module provides comprehensive backup management capabilities for your Open Core Business Suite installation. Built on the robust Spatie Laravel Backup package, it enables administrators to create, schedule, and manage backups of both the database and application files.

Features

  • Database Backups: Full database dumps with compression
  • File Backups: Backup application files and uploads
  • Scheduled Backups: Automated backups on configurable schedules
  • Backup Download: Download backup files directly from the admin panel
  • Backup Restoration: Restore from previous backups
  • Multiple Storage: Store backups locally, on cloud storage, or both
  • Backup Notifications: Email alerts for backup success/failure
  • Retention Policies: Automatic cleanup of old backups
  • Backup Health Monitoring: Monitor backup status and disk usage

Requirements

  • Open Core Business Suite (Base System)
  • No additional module dependencies
  • Spatie Laravel Backup (included)
  • Sufficient storage space for backups

Installation

  1. Enable the module in your module configuration:
// config/modules.php or via admin panel
'SystemBackup' => true,
  1. Run the module migrations:
php artisan module:migrate SystemBackup
  1. Publish the backup configuration:
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"

Configuration

Module Settings

Access backup settings through Settings > System Backup:

SettingDescriptionDefault
Enable BackupsEnable/disable backup functionalityEnabled
Backup DatabaseInclude database in backupsYes
Backup FilesInclude application filesYes
Storage DiskWhere to store backupslocal
Retention DaysDays to keep daily backups7
Retention WeeksWeeks to keep weekly backups4
Retention MonthsMonths to keep monthly backups6
Notification EmailEmail for backup notifications-

Backup Configuration File

For advanced configuration, edit config/backup.php:

return [
'backup' => [
'name' => env('APP_NAME', 'laravel-backup'),

'source' => [
'files' => [
'include' => [
base_path(),
],
'exclude' => [
base_path('vendor'),
base_path('node_modules'),
storage_path('app/backups'),
],
],
'databases' => [
'mysql',
],
],

'destination' => [
'filename_prefix' => '',
'disks' => [
'local',
// 's3', // Uncomment for cloud backup
],
],
],

'cleanup' => [
'strategy' => \Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy::class,
'default_strategy' => [
'keep_all_backups_for_days' => 7,
'keep_daily_backups_for_days' => 16,
'keep_weekly_backups_for_weeks' => 8,
'keep_monthly_backups_for_months' => 4,
'keep_yearly_backups_for_years' => 2,
'delete_oldest_backups_when_using_more_megabytes_than' => 5000,
],
],
];

Cloud Storage Setup

To backup to cloud storage (e.g., AWS S3):

  1. Configure your cloud disk in config/filesystems.php
  2. Add the disk name to backup.destination.disks
  3. Set up appropriate credentials in .env
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=your-backup-bucket

Usage

Manual Backup

Via Admin Panel

  1. Navigate to Settings > System Backup
  2. Click Create Backup Now
  3. Select backup type (Full, Database Only, or Files Only)
  4. Wait for backup to complete
  5. Download or verify the backup

Via Command Line

# Full backup
php artisan backup:run

# Database only
php artisan backup:run --only-db

# Files only
php artisan backup:run --only-files

# To specific disk
php artisan backup:run --only-to-disk=s3

Scheduled Backups

Configure automatic backups in your scheduler (app/Console/Kernel.php):

protected function schedule(Schedule $schedule)
{
// Daily backup at 1:00 AM
$schedule->command('backup:run')->daily()->at('01:00');

// Weekly cleanup of old backups
$schedule->command('backup:clean')->weekly()->at('02:00');

// Daily backup monitoring
$schedule->command('backup:monitor')->daily()->at('03:00');
}

Or configure via the admin panel schedule settings.

Viewing Backups

Via Admin Panel

  1. Go to Settings > System Backup > Backup List
  2. View all available backups with:
    • Backup date and time
    • Backup size
    • Storage location
    • Download and delete options

Via Command Line

php artisan backup:list

Downloading Backups

  1. Navigate to the backup list
  2. Click the download icon for the desired backup
  3. The backup ZIP file will download to your browser

Restoring from Backup

Database Restoration

# Extract backup
unzip backup-2024-01-15.zip

# Restore database
mysql -u username -p database_name < db-dumps/mysql-database.sql

Full Restoration

  1. Extract the backup archive
  2. Restore database from the SQL dump
  3. Copy files back to their original locations
  4. Clear application caches:
php artisan cache:clear
php artisan config:clear
php artisan view:clear

Backup Cleanup

Remove old backups according to retention policy:

php artisan backup:clean

Monitoring Backup Health

Check backup status and storage:

php artisan backup:monitor

API Endpoints

List Backups

GET /api/V1/system/backups

Create Backup

POST /api/V1/system/backups
Content-Type: application/json

{
"type": "full" // Options: full, database, files
}

Download Backup

GET /api/V1/system/backups/{filename}/download

Delete Backup

DELETE /api/V1/system/backups/{filename}

Backup Status

GET /api/V1/system/backups/status

Notifications

Configure email notifications for backup events:

// config/backup.php
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class => ['mail'],
],

'mail' => [
'to' => '[email protected]',
'from' => [
'address' => env('MAIL_FROM_ADDRESS'),
'name' => env('MAIL_FROM_NAME'),
],
],
],

Best Practices

  1. Regular Testing: Periodically test backup restoration
  2. Offsite Storage: Keep copies on cloud storage or external drives
  3. Monitor Disk Space: Ensure adequate storage for backups
  4. Secure Backups: Encrypt backups containing sensitive data
  5. Document Procedures: Maintain restoration documentation
  6. Verify Completeness: Regularly check backup contents

Troubleshooting

Backup Fails with Memory Error

Increase PHP memory limit:

// In backup command or php.ini
ini_set('memory_limit', '512M');

Backup Too Large

  • Exclude unnecessary files (vendor, node_modules)
  • Use database-only backups more frequently
  • Increase storage allocation

Backup Timeout

For large backups, increase timeout:

php artisan backup:run --timeout=3600

Cannot Download Large Backups

  • Use command line to copy backups
  • Configure direct download links
  • Use cloud storage with signed URLs

Storage Disk Full

  • Review retention policies
  • Run cleanup manually: php artisan backup:clean
  • Move old backups to archive storage