ubxty / spatie-laravel-backup-utils
Enhanced utilities and notifications for spatie/laravel-backup with comprehensive logging, S3 configuration, and statistical analysis
Installs: 37
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ubxty/spatie-laravel-backup-utils
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/filesystem: ^10.0|^11.0|^12.0
- illuminate/notifications: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- spatie/laravel-backup: ^8.0|^9.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
README
Enhanced utilities and notifications for spatie/laravel-backup with comprehensive logging, S3 configuration, and statistical analysis.
๐ Features
- ๐ง Unified Command Interface - Single
backup:utilscommand for all backup operations - ๐ Advanced Analytics - Comprehensive backup statistics and trend analysis
- ๐ S3 Configuration & Testing - Interactive S3 setup with connection validation
- ๐ Enhanced Logging - Structured backup event logging with metadata
- ๐ Smart Notifications - Auto-enhanced notification system with detailed context
- โ๏ธ Auto-Configuration - Automatic setup of logging, filesystem, and notifications
- ๐งช Testing Tools - Built-in connection testing and validation utilities
๐ Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
- spatie/laravel-backup 8.0 or higher
๐ฆ Installation
Install the package via Composer:
composer require ubxty/spatie-laravel-backup-utils
The package will automatically register its service provider and commands.
Quick Setup
Run the installation command for guided setup:
php artisan backup:utils install
This will:
- Publish configuration files
- Set up backup logging
- Configure S3 filesystem (if needed)
- Install spatie/laravel-backup (if not present)
- Guide you through S3 configuration
๐ฏ Usage
Unified Command Interface
Access all backup utilities through a single command:
# Interactive menu with numbered options php artisan backup:utils # Direct actions php artisan backup:utils stats # View backup statistics php artisan backup:utils config-s3 # Configure S3 settings php artisan backup:utils logs # View and analyze logs php artisan backup:utils test # Test notification system php artisan backup:utils run # Run backup with enhanced logging php artisan backup:utils monitor # Monitor backup health php artisan backup:utils install # Setup and configuration
Interactive Menu Features:
- ๐ฏ Numbered Options (1-9) - Simply type a number to select an action
- ๐ Smart Navigation - Return to menu after each action completes
- ๐ System Status - Real-time status check of backup components
- ๐ก Contextual Tips - Random helpful tips displayed with each menu
- โจ Visual Feedback - Beautiful execution boxes with timing information
- ๐งน Clean Interface - Screen clearing and consistent styling
The interactive menu displays:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐ง UBXTY Backup Utils Dashboard โ
โ Enhanced Laravel Backup Management โ
โ by Ubxty v1.0.0 โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
๐ฏ Available Actions:
[1] ๐ Backup Statistics & Analytics
View comprehensive backup statistics, trends, and performance metrics
[2] ๐ง S3 Configuration & Testing
Configure and test S3 backup settings interactively
[3] ๐ Run Backup
Execute backup with enhanced logging and notifications
[4] ๐ Monitor Backup Health
Check backup health and generate monitoring reports
[5] ๐ List Backups
Display all available backups with detailed information
[6] ๐งน Clean Old Backups
Remove old backups according to retention policies
[7] ๐งช Test Notifications
Test backup notification system and logging
[8] ๐ View Backup Logs
View and analyze backup notification logs
[9] โ๏ธ Install & Configure
Set up backup utilities with guided configuration
[0] ๐ช Exit
๐ก Tip: Start with "Install & Configure" if this is your first time
๐ Please enter your choice (0-9) [1]:
Backup Statistics & Analytics
View comprehensive backup statistics:
# Default view (last 30 days) php artisan backup:stats # Custom time period php artisan backup:stats --days=7 # Different output formats php artisan backup:stats --format=summary php artisan backup:stats --format=json # Export reports php artisan backup:stats --export=json php artisan backup:stats --export=csv
Statistics Include:
- Success/failure rates and trends
- Performance metrics (memory usage, execution time)
- Notification type breakdown
- Recent activity timeline
- Failure analysis with troubleshooting suggestions
S3 Configuration & Testing
Interactive S3 backup configuration:
php artisan backup:config
Features:
- ๐ Show current configuration with masked sensitive values
- โ๏ธ Interactive prompts for all S3 settings
- ๐งช Comprehensive connection testing
- ๐ ๏ธ Troubleshooting suggestions
- ๐ Smart workflows (configure โ test)
Connection Testing:
- S3 disk connectivity
- File upload/download operations
- Directory access validation
- Optional backup run test
Backup Log Analysis
View and analyze backup logs with detailed filtering:
# View recent backup logs (default: last 7 days) php artisan backup:logs # Filter by time period php artisan backup:logs --days=30 # Filter by log level php artisan backup:logs --level=error # Show only statistics php artisan backup:logs --stats # Filter by backup event type php artisan backup:logs --event=BackupWasSuccessful # Limit number of entries php artisan backup:logs --tail=100
Log Analysis Features:
- ๐ Automatic log file detection (daily rotation support)
- ๐ Advanced filtering by level, event type, and time period
- ๐ Statistical analysis of backup events
- ๐ Formatted table output with color-coded log levels
- ๐ Human-readable timestamps and event summaries
โ๏ธ Configuration
Environment Variables
The package uses these environment variables:
# S3 Backup Configuration (Required) AWS_ACCESS_KEY_ID_BACKUP=your_access_key AWS_SECRET_ACCESS_KEY_BACKUP=your_secret_key AWS_DEFAULT_REGION_BACKUP=us-east-1 AWS_BUCKET_BACKUP=your_bucket_name # Optional S3 Settings AWS_URL_BACKUP=https://your-bucket.s3.region.amazonaws.com AWS_ENDPOINT_BACKUP=https://s3.region.amazonaws.com AWS_USE_PATH_STYLE_ENDPOINT_BACKUP=false # Backup Archive Encryption BACKUP_ARCHIVE_PASSWORD=your_secure_password # UBXTY Backup Utils Settings BACKUP_LOG_LEVEL=debug BACKUP_LOG_DAYS=60 BACKUP_STATS_DEFAULT_DAYS=30
Auto-Configuration
The package automatically configures:
- Backup Logging Channel - Creates
backuplog channel - S3 Filesystem Disk - Sets up
s3_backupdisk - Enhanced Notifications - Adds logging to all backup notifications
- Backup Notifiable - Uses enhanced notifiable class
To disable auto-configuration:
BACKUP_UTILS_AUTO_LOGGING=false BACKUP_UTILS_AUTO_FILESYSTEM=false BACKUP_UTILS_AUTO_NOTIFICATIONS=false
Manual Configuration
Publish configuration files for manual setup:
# Publish main config php artisan vendor:publish --tag=backup-utils-config # Publish environment template php artisan vendor:publish --tag=backup-utils-env
๐ Backup Encryption
The package supports password-based encryption for backup archives:
Setting Up Encryption
- Environment Variable Method (Recommended):
BACKUP_ARCHIVE_PASSWORD=your_secure_password_here
- Interactive Configuration:
php artisan backup:config
# Select "Update S3 configuration" and set the archive password
- Direct Configuration:
// config/backup.php 'backup' => [ 'destination' => [ 'password' => env('BACKUP_ARCHIVE_PASSWORD'), 'encryption' => 'default', // Uses AES-256 when available ], ],
Encryption Features
- AES-256 Encryption: Uses strong encryption when available on your system
- Password Protection: All backup archives are encrypted with your password
- Secure Input: Password is entered securely (hidden input) during configuration
- Optional: Encryption can be disabled by leaving password empty
- Cross-Platform: Works with standard ZIP encryption
Security Best Practices
- Use a strong, unique password for backup encryption
- Store the password securely (e.g., password manager)
- Consider rotating encryption passwords periodically
- Test backup restoration with encrypted archives
- Keep password separate from backup storage location
Testing Encrypted Backups
# Test backup creation with encryption php artisan backup:run # Verify encrypted backup can be accessed php artisan backup:list # Test S3 upload of encrypted backups php artisan backup:config # Choose "Update configuration and then test"
๐ Enhanced Logging
The package provides structured logging for all backup events:
{
"timestamp": "2024-01-15T10:30:00.000000Z",
"notification_type": "BackupWasSuccessfulNotification",
"notifiable_type": "BackupNotifiable",
"metadata": {
"memory_usage": 67108864,
"php_version": "8.2.0",
"laravel_version": "12.0"
},
"backup_info": {
"backup_name": "laravel-backup",
"disk_names": ["local", "s3_backup"],
"file_size": 52428800,
"backup_date": "2024-01-15T10:30:00.000000Z"
}
}
Logs are automatically written to storage/logs/backup.log with daily rotation.
๐ Enhanced Notifications
The package enhances all Spatie backup notifications with:
- Structured logging of notification events
- Metadata extraction (memory usage, system info)
- Backup information (file sizes, disk names, dates)
- Exception details for failed operations
- Performance metrics for monitoring
๐ Statistics Dashboard
The backup:stats command provides comprehensive analytics:
Overview Metrics
- Total backup events
- Success/failure rates
- Performance trends
Detailed Analysis
- Notification type breakdown
- Time-based patterns (daily/hourly)
- Failure analysis with trends
- Recent activity timeline
Export Options
- JSON format for APIs
- CSV format for spreadsheets
- Timestamped files for history
๐งช Testing
The package includes comprehensive testing utilities:
S3 Connection Testing
php artisan backup:config
# Choose "Test existing S3 connection"
Notification Testing
php artisan backup:test-notifications --type=success php artisan backup:test-notifications --type=failed
๐ง Advanced Usage
Custom Notifiable Class
To use a custom notifiable class:
// config/backup-utils.php 'notifications' => [ 'notifiable_class' => App\Notifications\CustomBackupNotifiable::class, ],
Custom Log Channel
Configure a custom backup log channel:
// config/logging.php 'channels' => [ 'backup' => [ 'driver' => 'daily', 'path' => storage_path('logs/backup.log'), 'level' => 'debug', 'days' => 60, ], ],
Statistics Caching
Configure statistics caching:
BACKUP_STATS_CACHE_DURATION=300 # 5 minutes
๐ ๏ธ Troubleshooting
Common Issues
S3 Connection Failures:
- Verify AWS credentials are correct
- Check bucket exists and region matches
- Ensure proper S3 permissions
- Validate bucket naming conventions
Missing Logs:
- Check
storage/logs/directory permissions - Verify backup log channel configuration
- Ensure notifications are properly configured
Command Not Found:
- Clear configuration cache:
php artisan config:clear - Verify package is properly installed
- Check service provider registration
Debug Mode
Enable verbose output for troubleshooting:
php artisan backup:utils stats -vvv php artisan backup:config -vvv
๐ License
The MIT License (MIT). Please see License File for more information.
๐ค Contributing
Please see CONTRIBUTING.md for details.
๐ Security
If you discover any security related issues, please email security@ubxty.com instead of using the issue tracker.
๐ Support
- ๐ง Email: info@ubxty.com
- ๐ Issues: GitHub Issues
- ๐ Documentation: GitHub Wiki
- ๐ Website: UBXTY Unboxing Technology
Built with โค๏ธ by Ravdeep Singh โข UBXTY Unboxing Technology