LaravelPackages.net
Acme Inc.
Toggle sidebar
tomshaw/laravel-database-export

A Laravel database export console command.

609
1
v0.6.1
About tomshaw/laravel-database-export

tomshaw/laravel-database-export is a Laravel package for a laravel database export console command.. It currently has 1 GitHub stars and 609 downloads on Packagist (latest version v0.6.1). Install it with composer require tomshaw/laravel-database-export. Discover more Laravel packages by tomshaw or browse all Laravel packages to compare alternatives.

Last updated

Laravel Database Export πŸ’Ύ

Latest Version on Packagist Total Downloads Tests License

A Laravel console command that exports your database to a compressed, optionally AES-256 encrypted zip archive on any Laravel filesystem disk. Supports SQLite, MySQL, MariaDB, PostgreSQL and SQL Server.

Features

  • Streams to disk β€” dumps are written directly to a temporary file by the native dump tool, so large databases never exhaust PHP's memory.
  • Credentials stay off the command line β€” passwords are passed via MYSQL_PWD, PGPASSWORD and SQLCMDPASSWORD environment variables so they never appear in the process list.
  • Any filesystem disk β€” archives are uploaded via streams, so remote disks such as Amazon S3 or SFTP work out of the box.
  • AES-256 zip encryption β€” archives are encrypted with the database password, or a password you provide.
  • Driver aware β€” connections are resolved by driver, so custom-named connections work, and each driver's dump options are configurable.

Requirements

  • PHP 8.5
  • Laravel 13.0
  • The PHP zip extension and the dump tool for your database (sqlite3, mysqldump, pg_dump or sqlcmd) on your PATH.

Installation

You can install the package via composer:

composer require tomshaw/laravel-database-export

Optionally publish the configuration file:

php artisan vendor:publish --tag=database-export-config

Usage

Export the default database connection:

php artisan db:export

Export a specific connection:

php artisan db:export --connection=pgsql

Encrypt the archive with a custom password (defaults to the database password when omitted):

php artisan db:export --password=yourpassword

Archives are stored as exports/{connection}/{filename}-{timestamp}.zip on the configured disk.

Scheduling

The command implements Isolatable, so overlapping scheduled runs are prevented automatically:

Schedule::command('db:export', ['--isolated' => true])->daily();

Configuration

| Key | Env variable | Default | Description | | --- | --- | --- | --- | | database-export.disk | BACKUP_DISK | local | Filesystem disk where archives are stored. | | database-export.filename | BACKUP_FILENAME | export | Base filename; a timestamp is appended. | | database-export.directory | BACKUP_DIRECTORY | exports | Directory on the disk; a per-connection subdirectory is added. | | database-export.timeout | BACKUP_TIMEOUT | 3600 | Maximum seconds the dump process may run. | | database-export.compression_level | BACKUP_COMPRESSION_LEVEL | 6 | Deflate compression level (0–9). | | database-export.options | β€” | sensible defaults | Extra CLI options passed to the dump tool, per driver. |

For example, the default MySQL options produce consistent, complete dumps without table locks:

'options' => [
    'mysql' => ['--single-transaction', '--routines', '--triggers', '--no-tablespaces'],
],

Notes

  • SQLite connections have no database password, so their archives are only encrypted when --password is provided.
  • SQL Server backups use BACKUP DATABASE, which is executed by the database server itself β€” the server must have access to the local temporary directory, so this is intended for setups where the server runs on the same host.

Testing

composer test

Run static analysis and formatting:

composer analyse
composer format

Support

If you have any issues or questions, please open an issue on the GitHub repository.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). See License File for more information.

Comments