PHPackages                             spatie/laravel-db-snapshots - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. spatie/laravel-db-snapshots

ActiveLibrary[Database &amp; ORM](/categories/database)

spatie/laravel-db-snapshots
===========================

Quickly dump and load databases

2.9.0(2mo ago)1.2k2.8M—2.4%10114MITPHPPHP ^8.2CI passing

Since Mar 22Pushed 1mo ago11 watchersCompare

[ Source](https://github.com/spatie/laravel-db-snapshots)[ Packagist](https://packagist.org/packages/spatie/laravel-db-snapshots)[ Docs](https://github.com/spatie/laravel-db-snapshots)[ Fund](https://spatie.be/open-source/support-us)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-laravel-db-snapshots/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (46)Used By (14)

Quickly dump and load databases
===============================

[](#quickly-dump-and-load-databases)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1c1a48648768d7eab21faf6d4657107f40c6320b06851eeda91a22eaf9f933c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d64622d736e617073686f74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-db-snapshots)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![run-tests](https://github.com/spatie/laravel-db-snapshots/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-db-snapshots/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/e22655ae12b960b1a09dd31195ceb4b09dda550e81b0ad16fb9b323b0501fb15/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d64622d736e617073686f74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-db-snapshots)

This package provides Artisan commands to quickly dump and load databases in a Laravel application.

```
# Create a dump
php artisan snapshot:create my-first-dump

# Make some changes to your db
# ...

# Create another dump
php artisan snapshot:create my-second-dump

# Load up the first dump
php artisan snapshot:load my-first-dump

# Load up the latest dump
php artisan snapshot:load --latest

# List all snapshots
php artisan snapshot:list

# Remove old snapshots. Keeping only the most recent
php artisan snapshot:cleanup --keep=2
```

This package supports MySQL, PostgreSQL and SQLite.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/a566a0bd1af11a77b915d30c2cf9d0e88e3f8679a06c704042a197fce1436d7f/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d64622d736e617073686f74732e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-db-snapshots)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Support us
----------

[](#support-us-1)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

> For PHP 7.x and/or Laravel 6.x, use v1.x of this package.

You can install the package via Composer:

```
composer require spatie/laravel-db-snapshots
```

You should add a disk named `snapshots` to `config/filesystems.php` on which the snapshots will be saved. This would be a typical configuration:

```
// ...
'disks' => [
    // ...
    'snapshots' => [
        'driver' => 'local',
        'root' => database_path('snapshots'),
    ],
// ...
```

Optionally, you may publish the configuration file with:

```
php artisan vendor:publish --provider="Spatie\DbSnapshots\DbSnapshotsServiceProvider"
```

This is the content of the published file:

```
return [

    /*
     * The name of the disk on which the snapshots are stored.
     */
    'disk' => 'snapshots',

    /*
     * The connection to be used to create snapshots. Set this to null
     * to use the default configured in `config/databases.php`
     */
    'default_connection' => null,

    /*
     * The directory where temporary files will be stored.
     */
    'temporary_directory_path' => storage_path('app/laravel-db-snapshots/temp'),

    /*
     * Create dump files that are gzipped
     */
    'compress' => false,

    /*
     * Only these tables will be included in the snapshot. Set to `null` to include all tables.
     *
     * Default: `null`
     */
    'tables' => null,

    /*
     * All tables will be included in the snapshot expect this tables. Set to `null` to include all tables.
     *
     * Default: `null`
     */
    'exclude' => null,
];
```

Usage
-----

[](#usage)

To create a snapshot (which is just a dump from the database) run:

```
php artisan snapshot:create my-first-dump
```

Giving your snapshot a name is optional. If you don't pass a name the current date time will be used:

```
# Creates a snapshot named something like `2017-03-17 14:31`
php artisan snapshot:create
```

If you pass a connection but do not declare a name for the snapshot, the connection will be prepended

```
# Creates a snapshot named something like `logging_2017-03-17 14:31`
php artisan snapshot:create --connection=logging
```

Maybe you only want to snapshot a couple of tables. You can do this by passing the `--table` multiple times or as a comma separated list:

```
# Both commands create a snapshot containing only the posts and users tables:
php artisan snapshot:create --table=posts,users
php artisan snapshot:create --table=posts --table=users
```

You may want to exclude some tables from snapshot. You can do this by passing the `--exclude` multiple times or as a comma separated list:

```
# create snapshot from all tables excluding the users and posts
php artisan snapshot:create --exclude=posts,users
php artisan snapshot:create --exclude=posts --exclude=users
```

> Note: if you pass `--table` and `--exclude` in the same time it will use `--table` to create the snapshot and it's ignore the `--exclude`

When creating snapshots, you can optionally create compressed snapshots. To do this either pass the `--compress` option on the command line, or set the `db-snapshots.compress` configuration option to `true`:

```
# Creates a snapshot named my-compressed-dump.sql.gz
php artisan snapshot:create my-compressed-dump --compress
```

After you've made some changes to the database you can create another snapshot:

```
php artisan snapshot:create my-second-dump
```

To load a previous dump issue this command:

```
php artisan snapshot:load my-first-dump
```

To load a previous dump to another DB connection:

```
php artisan snapshot:load my-first-dump --connection=connectionName
```

By default, `snapshot:load` will drop all existing tables in the database. If you don't want this behaviour, you can pass the `--drop-tables=0` option:

```
php artisan snapshot:load my-first-dump --drop-tables=0
```

By default, `snapshot:load` will load the entire snapshot into memory which may cause problems when using large files. To avoid this, you can pass the `--stream` option to stream the snapshot to the database one statement at a time:

```
php artisan snapshot:load my-first-dump --stream
```

To list all the dumps run:

```
php artisan snapshot:list
```

A dump can be deleted with:

```
php artisan snapshot:delete my-first-dump
```

To remove all backups except the most recent 2

```
php artisan snapshot:cleanup --keep=2
```

If you need to pass extra options to the underlying db-dumper, add a `dump` key to the database **connection** with a key of `addExtraOption` and a value of the option. For example, to prevent the Postgres db dumper from setting the owner, you'd add:

```
'dump' => [
    'addExtraOption' => '--no-owner',
],

```

To the `pgsql` connection in `database.php`

Events
------

[](#events)

There are several events fired which can be used to perform some logic of your own:

- `Spatie\DbSnapshots\Events\CreatingSnapshot`: will be fired before a snapshot is created
- `Spatie\DbSnapshots\Events\CreatedSnapshot`: will be fired after a snapshot has been created
- `Spatie\DbSnapshots\Events\LoadingSnapshot`: will be fired before a snapshot is loaded
- `Spatie\DbSnapshots\Events\LoadedSnapshot`: will be fired after a snapshot has been loaded
- `Spatie\DbSnapshots\Events\DeletingSnapshot`: will be fired before a snapshot is deleted
- `Spatie\DbSnapshots\Events\DeletedSnapshot`: will be fired after a snapshot has been deleted

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

75

—

ExcellentBetter than 100% of packages

Maintenance89

Actively maintained with recent releases

Popularity67

Solid adoption and visibility

Community41

Growing community involvement

Maturity88

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 58.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~76 days

Recently: every ~115 days

Total

44

Last Release

63d ago

Major Versions

0.0.2 → 1.0.02017-03-24

1.7.1 → 2.0.02021-04-01

PHP version history (9 changes)0.0.1PHP ^7.1

0.0.2PHP ^7.0

1.3.0PHP ^7.2

1.6.0PHP ^7.3

1.6.1PHP ^7.4

1.7.1PHP ^7.4|^8.0

2.0.0PHP ^8.0

2.7.1PHP ^8.1

2.8.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (207 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (28 commits)")[![alexmanase](https://avatars.githubusercontent.com/u/10696975?v=4)](https://github.com/alexmanase "alexmanase (17 commits)")[![ariaieboy](https://avatars.githubusercontent.com/u/15873972?v=4)](https://github.com/ariaieboy "ariaieboy (10 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (10 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (7 commits)")[![michaeljhopkins](https://avatars.githubusercontent.com/u/4623657?v=4)](https://github.com/michaeljhopkins "michaeljhopkins (7 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (7 commits)")[![tsjason](https://avatars.githubusercontent.com/u/26229182?v=4)](https://github.com/tsjason "tsjason (7 commits)")[![xHeaven](https://avatars.githubusercontent.com/u/14284867?v=4)](https://github.com/xHeaven "xHeaven (6 commits)")[![ralphschindler](https://avatars.githubusercontent.com/u/76674?v=4)](https://github.com/ralphschindler "ralphschindler (6 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (5 commits)")[![jamatheney](https://avatars.githubusercontent.com/u/10274164?v=4)](https://github.com/jamatheney "jamatheney (4 commits)")[![amaelftah](https://avatars.githubusercontent.com/u/17250137?v=4)](https://github.com/amaelftah "amaelftah (3 commits)")[![joaorobertopb](https://avatars.githubusercontent.com/u/6556083?v=4)](https://github.com/joaorobertopb "joaorobertopb (3 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (3 commits)")[![wattnpapa](https://avatars.githubusercontent.com/u/3910878?v=4)](https://github.com/wattnpapa "wattnpapa (3 commits)")[![ssmusoke](https://avatars.githubusercontent.com/u/689900?v=4)](https://github.com/ssmusoke "ssmusoke (3 commits)")[![carlobeltrame](https://avatars.githubusercontent.com/u/7566995?v=4)](https://github.com/carlobeltrame "carlobeltrame (3 commits)")[![lex111](https://avatars.githubusercontent.com/u/4408379?v=4)](https://github.com/lex111 "lex111 (2 commits)")

---

Tags

artisandatabasedumpmysqlpostgresqlrestorespatielaravel-db-snapshots

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-laravel-db-snapshots/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-db-snapshots/health.svg)](https://phpackages.com/packages/spatie-laravel-db-snapshots)
```

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M191](/packages/spatie-laravel-backup)[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k37.7M472](/packages/spatie-laravel-medialibrary)[spatie/laravel-translatable

A trait to make an Eloquent model hold translations

2.4k23.0M413](/packages/spatie-laravel-translatable)[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[spatie/laravel-sluggable

Generate slugs when saving Eloquent models

1.6k11.5M223](/packages/spatie-laravel-sluggable)[spatie/laravel-schemaless-attributes

Add schemaless attributes to Eloquent models

1.1k8.7M62](/packages/spatie-laravel-schemaless-attributes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
