Skip to content

Database Snapshots

Database snapshots allow you to save the current state of your database and quickly restore it later. This is invaluable during development when you need to:

  • Test data modifications and quickly reset to a known state
  • Quickly switch between different test scenarios
  • Preserve data before making potentially destructive changes

Create a snapshot with a descriptive name:

Terminal window
php artisan db:snapshot:create my-snapshot-name

The snapshot will be saved to the database/snapshots/ directory.

Terminal window
# Rebuild database with fresh data
php artisan db:rebuild
# Create some test data through the UI
# Save this state
php artisan db:snapshot:create clean-test-data
# Now you can make changes, and restore whenever needed
php artisan db:snapshot:restore clean-test-data

View all available snapshots:

Terminal window
php artisan db:snapshot:list

Restore a snapshot by name:

Terminal window
php artisan db:snapshot:restore my-snapshot-name

Create an automatic backup before restoring:

Terminal window
php artisan db:snapshot:restore my-snapshot-name --backup

Get detailed information about a specific snapshot:

Terminal window
php artisan db:snapshot:info my-snapshot-name

This displays:

  • File path and size
  • Creation timestamp
  • Schema checksum and migration/seeder counts
  • Comparison with current codebase schema

Delete a single snapshot:

Terminal window
php artisan db:snapshot:delete my-snapshot-name

Delete all snapshots:

Terminal window
php artisan db:snapshot:delete --all

Both the SQL file and any associated metadata will be removed.