Weave Code
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

Db Dumper Laravel Package

spatie/db-dumper

PHP library to create database dumps via native CLI tools. Supports MySQL, MariaDB, PostgreSQL, SQLite, and MongoDB, wrapping mysqldump/mariadb-dump/pg_dump/sqlite3/mongodump with a simple fluent API.

View on GitHub
Deep Wiki
Context7

spatie/db-dumper is a PHP utility for creating database dumps through a fluent API. It supports MySQL, MariaDB, PostgreSQL, SQLite, and MongoDB, and delegates the heavy lifting to native CLI tools like mysqldump, mariadb-dump, pg_dump, sqlite3, and mongodump for reliable exports.

Use it to configure credentials and options in code and write dumps directly to a file (e.g. .sql or compressed archives) with minimal setup.

  • Fluent builder API per database driver
  • Supports 5 popular databases (SQL + MongoDB)
  • Dumps to a specified file path (SQL or gz)
  • Leverages proven native dump binaries under the hood
  • Simple integration in scripts, jobs, or maintenance tooling
Frequently asked questions about Db Dumper
How do I install spatie/db-dumper in a Laravel project?
Run `composer require spatie/db-dumper` in your project directory. The package integrates seamlessly with Laravel’s service container and supports configuration via `.env` or `config/database.php`. No additional Laravel-specific setup is required beyond Composer installation.
Can I use this package to create compressed database dumps (e.g., `.sql.gz`)?
Yes, the package supports compressed dumps out of the box. For example, use `->dumpToFile('dump.sql.gz')` to generate a compressed SQL file. You can also customize compression settings via the fluent API for specific use cases.
Does spatie/db-dumper work with Laravel’s `.env` configuration for database credentials?
Yes, you can use Laravel’s `.env` variables directly by passing the `DB_DATABASE`, `DB_USERNAME`, and `DB_PASSWORD` values to the builder methods (e.g., `setDbName(env('DB_DATABASE'))`). Alternatively, use `setDatabaseUrl()` for a cleaner approach, which parses Laravel’s `database.php` configuration.
What Laravel versions does spatie/db-dumper support?
The package is compatible with Laravel 8.x, 9.x, and 10.x. It follows Laravel’s semantic versioning and requires PHP 8.0+. Check the [GitHub repository](https://github.com/spatie/db-dumper) for the latest compatibility details, as minor updates may align with newer Laravel releases.
How can I exclude specific tables or data from a dump in Laravel?
Use the fluent methods `excludeTables()` to skip entire tables or `excludeTablesData()` to exclude only data while keeping schema. For example: `MySql::create()->excludeTables(['temp_data'])->dumpToFile('dump.sql')`. This is useful for partial backups or selective migrations.
Is spatie/db-dumper safe to use in production? What about security risks?
The package is production-ready and mitigates risks by abstracting CLI tool execution. However, ensure credentials are never hardcoded; always use Laravel’s `.env` or `setDatabaseUrl()`. Avoid command injection by validating inputs and using the package’s built-in methods for binary execution.
Can I integrate spatie/db-dumper into Laravel Artisan commands or queue jobs?
Absolutely. Wrap the dumper in an Artisan command (e.g., `php artisan db:dump`) or dispatch it as a Laravel queue job for large databases. Example: `DumpDatabaseJob::dispatch()->onQueue('backups')`. This is ideal for automated backups or CI/CD pipelines.
Does the package support MongoDB dumps, and how does it handle sharded clusters?
Yes, MongoDB is supported via `mongodump`. For sharded clusters, use MongoDB’s native `--oplog` or `--query` flags by extending the builder or passing custom options. Note that production environments may require additional tuning (e.g., oplog size) for consistency.
How do I test database dumps in Laravel’s testing environment?
Use the package to create dumps in your `testing` environment (e.g., `php artisan db:dump --env=testing`) and restore them in test suites. Combine with Laravel’s `RefreshDatabase` trait to reset the database state before each test, ensuring reproducible test environments.
Are there alternatives to spatie/db-dumper for Laravel database backups?
Yes, alternatives include Laravel Backup (by Spatie), which offers more features like cloud storage integration, or native CLI tools like `mysqldump` with custom scripts. However, `spatie/db-dumper` stands out for its Laravel-native fluent API, multi-database support, and seamless integration with Laravel’s configuration system.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport