Download the PHP package smwks/laravel-db-snapshots without Composer
On this page you can find all versions of the php package smwks/laravel-db-snapshots. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smwks/laravel-db-snapshots
More information about smwks/laravel-db-snapshots
Files in smwks/laravel-db-snapshots
Package laravel-db-snapshots
Short Description DB snapshots for Laravel using native CLI tools
License MIT
Homepage https://github.com/smwks/laravel-db-snapshots
Informations about the package laravel-db-snapshots
Laravel DB Snapshots
Database snapshots for Laravel using native CLI tools (mysqldump, pg_dump, gzip, etc.). Create compressed snapshots of your production database, store them on any Laravel filesystem disk, and load them into your local environment with a single command.
Supports MySQL/MariaDB and PostgreSQL with automatic driver detection from your Laravel database config.
Installation
Publish the config file:
This creates config/db-snapshots.php.
How It Works
The package revolves around plans -- named snapshot configurations. A plan defines which database connection to use, how to name the files, which tables to include or exclude, and where to store the results.
The typical workflow:
- Production:
db-snapshots:createrunsmysqldump(orpg_dump), compresses the output withgzip, and uploads it to your archive disk (e.g. S3). - Local:
db-snapshots:loaddownloads the latest snapshot, drops your local tables, and pipes the dump throughzcatintomysql(orpsql).
Configuration
Filesystem
Snapshots are stored on a Laravel filesystem disk. The archive disk is where snapshots are permanently stored (typically a cloud disk like S3). The local disk is used for temporary caching during downloads.
Plans
Each plan defines a snapshot configuration:
File Templates
The file_template controls snapshot file naming. It must contain a {date:FORMAT} placeholder using PHP date format characters:
| Template | Example Filename |
|---|---|
db-snapshot-daily-{date:Ymd} |
db-snapshot-daily-20250209.sql.gz |
db-snapshot-hourly-{date:YmdH} |
db-snapshot-hourly-2025020914.sql.gz |
db-snapshot-{date:Ymd-His} |
db-snapshot-20250209-143022.sql.gz |
Table Selection
You have three ways to control which tables are included:
- All tables (default): Leave
tablesandignore_tablesempty. - Specific tables only: List them in
tables. Only these tables will be dumped. - Exclude specific tables: List them in
ignore_tables. Everything except these will be dumped.
tables and ignore_tables cannot both be set on the same plan.
schema_only_tables dumps the table structure without data -- useful for large tables like failed_jobs where you need the schema but not the rows. When using tables, any schema_only_tables must also appear in the tables list.
Dump Options
The dump_options string is passed directly to the dump utility. Common values:
Environment Locks
Environment locks prevent accidental operations. With the default config, snapshots can only be created in production and only loaded in local. Set either to null to allow the operation in any environment.
Plan Groups
Plan groups let you batch multiple plans together. This is useful when your application uses multiple databases:
Plan groups work with db-snapshots:create and db-snapshots:load -- pass the group name instead of a plan name.
Caching
When loading snapshots, the file is downloaded to the local disk, loaded into the database, then deleted. You can keep local copies to speed up repeated loads:
Or use the --cached / --recached flags on the load command (see below).
Utilities
The package needs CLI tools available on the system. Configure custom paths if they're not in your $PATH:
Post-Load SQL Commands
SQL commands can be configured at three levels, and they run in this order:
- Global (
post_load_sqlsat the config root) -- runs after every snapshot load - Plan-level (
post_load_sqlsinside a plan) -- runs after that specific plan loads - Plan group-level (
post_load_sqlsinside a plan group) -- runs after all plans in the group have loaded
Commands
db-snapshots:create
Create a snapshot.
db-snapshots:load
Download and load a snapshot into your local database. By default this drops all tables before loading.
Use -v for verbose output to see the exact commands being run.
db-snapshots:list
List available snapshots, cached files, and plan groups.
db-snapshots:delete
Delete a snapshot from the archive.
db-snapshots:clear-cache
Remove locally cached snapshot files.
Database Driver Support
The database driver is auto-detected from your Laravel connection config (database.connections.{name}.driver). No manual configuration is needed.
| Driver | Dump Tool | Load Tool | Credentials |
|---|---|---|---|
| MySQL / MariaDB | mysqldump |
mysql |
Temporary .my.cnf file with --defaults-extra-file |
| PostgreSQL | pg_dump |
psql |
Temporary pgpass file via PGPASSFILE |
Compression (gzip / zcat) is handled the same way for all drivers.
Requirements
- PHP 8.4+
- Laravel 11+ (via Orchestra Testbench 10)
- The appropriate CLI tools installed on your system (
mysqldump/mysqlfor MySQL,pg_dump/psqlfor PostgreSQL,gzip/zcatfor compression)
Testing
License
The MIT License (MIT). Please see License File for more information.