spatie/laravel-db-snapshots
Artisan commands to quickly create, load, list, and clean up database snapshots in Laravel. Dump your DB, restore any snapshot (or the latest), and keep only recent dumps. Supports MySQL, PostgreSQL, and SQLite.
CreatingSnapshot, LoadedSnapshot, etc.), enabling custom logic hooks (e.g., notifications, pre/post-processing). This is valuable for auditability or integration with other tools (e.g., Slack alerts, monitoring).--connection) is critical for multi-tenant or microservice architectures.vendor:publish step for config is a best practice for customization.spatie/db-dumper (v4+), which is mature and actively maintained. Compatibility with Laravel 10–13 ensures long-term viability.snapshots), which can be local, S3, or other Laravel-supported storage. This allows for scalable storage (e.g., cloud backups) without code changes.--stream flag for large dumps and compression support optimize performance in CI environments.snapshot:cleanup) could fill disk space. Automated cleanup policies (e.g., TTL-based deletion) should be implemented.failed_jobs table). Exclusion lists or environment-aware configs are needed to avoid accidental data leaks.--stream) mitigates memory issues, but complex transactions (e.g., triggers, stored procedures) may still cause problems. Testing with production-like data is critical.--no-owner flag). Test with target databases early.config/db-snapshots.php:
disk to a dedicated storage location (e.g., s3 for durability).compress (recommended for large dumps).tables/exclude to optimize snapshot scope.'disk' => 's3',
'compress' => true,
'tables' => ['users', 'orders'], // Only snapshot critical tables
- name: Create pre-deploy snapshot
run: php artisan snapshot:create pre-deploy-$(date +%s)
// app/Providers/EventServiceProvider.php
protected $listen = [
\Spatie\DbSnapshots\Events\LoadedSnapshot::class => [
\App\Listeners\SnapshotLoadedListener::class,
],
];
snapshot:cleanup --keep=5).production-2023-10-01 snapshot").spatie/db-dumper compatibility.config/db-snapshots.php) reduces drift risk, but environment-specific overrides (e.g., .env) may be needed.spatie/db-dumper for breaking changes. Laravel’s auto-updates may require manualHow can I help you explore Laravel packages today?