{"id":13828254,"url":"https://github.com/spatie/laravel-db-snapshots","last_synced_at":"2026-01-29T00:14:55.406Z","repository":{"id":38955404,"uuid":"85295298","full_name":"spatie/laravel-db-snapshots","owner":"spatie","description":"Quickly dump and load databases","archived":false,"fork":false,"pushed_at":"2025-02-21T13:06:23.000Z","size":255,"stargazers_count":1106,"open_issues_count":1,"forks_count":99,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-25T15:48:42.208Z","etag":null,"topics":["artisan","database","dump","mysql","postgresql","restore"],"latest_commit_sha":null,"homepage":"https://freek.dev/716-a-laravel-package-to-quickly-dump-and-load-the-database","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie","custom":"https://spatie.be/open-source/support-us"}},"created_at":"2017-03-17T09:39:15.000Z","updated_at":"2025-04-24T23:21:19.000Z","dependencies_parsed_at":"2023-10-11T22:34:34.270Z","dependency_job_id":"4e71a464-6634-4c6c-b3da-344161dd6169","html_url":"https://github.com/spatie/laravel-db-snapshots","commit_stats":{"total_commits":297,"total_committers":49,"mean_commits":6.061224489795919,"dds":0.5622895622895623,"last_synced_commit":"dcb5abde4f4d5d9123be193b31191ddab2f50d71"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-db-snapshots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-db-snapshots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-db-snapshots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-db-snapshots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-db-snapshots/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000854,"owners_count":21997442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artisan","database","dump","mysql","postgresql","restore"],"created_at":"2024-08-04T09:02:38.599Z","updated_at":"2026-01-29T00:14:55.377Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie","https://spatie.be/open-source/support-us"],"categories":["PHP"],"sub_categories":[],"readme":"# Quickly dump and load databases\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-db-snapshots.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-db-snapshots)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![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)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-db-snapshots.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-db-snapshots)\n\nThis package provides Artisan commands to quickly dump and load databases in a Laravel application.\n\n```bash\n# Create a dump\nphp artisan snapshot:create my-first-dump\n\n# Make some changes to your db\n# ...\n\n# Create another dump\nphp artisan snapshot:create my-second-dump\n\n# Load up the first dump\nphp artisan snapshot:load my-first-dump\n\n# Load up the latest dump\nphp artisan snapshot:load --latest\n\n# List all snapshots\nphp artisan snapshot:list\n\n# Remove old snapshots. Keeping only the most recent\nphp artisan snapshot:cleanup --keep=2\n```\n\nThis package supports MySQL, PostgreSQL and SQLite.\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-db-snapshots.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-db-snapshots)\n\nWe 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).\n\nWe 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).\n\n## Support us\n\nWe 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).\n\nWe 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).\n\n## Installation\n\n\u003e For PHP 7.x and/or Laravel 6.x, use v1.x of this package.\n\nYou can install the package via Composer:\n\n```bash\ncomposer require spatie/laravel-db-snapshots\n```\n\nYou should add a disk named `snapshots` to `config/filesystems.php` on which the snapshots will be saved. This would be a typical configuration:\n\n```php\n// ...\n'disks' =\u003e [\n    // ...\n    'snapshots' =\u003e [\n        'driver' =\u003e 'local',\n        'root' =\u003e database_path('snapshots'),\n    ],\n// ...\n```\n\nOptionally, you may publish the configuration file with:\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\DbSnapshots\\DbSnapshotsServiceProvider\"\n```\n\nThis is the content of the published file:\n\n```php\nreturn [\n\n    /*\n     * The name of the disk on which the snapshots are stored.\n     */\n    'disk' =\u003e 'snapshots',\n\n    /*\n     * The connection to be used to create snapshots. Set this to null\n     * to use the default configured in `config/databases.php`\n     */\n    'default_connection' =\u003e null,\n\n    /*\n     * The directory where temporary files will be stored.\n     */\n    'temporary_directory_path' =\u003e storage_path('app/laravel-db-snapshots/temp'),\n\n    /*\n     * Create dump files that are gzipped\n     */\n    'compress' =\u003e false,\n\n    /*\n     * Only these tables will be included in the snapshot. Set to `null` to include all tables.\n     *\n     * Default: `null`\n     */\n    'tables' =\u003e null,\n\n    /*\n     * All tables will be included in the snapshot expect this tables. Set to `null` to include all tables.\n     *\n     * Default: `null`\n     */\n    'exclude' =\u003e null,\n];\n\n```\n\n## Usage\n\nTo create a snapshot (which is just a dump from the database) run:\n\n```bash\nphp artisan snapshot:create my-first-dump\n```\n\nGiving your snapshot a name is optional. If you don't pass a name the current date time will be used:\n\n```bash\n# Creates a snapshot named something like `2017-03-17 14:31`\nphp artisan snapshot:create\n```\n\nIf you pass a connection but do not declare a name for the snapshot, the connection will be prepended\n\n```bash\n# Creates a snapshot named something like `logging_2017-03-17 14:31`\nphp artisan snapshot:create --connection=logging\n```\n\nMaybe 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:\n\n```bash\n# Both commands create a snapshot containing only the posts and users tables:\nphp artisan snapshot:create --table=posts,users\nphp artisan snapshot:create --table=posts --table=users\n```\n\nYou may want to exclude some tables from snapshot. You can do this by passing the `--exclude` multiple times or as a comma separated list:\n```bash\n# create snapshot from all tables excluding the users and posts\nphp artisan snapshot:create --exclude=posts,users\nphp artisan snapshot:create --exclude=posts --exclude=users\n```\n\u003e 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`\n\nWhen 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`:\n\n```bash\n# Creates a snapshot named my-compressed-dump.sql.gz\nphp artisan snapshot:create my-compressed-dump --compress\n```\n\nAfter you've made some changes to the database you can create another snapshot:\n\n```bash\nphp artisan snapshot:create my-second-dump\n```\n\nTo load a previous dump issue this command:\n\n```bash\nphp artisan snapshot:load my-first-dump\n```\n\nTo load a previous dump to another DB connection:\n\n```bash\nphp artisan snapshot:load my-first-dump --connection=connectionName\n```\n\nBy 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:\n\n```bash\nphp artisan snapshot:load my-first-dump --drop-tables=0\n```\n\nBy 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:\n\n```bash\nphp artisan snapshot:load my-first-dump --stream\n```\n\nTo list all the dumps run:\n\n```bash\nphp artisan snapshot:list\n```\n\nA dump can be deleted with:\n\n```bash\nphp artisan snapshot:delete my-first-dump\n```\n\nTo remove all backups except the most recent 2\n\n```bash\nphp artisan snapshot:cleanup --keep=2\n```\n\nIf 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:\n```\n'dump' =\u003e [\n    'addExtraOption' =\u003e '--no-owner',\n],\n```\nTo the `pgsql` connection in `database.php`\n\n## Events\n\nThere are several events fired which can be used to perform some logic of your own:\n\n- `Spatie\\DbSnapshots\\Events\\CreatingSnapshot`: will be fired before a snapshot is created\n- `Spatie\\DbSnapshots\\Events\\CreatedSnapshot`: will be fired after a snapshot has been created\n- `Spatie\\DbSnapshots\\Events\\LoadingSnapshot`: will be fired before a snapshot is loaded\n- `Spatie\\DbSnapshots\\Events\\LoadedSnapshot`: will be fired after a snapshot has been loaded\n- `Spatie\\DbSnapshots\\Events\\DeletingSnapshot`: will be fired before a snapshot is deleted\n- `Spatie\\DbSnapshots\\Events\\DeletedSnapshot`: will be fired after a snapshot has been deleted\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-db-snapshots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-db-snapshots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-db-snapshots/lists"}