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.3(1mo ago)097MITPHPPHP ^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 1mo ago

READMEChangelog (7)Dependencies (2)Versions (12)Used By (0)

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

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
```

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

44

—

FairBetter than 92% of packages

Maintenance89

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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 ~42 days

Recently: every ~99 days

Total

11

Last Release

58d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b43359edbb79cfeec622571fbf701e4bf401283a5a717e1bfc296d360608459?d=identicon)[marekmiklusek](/maintainers/marekmiklusek)

---

Top Contributors

[![marekmiklusek](https://avatars.githubusercontent.com/u/112761697?v=4)](https://github.com/marekmiklusek "marekmiklusek (35 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

[sarfraznawaz2005/backupmanager

laravel package to backup/restore files and database.

313.7k](/packages/sarfraznawaz2005-backupmanager)

PHPackages © 2026

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