arpanpatoliya/db-backup

A Laravel package for database backup with Google Drive integration

v1.0.0 2025-05-17 05:08 UTC

This package is auto-updated.

Last update: 2025-05-17 09:49:47 UTC


README

Latest Version License

A Laravel package to automate your database backups and upload them directly to Google Drive.

✨ Features

  • Easily back up your Laravel application's database
  • Automatically upload backups to Google Drive
  • Run backups via artisan commands
  • Configure automatic cleanup of old backups

📦 Installation

Install the package via Composer:

composer require arpanpatoliya/db-backup

⚙️ Configuration

After installation, publish the configuration file:

php artisan vendor:publish --provider="Arpanpatoliya\DBBackup\DBBackupServiceProvider"

This will create a config file at:

config/dbbackup.php

Update your .env file with the following values:

# Local backup path (customize if needed)
DBBACKUP_LOCAL_PATH=/full/custom/path/if/needed

# Optional: Maximum number of backups to retain (default: 5)
DBBACKUP_MAX_STORED=5

# Database connection (should match config/database.php)
DB_CONNECTION=mysql

# Google Drive API credentials
GOOGLE_DRIVE_CLIENT_ID=your-client-id
GOOGLE_DRIVE_CLIENT_SECRET=your-client-secret
GOOGLE_DRIVE_ACCESS_TOKEN=your-access-token
GOOGLE_DRIVE_REFRESH_TOKEN=your-refresh-token

# Google Drive folder ID to store backups
GOOGLE_DRIVE_FOLDER=your-google-drive-folder-id

🚀 Usage

Run Backup Programmatically

You can trigger a backup directly in your code:

use Arpanpatoliya\DbBackup\Backup;

public function triggerBackupDirectly()
{
    $backup = new Backup();
    $success = $backup->run();

    return $success
        ? response()->json(['message' => 'Backup completed successfully.'])
        : response()->json(['message' => 'Backup failed.'], 500);
}

Run Backup via Artisan Command

Useful for cron jobs or scheduled tasks:

php artisan db-backup:run

✅ Testing

To run the tests:

composer test

👨‍💻 Credits

📄 License

MIT License. See LICENSE for details.