PHPackages                             mhmdomer/laravel-database-backup - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mhmdomer/laravel-database-backup

ActiveLibrary[Database &amp; ORM](/categories/database)

mhmdomer/laravel-database-backup
================================

Backup your laravel database by a simple artisan command

1.1.0(1y ago)294.5k5MITPHPPHP ^7.4|^8.0

Since Aug 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mhmdomer/laravel-database-backup)[ Packagist](https://packagist.org/packages/mhmdomer/laravel-database-backup)[ Docs](https://github.com/mhmdomer/laravel-database-backup)[ RSS](/packages/mhmdomer-laravel-database-backup/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (12)Used By (0)

[![Laravel Database Backup](https://user-images.githubusercontent.com/39973541/134142232-982b60e1-a765-4a37-b2f0-43e32d407a21.png)](https://user-images.githubusercontent.com/39973541/134142232-982b60e1-a765-4a37-b2f0-43e32d407a21.png)

Backup your laravel database by a simple artisan command
========================================================

[](#backup-your-laravel-database-by-a-simple-artisan-command)

[![GitHub Tests Action Status](https://camo.githubusercontent.com/0b1fb56ad09b2f67cc93eeed4272e1bd4b2932f236bfa2f9a41539ac37fea3ae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d686d646f6d65722f6c61726176656c2d64617461626173652d6261636b75702f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/mhmdomer/laravel-database-backup/actions/workflows/run-tests.yml/badge.svg)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/63f32365ea4e80f0dffa1e4ea142c2bf0f45503af2d7c99bc8f69917f7cc302c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d686d646f6d65722f6c61726176656c2d64617461626173652d6261636b75702f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/mhmdomer/laravel-database-backup/actions/workflows/php-cs-fixer.yml/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/39986916cb74b8d106028518b61c80c01d1622e94001c468718f8eb525bb021f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d686d646f6d65722f6c61726176656c2d64617461626173652d6261636b75702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mhmdomer/laravel-database-backup)[![Latest Stable Version](https://camo.githubusercontent.com/50974e253256330cf11ffa0b3686c192c952af9188f9334ff961b8db8560a846/687474703a2f2f706f7365722e707567782e6f72672f6d686d646f6d65722f6c61726176656c2d64617461626173652d6261636b75702f76)](https://packagist.org/packages/mhmdomer/laravel-database-backup)[![License](https://camo.githubusercontent.com/9e74e2ba09a218ea56dcbdc9250298b65df6bb96c7b5b32bfce9dbebe4054053/687474703a2f2f706f7365722e707567782e6f72672f6d686d646f6d65722f6c61726176656c2d64617461626173652d6261636b75702f6c6963656e7365)](https://packagist.org/packages/mhmdomer/laravel-database-backup)

This package will allow you to backup your laravel app database and you can also choose to send the backup file via email by simply running the command `php artisan database:backup`

Supported Databases
-------------------

[](#supported-databases)

- Mysql
- Postgresql
- sqlite

Requirements
------------

[](#requirements)

- If you are using Mysql, make sure `mysqldump` is installed on your system
- If you are using Postgresql, make sure `pg_dump` is installed on your system

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require mhmdomer/laravel-database-backup
```

You can publish the config file with:

```
php artisan vendor:publish --tag=database-backup
```

You can configure the `maximum_backup_files` and whether to send an email when a backup occurs as well as specifying the email to send the backup file to

This is the contents of the published config file:

```
return [

    /*
    |-------------------------------------------------------------------------
    | Backup Folder
    |-------------------------------------------------------------------------
    |
    | The path of the folder to save backups on and retrieve backups from.
    */

    'backup_folder' => storage_path('app/backup'),

    /*
    |-------------------------------------------------------------------------
    | Maximum Backup Files
    |-------------------------------------------------------------------------
    |
    | The maximum number of files that should be present inside the backup folder,
    | each new backup after this limit will result in removing the oldest backup file
    */

    'maximum_backup_files' => 10,

    /*
    |-------------------------------------------------------------------------
    | Mail Settings
    |-------------------------------------------------------------------------
    | Email configuration for backups.
    */

    "mail" => [

        /*
        |-------------------------------------------------------------------------
        | Send Mail
        |-------------------------------------------------------------------------
        | Specify if an email with the backup file attached should
        | be sent when creating a backup.
        */

        'send' => env('DB_BACKUP_SEND_MAIL', false),

        /*
        |-------------------------------------------------------------------------
        | Backup Mail
        |-------------------------------------------------------------------------
        | Specify the email that should receive the backup file.
        */

        'to' => env('DB_BACKUP_EMAIL', 'example@example.com')
    ]
];
```

Usage
-----

[](#usage)

To create a backup of your database you can run:

```
php artisan database:backup
```

The above command is typically run as a schedule command, for example, you can add the following line in the `schedule` function inside `app\Console\Kernel.php`

```
$schedule->command('database:backup')->daily();
```

To disable sending a backup email you can add `--no-mail` option:

```
php artisan database:backup --no-mail
```

To get the latest backup file:

```
DatabaseBackup::getLatestBackupFile();
```

To get all backup files:

```
DatabaseBackup::getBackupFiles();
```

To download the latest backup file:

```
$backupFile = DatabaseBackup::getLatestBackupFile();
return response()->download($backupFile);
```

### Listening to Events

[](#listening-to-events)

`Mhmdomer\DatabaseBackup\Events\DatabaseBackupComplete` Event will be fired after each backup success, this event has a `string` public property called `$path` containing the path of the backup file so you can use it to download the file

Similarly,`Mhmdomer\DatabaseBackup\Events\DatabaseBackupFailed` Event will be fired after each backup failure, this event has an `Exception` public property called `$exception` containing the exception that caused the database backup failure. For example, you can add listeners to listen for these events by editing your `EventServiceProvider` like this:

```
protected $listen = [
    Mhmdomer\DatabaseBackup\Events\DatabaseBackupComplete::class => [
        SendSuccessMessage::class,
    ],
    Mhmdomer\DatabaseBackup\Events\DatabaseBackupFailed::class => [
        LogException::class,
    ],
];
```

change `SendSuccessMessage::class` and `LogException::class` to match your own listeners

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [mhmdomer](https://github.com/mhmdomer)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 96.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~127 days

Recently: every ~285 days

Total

10

Last Release

580d ago

Major Versions

v0.3.4 → 1.0.02023-03-08

PHP version history (2 changes)v0.0.1PHP ^8.0

v0.0.2PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe78ae297fb521a61b7ce76c852a4963fb4b073faeffe228727e55f98d1fd269?d=identicon)[mohammed omer](/maintainers/mohammed%20omer)

---

Top Contributors

[![mhmdomer](https://avatars.githubusercontent.com/u/39973541?v=4)](https://github.com/mhmdomer "mhmdomer (55 commits)")[![arif98741](https://avatars.githubusercontent.com/u/17213478?v=4)](https://github.com/arif98741 "arif98741 (1 commits)")[![rhynodesigns](https://avatars.githubusercontent.com/u/2198266?v=4)](https://github.com/rhynodesigns "rhynodesigns (1 commits)")

---

Tags

backupdatabaselaravelpackagelaravellaravel-database-backupmhmdomer

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mhmdomer-laravel-database-backup/health.svg)

```
[![Health](https://phpackages.com/badges/mhmdomer-laravel-database-backup/health.svg)](https://phpackages.com/packages/mhmdomer-laravel-database-backup)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[yii2tech/illuminate

Yii2 to Laravel Migration Package

11315.1k](/packages/yii2tech-illuminate)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
