spatie/db-dumper
PHP database dump helper that wraps native tools (mysqldump, mariadb-dump, pg_dump, sqlite3, mongodump). Supports MySQL/MariaDB, PostgreSQL, SQLite, and MongoDB with a fluent API to configure credentials and dump to SQL or gz files.
Strengths:
setDbName(), excludeTables(), etc.) align well with Laravel’s expressive syntax.GzipCompressor/Bzip2Compressor reduces storage/transfer overhead, critical for large databases.skipAutoIncrement(), doNotDumpData(), and includeRoutines() enable precise dump customization (e.g., excluding logs or sessions).mysqldump, pg_dump, etc.), ensuring performance and reliability without reinventing the wheel.Weaknesses:
mysqldump), which may not be available in all environments (e.g., Docker containers without CLI tools).Laravel Ecosystem Fit:
php artisan db:dump) for CLI-driven workflows..env for credentials) via dependency injection.storage/app/dumps/) for standardized storage paths.Potential Friction Points:
mysqldump, pg_dump, etc., are installed in CI/CD pipelines (e.g., GitHub Actions, Docker).env() or vaults like HashiCorp Vault).High:
--column-statistics=0 may behave differently across MySQL versions (e.g., 5.7 vs. 8.0)..gz) are less portable than SQL dumps (e.g., no direct mysql import).Medium:
Low:
Deployment Context:
mysqldump, pg_dump) guaranteed to be available in all environments (e.g., shared hosting, serverless)?.env, secrets manager, IAM roles)?Scalability:
Recovery Workflow:
Monitoring/Alerting:
Alternatives:
Schema::dump() or third-party tools like Laravel Backup or Veewee Backup?Laravel Core:
php artisan db:dump) to encapsulate usage.
// app/Console/Commands/DumpDatabase.php
use Spatie\DbDumper\Databases\MySql;
class DumpDatabase extends Command {
protected $signature = 'db:dump {--database=} {--output=storage/app/dumps/{timestamp}.sql}';
public function handle() {
MySql::create()
->setDbName(config('database.connections.mysql.database'))
->setUserName(config('database.connections.mysql.username'))
->setPassword(config('database.connections.mysql.password'))
->dumpToFile($this->option('output'));
}
}
config/database.php to include dump-specific settings (e.g., default paths, compression).Infrastructure:
FROM mysql:8.0 + mysqldump).which mysqldump).Frontend/Backend:
/admin/db/dump).Phase 1: Proof of Concept
Phase 2: Integration
app/Console/Kernel.php.config/db-dumper.php (e.g., default paths, compression).DatabaseManager for dynamic config).Phase 3: Automation
schedule (e.g., nightly backups).filesystem disk).Phase 4: Scaling
dumpToFile with Laravel Encryption).| Component | Compatibility Notes |
|---|---|
| Laravel Versions | Tested on Laravel 8+ (PHP 8.0+). Backward compatibility may require adjustments. |
| Databases | MySQL 5.7+, PostgreSQL 10+, SQLite 3, MongoDB 4+. Validate versions in README. |
| PHP Extensions | None required, but pdo_mysql, pdo_pgsql may be needed for connection checks. |
| OS | Linux/Windows/macOS (CLI tools must be installed). |
| Laravel Packages | Conflicts unlikely, but test with laravel-backup or spatie/laravel-backup. |
Prerequisites:
mysqldump, pg_dump, etc.) in all environments..env or a secrets manager.Development:
composer require spatie/db-dumper.Testing:
Production:
0 2 * * * php artisan db:dump).Maintenance:
How can I help you explore Laravel packages today?