spatie/db-dumper
PHP database dump utility supporting MySQL, MariaDB, PostgreSQL, SQLite, and MongoDB. Wraps native tools (mysqldump, mariadb-dump, pg_dump, sqlite3, mongodump) with a simple fluent API to export databases to SQL or gz files.
Pros:
setDbName(), includeTables(), skipAutoIncrement()) align well with Laravel’s expressive syntax.GzipCompressor/Bzip2Compressor reduces storage/transfer overhead, critical for large databases.excludeTablesData(), doNotCreateTables(), and addExtraOption() enable granular backup customization (e.g., excluding logs, preserving routines)..env credentials (via setDatabaseUrl()) or direct configuration, fitting Laravel’s dotenv-first approach.useAppendMode() allows incremental dumps, useful for partial backups (e.g., migrations-only).Cons:
mysqldump, pg_dump, etc.), introducing OS-specific constraints (e.g., Docker/CI environments must pre-install these).Artisan command or ServiceProvider hooks out of the box).mongodump (binary) instead of PHP drivers, which may complicate MongoDB-specific workflows (e.g., sharded clusters).DB facade or .env configurations.Artisan command (e.g., php artisan db:dump) for CLI integration.database.backup events (via Laravel’s event system) for automated workflows.storage/app/dumps/ or cloud storage (e.g., S3) via Laravel’s Filesystem contracts.mysqldump scripts with the package’s PHP API (e.g., in app/Console/Kernel.php).Artisan commands or Laravel tasks (e.g., php artisan db:dump --tables=users,posts).Log facade) or CI/CD pipelines (e.g., trigger on git push).mysqldump paths (e.g., /usr/local/mysql/bin/mysqldump) may break in shared hosting or containerized environments. Mitigation: Validate paths in config or use Laravel’s exec() with error handling.env() or config() with encryption (e.g., laravel/env package).mongodump directly for advanced use cases.gzip) differ between dev/prod. Mitigation: Containerize dependencies (e.g., Docker with mysqldump pre-installed).AUTO_INCREMENT may cause ID gaps in restored data. Mitigation: Document this in runbooks.doNotDumpData()/useAppendMode().)includeRoutines().)mysqldump, gzip) guaranteed to be available in all environments? If not, how will you handle missing binaries?env() or vaults like HashiCorp Vault.)Encrypter.)mysqldump crashes) be logged/alerted? (Integrate with Laravel’s Log or third-party tools like Sentry.)php artisan migrate:fresh --with-data)?php artisan db:dump --compress --tables="users,posts").database.backup events for post-dump actions (e.g., notifications, uploads to S3).storage/app/dumps/ or cloud storage via Laravel’s Filesystem contracts.schedule() to run dumps nightly (e.g., Schedule::command('db:dump')->daily()).laravel-backup or spatie/laravel-medialibrary for asset/database backups.main branch pushes).mysqldump cron jobs) for gaps (e.g., no compression, hardcoded paths).app/Console/Commands/DumpDatabase.php).AUTO_INCREMENT conflicts, excluded tables).GzipCompressor).ZipCompressor for S3 compatibility).php artisan db:restore).| Component | Compatibility | Notes |
|---|---|---|
| Laravel Version | 8.x–11.x (PHP 8.0+) | Tested via Spatie’s CI. |
| Databases | MySQL, PostgreSQL, SQLite, MariaDB, MongoDB | MongoDB uses mongodump (binary dependency). |
| PHP Extensions | None (uses system binaries) | Ensure exec() is enabled in php.ini. |
| System Tools | mysqldump, pg_dump, sqlite3, mongodump, gzip, bzip2 |
Must be installed and in PATH. |
| Storage | Local filesystem, S3, FTP (via Laravel Filesystem) | Use Storage::disk('s3')->put(). |
| Artisan | Custom commands | Example: php artisan db:dump --host=prod-db.example.com. |
| Events | database.backup (custom) |
Dispatch after dump completes. |
apt-get install mysqldump gzip).How can I help you explore Laravel packages today?