PHPackages                             marekmiklusek/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. marekmiklusek/database-backup

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

marekmiklusek/database-backup
=============================

A Laravel package for database backups

v1.2.6(1mo ago)02832MITPHPPHP ^8.2

Since Jan 25Pushed 1mo ago1 watchersCompare

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

READMEChangelog (7)Dependencies (3)Versions (15)Used By (2)

[![image(1)(2)](https://private-user-images.githubusercontent.com/112761697/406664782-7263ce86-3d48-4aec-807d-20267fbf5742.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODYzNTc0NTYsIm5iZiI6MTc4NjM1NzE1NiwicGF0aCI6Ii8xMTI3NjE2OTcvNDA2NjY0NzgyLTcyNjNjZTg2LTNkNDgtNGFlYy04MDdkLTIwMjY3ZmJmNTc0Mi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwODEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDgxMFQxMDE5MTZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jMGIxNjYyYWU4NzY0OTRjMWY4Yzc0MWFmNjQ2ODU3YjlkZTY3M2JkMjQ3ZjJkNmZjMWU3YTI5M2I3ODlhMmUwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.xLPVXTpqSGlhznUJ2FQpCm_MH4fScCVaplaJbzpY6WE)](https://private-user-images.githubusercontent.com/112761697/406664782-7263ce86-3d48-4aec-807d-20267fbf5742.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODYzNTc0NTYsIm5iZiI6MTc4NjM1NzE1NiwicGF0aCI6Ii8xMTI3NjE2OTcvNDA2NjY0NzgyLTcyNjNjZTg2LTNkNDgtNGFlYy04MDdkLTIwMjY3ZmJmNTc0Mi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwODEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDgxMFQxMDE5MTZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jMGIxNjYyYWU4NzY0OTRjMWY4Yzc0MWFmNjQ2ODU3YjlkZTY3M2JkMjQ3ZjJkNmZjMWU3YTI5M2I3ODlhMmUwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.xLPVXTpqSGlhznUJ2FQpCm_MH4fScCVaplaJbzpY6WE)

Laravel Database Backup 💾📂🌐
===========================

[](#laravel-database-backup-)

A lightweight package for automated MySQL database backups in Laravel applications. This package seamlessly integrates with both local storage and Google Drive, providing a reliable solution for database backup management.

Features
--------

[](#features)

- Simple and automated MySQL database backups
- Multiple storage options:
    - Local storage
    - Google Drive integration
    - Simultaneous backup to multiple locations
- Command-line interface for easy management
- Automatic cleanup of old backups
- Customizable backup settings
- Minimal configuration required

System Requirements
-------------------

[](#system-requirements)

Ensure your system meets the minimum version requirements before installing this package.

- PHP Version: 8.2
- Laravel Version: 11

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

[](#installation)

### Step 1: Install the Package

[](#step-1-install-the-package)

```
composer require marekmiklusek/database-backup
```

### Step 2: Publish Configuration

[](#step-2-publish-configuration)

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

Local Backup Configuration
--------------------------

[](#local-backup-configuration)

Backups are stored locally by default using the `local` disk.

Usage
-----

[](#usage)

### Run a Backup

[](#run-a-backup)

To create a new backup, run the following Artisan command:

```
php artisan db-backup:run
```

### Clean Up Old Backups

[](#clean-up-old-backups)

- By default, old backups are **automatically cleaned up** after each backup.
- Backups older than **14 days** are automatically deleted to free up space.
- This retention period is **configurable**, allowing you to adjust how long backups are kept based on your needs.

#### Disabling Automatic Cleanup

[](#disabling-automatic-cleanup)

If you want to **disable automatic cleanup**, you can set the `automatic` option to `false` in the configuration file:

```
// config/database-backup.php
'cleanup' => [
   'automatic' => false,
],
```

If you prefer to manually clean up old backups, you can run the following Artisan command:

```
php artisan db-backup:cleanup
```

TLS/SSL Connections (optional)
------------------------------

[](#tlsssl-connections-optional)

By default no SSL options are passed to the dump client, so most setups need **no extra configuration**.

If your database server **forces TLS** (common on managed/shared hosts, especially after a server migration), the backup may fail with:

```
mysqldump: Got error: 2026: "TLS/SSL error: Certificate verification failure: The certificate is NOT trusted." when trying to connect

```

Add the SSL settings to your `.env`:

```
# 'mysql' (default) or 'mariadb' — MariaDB rejects `ssl-mode`, so use 'mariadb'
DB_BACKUP_DUMP_CLIENT=mariadb

# Force an encrypted connection
MYSQL_SSL_MODE=REQUIRED
```

> If the dump output shows `mysqldump: Deprecated program name ... use mariadb-dump`, your server is **MariaDB** → set `DB_BACKUP_DUMP_CLIENT=mariadb`. This also makes the package call `mariadb-dump` directly, which removes that warning. To force a specific binary, set `DB_BACKUP_DUMP_BINARY=/usr/bin/mariadb-dump`.

**With a CA certificate (verified connection, recommended when available):**

```
MYSQL_ATTR_SSL_CA=/path/to/ca-cert.pem
MYSQL_SSL_MODE=VERIFY_CA
```

After changing `.env`, clear the config cache:

```
php artisan config:clear
```

Google Drive Integration
------------------------

[](#google-drive-integration)

### Step 1: Configure Google Drive

[](#step-1-configure-google-drive)

Add the following configuration to `config/filesystems.php`:

```
'google' => [  // Can be renamed to your preferred disk name
    'driver' => 'google',
    'client_id' => env('GOOGLE_CLIENT_ID'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET'),
    'refresh_token' => env('GOOGLE_REFRESH_TOKEN'),
    'folder_id' => env('GOOGLE_FOLDER_ID'),
]
```

NOTE: you can customize the disk name (e.g., `google_db_backup` instead of `google`)

### Step 2: Environment Variables

[](#step-2-environment-variables)

Add these variables to your `.env` file:

```
GOOGLE_CLIENT_ID=your_client_id
GOOGLE_CLIENT_SECRET=your_client_secret
GOOGLE_REFRESH_TOKEN=your_refresh_token
GOOGLE_FOLDER_ID=your_folder_id
```

Google Drive API Setup Guide
----------------------------

[](#google-drive-api-setup-guide)

This guide will walk you through setting up Google Drive API credentials and obtaining the necessary tokens for integration with your Laravel application.

### Step 1: Create Google Cloud Project

[](#step-1-create-google-cloud-project)

1. Visit [Google Cloud Console](https://console.cloud.google.com)
2. Click "Select a project" → "New Project"
3. Enter a project name and click "CREATE"
4. Wait for the project to be created and select it

### Step 2: Enable Google Drive API

[](#step-2-enable-google-drive-api)

1. In the left sidebar, navigate to "APIs &amp; Services" → "Library"
2. Search for "Google Drive API"
3. Click on "Google Drive API"
4. Click "ENABLE"

### Step 3: Configure OAuth Consent Screen

[](#step-3-configure-oauth-consent-screen)

1. Go to "APIs &amp; Services" → "OAuth consent screen"
2. Select "External" user type and click "CREATE"
3. Fill in the required information:
    - App name
    - User support email
    - Developer contact information
4. Click "SAVE AND CONTINUE"
5. Skip scopes screen by clicking "SAVE AND CONTINUE"
6. Add test users (your email) if in testing mode
7. Click "SAVE AND CONTINUE"

### Step 4: Create Credentials

[](#step-4-create-credentials)

For Web Application:

1. Go to "APIs &amp; Services" → "Credentials"
2. Click "+ CREATE CREDENTIALS" → "OAuth client ID"
3. Select "Web application" as application type
4. Enter a name for your client
5. Under "Authorized redirect URIs" add: ```
    https://developers.google.com/oauthplayground

    ```
6. Click "CREATE"
7. A popup will show your Client ID and Client Secret
8. Add them to your `.env` file as `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET`

For Desktop Application:

1. Go to "APIs &amp; Services" → "Credentials"
2. Click "+ CREATE CREDENTIALS" → "OAuth client ID"
3. Select "Desktop app" as application type
4. Enter a name for your client
5. Click "CREATE"
6. A popup will show your Client ID and Client Secret
7. Add them to your `.env` file as `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET`

### Step 5: Get Refresh Token

[](#step-5-get-refresh-token)

For Web Application:

1. Go to [Google OAuth Playground](https://developers.google.com/oauthplayground/)
2. Click the gear icon (⚙️) in the top right corner
3. Check "Use your own OAuth credentials"
4. Enter your:
    - OAuth Client ID
    - OAuth Client Secret
5. Click "Close"
6. In the left sidebar, find "Drive API v3"
7. Select `https://www.googleapis.com/auth/drive.file`
8. Click "Authorize APIs"
9. Log in with your Google account and accept permissions
10. Click "Exchange authorization code for tokens"
11. Copy the refresh token from the response and add it to your `.env` file as `GOOGLE_REFRESH_TOKEN`

For Desktop Application:

1. Open the following URL in your web browser (replace `YOUR_CLIENT_ID` with your actual client ID): [https://accounts.google.com/o/oauth2/auth?client\_id=YOUR\_CLIENT\_ID&amp;redirect\_uri=urn:ietf:wg:oauth:2.0:oob&amp;response\_type=code&amp;scope=https://www.googleapis.com/auth/drive.file&amp;access\_type=offline&amp;prompt=consent](https://accounts.google.com/o/oauth2/auth?client_id=YOUR_CLIENT_ID&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive.file&access_type=offline&prompt=consent)
    - Using the scope `https://www.googleapis.com/auth/drive.file` allows your application to view and manage Google Drive files and folders that were opened or created by the app
2. Sign in with your Google account and grant access to the requested permissions
3. Google will display an **authorization code** on the screen. Copy this code
4. In your terminal run the following `curl` command, to exchange the authorization code for tokens (replace YOUR\_AUTHORIZATION\_CODE, YOUR\_CLIENT\_ID, and YOUR\_CLIENT\_SECRET with the actual values): ```
    curl --request POST \
       --url https://oauth2.googleapis.com/token \
       --header 'Content-Type: application/x-www-form-urlencoded' \
       --data 'code=YOUR_AUTHORIZATION_CODE&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code'
    ```
5. The response will include a refresh token. Copy it and store it in your `.env` file as `GOOGLE_REFRESH_TOKEN`

### Step 6: Get Google Drive Folder ID

[](#step-6-get-google-drive-folder-id)

1. Go to [Google Drive](https://drive.google.com)
2. Create a new folder or select an existing one for backups
3. Open the folder
4. Copy the folder ID from the URL
    - The URL will look like: `https://drive.google.com/drive/folders/1A2B3C4D5E6F7...`
    - The folder ID is the string after `/folders/`
5. Add this folder ID to your `.env` file as `GOOGLE_FOLDER_ID`

### That's it! 🚀 You're now ready to use this package — have fun and enjoy! 😊🎉

[](#thats-it--youre-now-ready-to-use-this-package--have-fun-and-enjoy-)

Events
------

[](#events)

This package emits the following events that you can listen to in your application:

- `MarekMiklusek\DatabaseBackup\Events\BackupCreated`

Triggered when a database backup is successfully created.

- `MarekMiklusek\DatabaseBackup\Events\BackupFailed`

Triggered when a database backup fails.

Common Issues
-------------

[](#common-issues)

1. **Redirect URI Mismatch**: Make sure you've added the exact OAuth Playground URL to authorized redirect URIs
2. **Invalid Credentials**: Double-check all IDs and tokens are copied correctly
3. **Token Expiration**: Refresh tokens don't expire unless revoked, but if you create new credentials, you'll need a new refresh token
4. **Permission Issues**: Ensure the Google Drive API is enabled and the correct scope is selected

Security Notes
--------------

[](#security-notes)

- Keep all credentials secure and never commit them to version control
- Use environment variables for all sensitive information
- Consider implementing credential rotation for production environments

License
-------

[](#license)

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

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance91

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~41 days

Recently: every ~29 days

Total

14

Last Release

42d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/112761697?v=4)[Marek Miklušek](/maintainers/marekmiklusek)[@marekmiklusek](https://github.com/marekmiklusek)

---

Top Contributors

[![marekmiklusek](https://avatars.githubusercontent.com/u/112761697?v=4)](https://github.com/marekmiklusek "marekmiklusek (38 commits)")

---

Tags

laraveldatabasebackup

### Embed Badge

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

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11225.5M36](/packages/anourvalar-eloquent-serialize)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

137236.2k8](/packages/statamic-rad-pack-runway)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

865.3k](/packages/waad-laravel-model-metadata)[ramadan/custom-fresh

A Laravel package to specify the tables that you do not want to drop while refreshing the database.

613.1k](/packages/ramadan-custom-fresh)[ramadan/easy-model

A Laravel package for enjoyably managing database queries.

111.6k](/packages/ramadan-easy-model)

PHPackages © 2026

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