spatie/laravel-db-snapshots
Artisan commands to quickly create, load, list, and clean up database snapshots in Laravel. Dump and restore MySQL, PostgreSQL, and SQLite databases with named or latest snapshots—ideal for local/dev workflows and fast resets.
CreatingSnapshot, LoadedSnapshot, etc.), enabling custom logic hooks (e.g., notifications, pre/post-dump validations, or integration with monitoring tools).snapshot:create --connection=logging).password_resets or sessions).filesystems.php). No ORM or framework-level changes needed.spatie/db-dumper (v4+), which is battle-tested and actively maintained. No breaking changes in recent versions.| Risk Area | Assessment | Mitigation |
|---|---|---|
| Database Locking | Large dumps may block production DBs if run on live systems. | Restrict to non-prod environments (e.g., via .env checks or CI/CD gating). Use --stream for large datasets. |
| Storage Bloat | Unchecked snapshots can consume disk space. | Enforce automated cleanup (e.g., snapshot:cleanup --keep=5 in cron) or integrate with Laravel Housekeeping. |
| Schema Mismatches | Loading a snapshot onto a schema-incompatible DB (e.g., wrong Laravel version) may fail silently or corrupt data. | Validate schema compatibility via custom events or pre-load hooks. Document snapshot metadata (e.g., Laravel version, PHP version). |
| Performance Overhead | Streaming large snapshots (--stream) adds CPU/memory overhead during load. |
Benchmark with real-world dataset sizes. Consider parallel loading for multi-table snapshots (though not natively supported). |
| Multi-Tenant Isolation | Snapshots may leak tenant data if not scoped properly. | Implement tenant-aware naming (e.g., snapshot:create tenant1_2024-01-01) or use connection-specific snapshots. |
| Backup Integrity | Corrupted snapshots (e.g., interrupted dumps) may go unnoticed. | Add checksum validation via custom events or post-load queries (e.g., SELECT COUNT(*) FROM users). |
Use Case Prioritization:
Data Sensitivity:
exclude or custom events) or encryption (e.g., S3 + KMS).Scalability:
--stream for datasets >1GB.Automation:
Monitoring:
LoadedSnapshot event).Rollback Strategy:
Cross-Environment Sync:
/storage/app/snapshots).| Phase | Action | Tools/Commands |
|---|---|---|
| Evaluation | Test with a non-prod DB clone. Validate snapshot/load times, storage usage, and edge cases (e.g., foreign keys, triggers). | snapshot:create --table=users,posts, snapshot:load --stream |
| Pilot | Restrict to one team/department. Use manual triggers first (e.g., snapshot:create pre-migration). |
Artisan CLI, custom scripts |
| Automation | Integrate with CI/CD (e.g., snapshot before phpunit). Add cleanup to deploy scripts. |
GitHub Actions, Laravel Forge hooks |
| Monitoring | Instrument events with Laravel Logging or Sentry. Set up alerts for failed loads. | LoadedSnapshot event listener, Healthchecks.io |
| Optimization | Profile large snapshots with --stream. Exclude non-critical tables (e.g., failed_jobs). |
snapshot:create --exclude=failed_jobs, tideways/xhprof |
PutObject/GetObject.laravel-backup): Can complement snapshots (e.g., use snapshots for dev, backups for prod).filesystems.php for snapshot storage.tables/exclude.snapshot:create initial).feature-x_2024-01-01).migrate).snapshot:cleanup --keep=3 in cron).How can I help you explore Laravel packages today?