- How do I install Spatie DB Dumper in a Laravel project?
- Run `composer require spatie/db-dumper` in your project directory. The package supports Laravel 8+ and requires PHP 8.0+. No additional configuration is needed unless you want to bind it to the service container.
- Can I dump a MySQL database directly from Laravel without CLI tools?
- No, Spatie DB Dumper relies on system tools like `mysqldump`. If these aren’t available (e.g., in Docker or CI/CD), you’ll need to install them manually or use a PDO-based fallback, though performance may degrade.
- Does this package support automated database backups via Laravel Scheduler?
- Yes, you can schedule dumps using Laravel’s scheduler. Register the `db:dump` Artisan command in your `app/Console/Kernel.php` and call it with `$schedule->command('db:dump')->daily()`.
- How do I customize the output path or filename for database dumps?
- Use the fluent API to specify the path. For example, `MySql::create()->dumpToFile(storage_path('app/dumps/backup_' . now()->format('Y-m-d') . '.sql'))` writes to a custom location.
- Is there a way to compress MongoDB dumps automatically?
- Yes, MongoDB dumps default to `.gz` format. For other databases, append `.gz` to the filename or use `->compress()` if supported (though this may require custom logic).
- Will this work in a multi-tenant Laravel app (e.g., Stancl/Tenant)?
- No, the package doesn’t natively support multi-tenancy. You’ll need to loop through tenants manually or extend the dumper to filter by tenant ID, then merge results.
- Are credentials stored securely in production?
- Credentials are passed as plaintext unless you use Laravel’s `.env` or encryption. Always avoid hardcoding sensitive data; rely on Laravel’s configuration system or environment variables.
- Can I dump multiple databases at once with this package?
- Not natively. You’d need to chain multiple dumper instances or write a custom wrapper to iterate over databases defined in `config/database.php`.
- How do I handle large databases that exceed memory limits?
- For large databases, use chunked dumps or stream output directly to a file. The package doesn’t natively support chunking, but you can extend it or use system tools like `mysqldump --quick`.
- Are there alternatives to Spatie DB Dumper for Laravel?
- Yes, alternatives include Laravel’s built-in `Schema::dump()` (for migrations), `laravel-backup` (for cloud storage), or `doctrine/dbal` for PDO-based dumps. Spatie’s package excels for raw, tool-based exports with a simple API.