arham-solcoders/backupguard

Laravel package that creates daily SQL database backups and keeps only the last 3 days using the scheduler.

Maintainers

Package info

github.com/arham-solcoders/backupguard

pkg:composer/arham-solcoders/backupguard

Transparency log

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-06-02 11:19 UTC

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:
    • mysqldump for MySQL/MariaDB
    • pg_dump for 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)

  1. Create a new GitHub repository for this package.
  2. Push code to main.
  3. Tag a release:
    git tag v1.0.0
    git push origin v1.0.0
  4. Publish to Packagist:
  5. In consumer Laravel app:
    • composer require arham-solcoders/backupguard
    • php artisan vendor:publish --tag=laravel-db-backup-config
    • Configure backup path/connections
    • Ensure scheduler cron exists

Troubleshooting

  • mysqldump: not found or pg_dump: not found:
    • Install database client tools and ensure they are available in PATH.
  • Authentication failures:
    • Verify host app .env DB credentials.
  • Empty output:
    • Try command manually with verbose DB credentials to confirm binary access.

License

MIT