- How do I integrate spatie/db-dumper into a Laravel project to replace manual mysqldump commands?
- Use Laravel’s `.env` configuration with `setDatabaseUrl()` or individual setters (e.g., `setDbName()`, `setUserName()`) in a Service Provider. For example, inject it via the container and chain methods like `excludeTables()` or `dumpToFile()`. Wrap it in an Artisan command (e.g., `php artisan db:dump`) for CLI access.
- Does spatie/db-dumper support Laravel’s Eloquent model-based filtering (e.g., exclude soft-deleted records)?
- No, it works with raw table names (e.g., `excludeTables(['users'])`). To filter Eloquent models, manually query the tables (e.g., `whereNull('deleted_at')`) before dumping or use a custom script to preprocess data. Pair with Laravel’s query builder for dynamic exclusions.
- What Laravel versions are compatible with spatie/db-dumper, and are there breaking changes?
- The package supports Laravel 8.x–10.x (check Packagist for exact versions). Breaking changes are rare but documented in the changelog. For Laravel 11+, verify compatibility with the latest release, as newer Laravel versions may alter `.env` or connection handling.
- How can I ensure spatie/db-dumper works in CI/CD or Docker environments where mysqldump/pg_dump might be missing?
- Add the required binaries to your Dockerfile (e.g., `RUN apt-get install -y mysql-client postgresql-client`) or CI setup (e.g., GitHub Actions with `before_script: apt-get install -y mysqldump`). Test the dump process in a pre-deployment job to catch missing dependencies early.
- Can I compress dumps (e.g., gzip) or customize the output format (e.g., schema-only) with spatie/db-dumper?
- Yes, use the `GzipCompressor` for compression (e.g., `->compressWith(GzipCompressor::class)`) or pass native flags like `--no-data` (MySQL) or `--schema-only` (PostgreSQL) via `setDumpOptions()`. For MongoDB, `.gz` is default. Check the README for database-specific options.
- Is spatie/db-dumper suitable for large databases (e.g., 100GB+), or will it cause timeouts/memory issues?
- For large databases, use native flags like `--quick` (MySQL) or `--single-transaction` (PostgreSQL) to optimize performance. Stream dumps to disk incrementally (e.g., `->dumpToFile()` with chunked writes) and avoid loading entire dumps into memory. Test with a subset of tables first.
- How do I restore a dump created with spatie/db-dumper in Laravel, and can I automate post-restore tasks (e.g., cache warming)?
- Restore using native tools (e.g., `mysql dump.sql < production.sql`) or Laravel’s `Artisan::call()` for automation. For post-restore tasks, chain a Laravel job (e.g., `php artisan db:restore && php artisan cache:warm`) or use a custom script triggered via `post-restore` hooks in your deployment pipeline.
- What alternatives exist to spatie/db-dumper for Laravel database backups, and when should I choose them?
- For advanced features (e.g., cloud storage, encryption), use `spatie/laravel-backup`. For MongoDB sharded clusters, consider `mongodump` directly or `mongorestore`. If you need transactional consistency, combine this package with Laravel’s database transactions or use `pg_dump --format=custom` for PostgreSQL.
- Can I schedule regular database dumps with spatie/db-dumper in Laravel, and how do I handle dump rotation?
- Yes, schedule dumps using Laravel’s `schedule` facade (e.g., `Schedule::command('db:dump')->daily()`). For rotation, store dumps in Laravel’s `Storage` facade (e.g., `Storage::disk('backups')`) and implement cleanup logic (e.g., delete files older than 7 days) via a scheduled job or `Storage::delete()`.
- Does spatie/db-dumper support MongoDB sharded clusters or oplog-based backups, and what are the limitations?
- No, it uses `mongodump`, which doesn’t support sharded clusters or oplog-based backups (e.g., continuous backups). For these use cases, use MongoDB’s native tools (`mongodump --oplog`) or a dedicated backup solution like `mongobackup`. Validate your MongoDB deployment type before using this package.