- What is spatie/db-dumper and how does it work in a Laravel app?
- spatie/db-dumper is a small framework-agnostic PHP package that builds and runs a database dump command using the native client binaries such as mysqldump, mariadb-dump, pg_dump, sqlite3, or mongodump. You configure it through a fluent API, call dumpToFile, and it writes the dump to a path you choose. In Laravel you typically wrap it in a queued job or a small service class and drive configuration from config/database.php. It does not handle storage, scheduling, retention, encryption, or restore verification, so it is one component in a larger backup pipeline.
- Do I need mysqldump, pg_dump, sqlite3, or mongodump installed on the server?
- Yes. The package is a command builder, so the matching client binary for your database driver must exist on the host running PHP. If you use compression you also need gzip or bzip2 available. This is the main deployment constraint on managed and restricted runtimes such as Heroku, AWS Lambda, distroless containers, and some PaaS images, where those binaries may be missing or impossible to install. Use setDumpBinaryPath if the binary lives in a non-standard location.
- How is spatie/db-dumper different from spatie/laravel-backup?
- spatie/laravel-backup is a full backup product for Laravel that uses spatie/db-dumper internally and adds storage destinations, retention policies, notifications, and restore commands. spatie/db-dumper only produces the dump file, giving you a fluent API with no opinions about where the file goes or what happens next. If your requirement is simply we need database backups, laravel-backup is usually the better fit. Reach for db-dumper directly when you need a narrow, bespoke dump job inside a pipeline you already control.
- Which Laravel and PHP versions does spatie/db-dumper support?
- The package is framework-agnostic plain PHP and has no hard Laravel dependency, so it works in any Laravel application whose PHP version satisfies the constraint in its composer.json. It is commonly installed on modern Laravel releases via Composer without additional service providers. Always check the current PHP requirement on Packagist before upgrading your runtime. Because it is not tied to Laravel internals, Laravel upgrades rarely affect it.
- Which databases can spatie/db-dumper dump?
- It supports MySQL, MariaDB, PostgreSQL, SQLite, and MongoDB through dedicated classes such as MySql, MariaDb, PostgreSql, Sqlite, and MongoDb. Each class wraps the corresponding native client: mysqldump, mariadb-dump, pg_dump, sqlite3, and mongodump. For SQLite the db name is the path to the database file, and for MongoDB the output is typically a gzipped archive. Other engines are not supported out of the box.
- How do I compress database dumps with spatie/db-dumper?
- The package lets you pipe the dump output through a compressor before writing it to a file, so you can produce files such as dump.sql.gz. The compressor relies on the gzip or bzip2 binary being installed on the host, alongside the database client binary. Compression reduces storage and transfer size but is not encryption, so sensitive dumps still need encryption at rest through your storage layer. You can also dump to an uncompressed file and compress it yourself if you prefer full control.
- Are database credentials safe when using spatie/db-dumper?
- The dump command signature accepts an output path and a credentials file, which implies credentials are written to a temporary file and referenced rather than passed on the command line, avoiding exposure through process listings. That is a meaningful improvement over inline passwords, but you should still require evidence of restrictive file permissions, a safe temporary location, and cleanup on failure. Use setDatabaseUrl or environment-driven configuration so secrets come from your secret store rather than source code. Treat credential handling as something to verify explicitly before production sign-off.
- Why does pg_dump or mysqldump fail after a database upgrade?
- Client and server version skew is the most common failure mode. pg_dump refuses to dump a PostgreSQL server whose major version is newer than the client binary, which becomes a hard blocking failure immediately after a managed database upgrade on RDS, Aurora, or Cloud SQL. With MySQL, mysqldump 8 against a 5.7 server can fail on information_schema.column_statistics unless you disable column statistics. Both issues are documented in the README, and the fix is to keep client binaries aligned with the server version on your application image.
- Does spatie/db-dumper handle scheduling, retention, and off-site storage?
- No. Scheduling, retention, off-host storage, encryption, alerting, and restore verification are all out of scope and must be built or bought separately. In Laravel you would normally pair it with the scheduler, queue workers, and Flysystem or S3 for storage. There is also no concurrency control, so two overlapping jobs writing to the same target path can corrupt the output and you must prevent that in your job design.
- How do I test spatie/db-dumper in a Laravel application, and is it actively maintained?
- Because the fluent API returns the instance from each setter, you can build the dumper from configuration and assert the generated command in unit tests without touching a real database. Integration tests should run against a real engine in CI where the client binaries are installed, since a green dump run does not prove the artifact is restorable. The package is small, stable, and effectively single-vendor maintained by Spatie with a modest bus-factor risk. It is also almost certainly already in your dependency tree transitively through spatie/laravel-backup, so check before adding it directly.