- How do I install spatie/laravel-db-snapshots in a Laravel project?
- Run `composer require spatie/laravel-db-snapshots` in your project root. The package auto-discovers Laravel and publishes no config files by default. Verify with `php artisan snapshot:list` to confirm it’s ready.
- Can I create snapshots for specific tables instead of the entire database?
- Yes. Use the `--table` flag to include only specific tables (e.g., `snapshot:create my-snapshot --table=users,orders`) or `--exclude` to omit tables. This reduces snapshot size and speeds up operations for large databases.
- Does this package support Laravel 10 and newer versions?
- Yes, the package is fully compatible with Laravel 10+ and PHP 8.1+. Check the [GitHub releases](https://github.com/spatie/laravel-db-snapshots/releases) for version-specific notes, but it follows Laravel’s semantic versioning and requires no manual adjustments.
- How do I load the latest snapshot automatically in CI/CD pipelines?
- Use `php artisan snapshot:load --latest` in your CI script. Combine it with `--force` to overwrite existing data. For safety, wrap it in a transaction or add a pre-load event listener to validate the snapshot before applying.
- Will snapshots work with multi-tenant databases or shared schemas?
- For multi-tenant setups, use the `--connection` flag to target specific database connections (e.g., `snapshot:create tenant1_backup --connection=tenant1`). Custom event listeners can also filter data per tenant during dump/load operations.
- Can I store snapshots in cloud storage like S3 instead of local disk?
- Yes. Configure the `default` filesystem in `config/filesystems.php` to point to S3 (e.g., `disk: 's3'`). The package uses Laravel’s filesystem, so ensure your S3 bucket has proper permissions and encryption (e.g., server-side or client-side via Laravel Encryption).
- How do I handle large databases that cause timeouts during snapshot:load?
- Use the `--stream` flag to process the dump in chunks, reducing memory usage. For very large databases, consider partial snapshots (e.g., `--table=users`) or split the load into smaller transactions. Monitor performance with `--verbose` to identify bottlenecks.
- Are there alternatives to spatie/laravel-db-snapshots for Laravel?
- Yes. For simpler needs, Laravel’s built-in `db:dump` and `db:seed` commands work, but lack snapshot management. For advanced use cases, consider `laravel-backup` (supports more DBMS) or `orchestra/database` (schema-aware snapshots). However, this package is optimized for Laravel’s Artisan ecosystem and event-driven extensibility.
- How do I clean up old snapshots programmatically or via cron?
- Use `php artisan snapshot:cleanup --keep=5` to retain only the 5 most recent snapshots. For automation, add it to your cron (e.g., `0 3 * * * cd /path/to/project && php artisan snapshot:cleanup --keep=7`). You can also trigger it via a custom command or event listener.
- Can I encrypt snapshots before storing them in cloud storage?
- Yes. Enable S3 server-side encryption in your `config/filesystems.php` (e.g., `'encryption' => 'true'`). For additional security, use Laravel’s encryption services in a custom event listener during snapshot creation to encrypt the dump file before saving it to disk or S3.