Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Db Snapshots

Laravel Db Snapshots Laravel Package

spatie/laravel-db-snapshots

Spatie's Laravel package adding Artisan commands to instantly dump and load MySQL, PostgreSQL, or SQLite databases. Create named snapshots, load the latest, list, and clean up old dumps in seconds.

View on GitHub
Deep Wiki
Context7

spatie/laravel-db-snapshots gives Laravel applications a fast, no-nonsense way to dump and load databases using simple Artisan commands—perfect for local development, testing, or before risky migrations. Create named snapshots, roll back to any of them, or grab the latest in a single command.

Supporting MySQL, PostgreSQL, and SQLite, it handles snapshot storage and retrieval so you don't have to write raw mysqldump or pg_dump scripts.

  • snapshot:create to dump your database with a custom name
  • snapshot:load to restore a named or --latest snapshot
  • snapshot:list to see all available snapshots
  • snapshot:cleanup --keep=N to prune older dumps
  • Works with MySQL, PostgreSQL, and SQLite out of the box
Frequently asked questions about Laravel Db Snapshots
How do I install spatie/laravel-db-snapshots in a Laravel app?
Install it with Composer using composer require spatie/laravel-db-snapshots. Laravel will auto-discover the service provider, so no manual registration is needed on Laravel 8 and above. Publishing the config file is optional and only necessary if you want to change the snapshot disk, dump paths, or other defaults. After that, add a dedicated disk in config/filesystems.php where the snapshot files should live.
Which Laravel and PHP versions does spatie/laravel-db-snapshots support?
Version 2.x requires PHP 8 or higher and supports Laravel 8 through 13, including the current Laravel 12 and 13 releases. If you are still on PHP 7 or Laravel 6 you would need the legacy 1.x line. The package is actively maintained alongside spatie/db-dumper v4, so recent Laravel releases are supported close to their launch.
Which databases can laravel-db-snapshots dump and load?
The package supports MySQL, PostgreSQL, and SQLite only. Dumps are produced by shelling out to the native client tools for each engine, so the engine you use must be one of those three. There is no SQL Server or MongoDB support, so any of those stores in your stack need a different backup approach.
Does snapshot:load delete my existing tables?
Yes, by default snapshot:load drops the existing tables in the target database before importing the dump, which makes it a destructive command. You can pass --drop-tables=0 to avoid the drop step, but the import still overwrites existing data. Because of this, never expose the command to production without an environment guard, a wrapper command, or an access policy that limits who can run it.
Why do I get mysqldump, pg_dump, or sqlite3 command not found errors?
The package does not include database clients itself; it requires mysqldump, pg_dump and psql, or sqlite3 to be installed on the machine or container running the Artisan command. Slim PHP Docker images and minimal CI runners routinely omit these binaries, which is the most common first failure. Install the matching client package in your image and check that its version is compatible with your database server before committing to the tool.
How do I load the latest snapshot or delete old ones?
Run php artisan snapshot:load --latest to restore the most recently created dump without typing its name. Use php artisan snapshot:list to see what is available, and php artisan snapshot:delete <name> to remove a single snapshot. For bulk retention, snapshot:cleanup --keep=N keeps only the N most recent snapshots and deletes the rest, though it is a blunt primitive with no age-based or size-based rules.
Where are snapshot files stored, and can I put them on S3?
Snapshots are written as plain files to any Laravel filesystem disk you configure, so you can use the local disk in development and S3 or another remote disk for shared or team environments. The path and disk are configurable in the package config file, and per-run options like --compress keep individual files smaller. Remember that dumps are unencrypted by default and contain full table data, including any PII, so bucket permissions, retention, and off-host durability are your responsibility.
Is spatie/laravel-db-snapshots suitable for production backups or disaster recovery?
No. It is a developer and ops convenience tool for fast local or staging database resets, not a backup or DR solution. It offers no point-in-time recovery, no incremental backups, no encryption, no verification, and only a keep-N cleanup rule. For production protection use a purpose-built tool such as spatie/laravel-backup or your database provider's managed snapshot and PITR features.
Can laravel-db-snapshots handle a large database?
By default the load reads the entire dump into memory, which will fail on big databases; pass --stream to feed the dump to the client incrementally and reduce memory pressure. Streaming does not reduce duration, though, and restore time scales roughly linearly with database size with no progress indicator or resume support. There is also no locking, so two loads against the same database at once can corrupt it — schedule restores so they never overlap.
How do I run code before or after a snapshot is created or loaded?
The package fires lifecycle events for creating and created, loading and loaded, and deleting and deleted snapshots. You can listen for these in an event listener or service provider to add audit logging, Slack notifications, or replication of the dump to another storage location. That gives you a clean extension point without forking the package or wrapping every Artisan call in custom code.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
marcelgwerder/laravel-api-handler
firebrikdotcom/conveyor-laravel-broadcaster
kanata-php/conveyor-laravel-broadcaster
alish/short-message
sonrac/lumen-league-oauth2
pushery/sanctum-hardening-for-laravel
evanschleret/laravel-uuidable
yigit-serin/laravel-openvidu
adachsoft/command-executor-lib
tagixo/document-builder
tagixo/page-builder
tagixo/mail-builder
tagixo/form-builder
primix/primix
tagixo/core
alesima/laravel-azure-service-bus
tomshaw/shopcart
likyly/laravel
darthsoup/shoppingcart
tdt/core