arham-solcoders / backupguard
Laravel package that creates daily SQL database backups and keeps only the last 3 days using the scheduler.
v1.0.0
2026-06-02 11:19 UTC
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
This package is not auto-updated.
Last update: 2026-08-12 10:29:35 UTC
README
A publishable Laravel package that creates daily SQL database backups from the host project's database configuration and keeps only the last 3 days of backup files.
Features
- Daily backup command:
db-backup:run - Reads connection settings from host app
config/database.php(which comes from host.env) - Supports MySQL/MariaDB and PostgreSQL
- Prunes backup files older than configured retention (default: 3 days)
- Publishable config file
Requirements
- PHP 8.1+
- Laravel 10/11/12
- System binaries:
mysqldumpfor MySQL/MariaDBpg_dumpfor PostgreSQL
Installation
composer require arham-solcoders/backupguard
The service provider is auto-discovered.
Publish Config
php artisan vendor:publish --tag=laravel-db-backup-config
This creates:
config/laravel-db-backup.php
Configuration
return [ 'enabled' => true, 'backup_path' => storage_path('app/db-backups'), 'connections' => [], // empty = auto-detect all supported SQL connections 'retention_days' => 3, 'compress' => false, 'timeout_seconds' => 300, ];
Scheduling
For Laravel 11+, the package uses withSchedule() automatically.
For Laravel 10, add this to your app scheduler:
protected function schedule(Schedule $schedule): void { $schedule->command('db-backup:run')->daily(); }
Cron (Server)
Make sure your server cron runs Laravel scheduler every minute:
* * * * * php /path-to-project/artisan schedule:run >> /dev/null 2>&1
Verify
Run manually:
php artisan db-backup:run
Backups are stored in:
storage/app/db-backups/{connection-name}/{YYYY-MM-DD}/
Publish This Package (Complete Steps)
- Create a new GitHub repository for this package.
- Push code to
main. - Tag a release:
git tag v1.0.0 git push origin v1.0.0
- Publish to Packagist:
- Open https://packagist.org/packages/submit
- Submit your repository URL
- In consumer Laravel app:
composer require arham-solcoders/backupguardphp artisan vendor:publish --tag=laravel-db-backup-config- Configure backup path/connections
- Ensure scheduler cron exists
Troubleshooting
mysqldump: not foundorpg_dump: not found:- Install database client tools and ensure they are available in PATH.
- Authentication failures:
- Verify host app
.envDB credentials.
- Verify host app
- Empty output:
- Try command manually with verbose DB credentials to confirm binary access.
License
MIT