ahmedweb / laravel-backup-service
A simple Laravel package to make backup services easier to implement using traits.
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ahmedweb/laravel-backup-service
Requires
- php: ^8.2
- google/apiclient: ^2.15.0
- irazasyed/telegram-bot-sdk: ^3.15
- laravel/framework: ^11.31
- laravel/sanctum: ^4.0
- laravel/tinker: ^2.9
- masbug/flysystem-google-drive-ext: ^2.4
- spatie/laravel-backup: ^9.3
- yaza/laravel-google-drive-storage: ^4.1
Requires (Dev)
- phpunit/phpunit: ^9.5
README
Laravel Backup Service is a powerful and developer-friendly package designed to automate your Laravel application backups. It seamlessly integrates with Google Drive and Telegram, offering convenient backup uploads, link notifications, and scheduled cleanup โ all through simple Artisan commands.
๐ Features
- ๐ Backup uploads directly to Google Drive
- ๐ Auto-send backup download links to Telegram
- ๐ Store and manage latest backup file links
- ๐งน Automatically delete outdated backup files
- โ Clean, modular, and maintainable code structure
- ๐ป Easy-to-use Artisan commands
- ๐ Fully schedulable via Laravel Scheduler
๐ฆ Installation
Install the package via Composer:
composer require ahmedweb/laravel-backup-service
Publish the configuration and service provider:
php artisan vendor:publish --tag=laravel-backup-service
โ๏ธ Configuration
1. Environment Setup
Add the following variables to your .env file:
FILESYSTEM_CLOUD=google GOOGLE_DRIVE_CLIENT_ID=your-client-id GOOGLE_DRIVE_CLIENT_SECRET=your-client-secret GOOGLE_DRIVE_REFRESH_TOKEN=your-refresh-token GOOGLE_DRIVE_FOLDER_ID=your-folder-id # Optional custom folder name GOOGLE_DRIVE_FOLDER= TELEGRAM_BOT_TOKEN=your-telegram-bot-token TELEGRAM_CHAT_ID=your-telegram-chat-id
2. Filesystem Configuration
Update config/filesystems.php with a new google_drive disk:
'google_drive' => [ 'driver' => 'google', 'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'), 'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'), 'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'), 'folder' => env('GOOGLE_DRIVE_FOLDER'), 'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'), ],
๐ฌ Telegram Integration
Step 1: Create a Telegram Bot
- Open Telegram and search for @BotFather.
- Use /newbotand follow the prompts to create a bot.
- Copy the provided token and paste it into your .envasTELEGRAM_BOT_TOKEN.
Step 2: Add Bot to a Group
- Create a group or use an existing one.
- Add your bot to the group.
- Mention the bot once to activate it.
Step 3: Get Group Chat ID
- Use @userinfobotor check thechat.idfield via bot API messages.
- Paste the group chat ID into your .envasTELEGRAM_CHAT_ID.
โ๏ธ Laravel 11 Integration
Register Storage Provider
In bootstrap/app.php, register the Google Drive provider:
use AhmedWeb\LaravelBackupService\Providers\GoogleDriveStorageProvider; return Application::configure(basePath: dirname(__DIR__)) ->withProviders([ GoogleDriveStorageProvider::class, ]) ->create();
โฐ Scheduling Backups (Optional)
In bootstrap/app.php, add scheduled commands:
use Illuminate\Console\Scheduling\Schedule; return Application::configure(basePath: dirname(__DIR__)) ->withSchedule(function (Schedule $schedule) { $schedule->command('backup:run')->daily(); $schedule->command('backup:clean')->daily(); $schedule->command('backup:store-latest-link')->dailyAt('01:00'); $schedule->command('backup:delete-old')->weekly(); }) ->create();
Ensure Laravel Scheduler is set in your server cron:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
๐งช Available Artisan Commands
| Command | Description | 
|---|---|
| backup:store-latest-link | Stores and sends the latest backup download link via Telegram | 
| backup:delete-old | Deletes outdated backup files from Google Drive | 
| backup:clean-drive | Cleans up Google Drive backups according to retention rules | 
For Laravel 10 or below, schedule commands in
app/Console/Kernel.php.
๐ File Structure
laravel-backup-service/
โโโ src/
โ   โโโ Commands/
โ   โ   โโโ StoreLatestBackupLink.php
โ   โ   โโโ DeleteOldBackupFiles.php
โ   โ   โโโ CleanGoogleDriveBackups.php
โ   โโโ Services/
โ   โ   โโโ GoogleDriveBackupService.php
โ   โโโ Providers/
โ   โ   โโโ GoogleDriveStorageProvider.php
โโโ config/
โ   โโโ filesystems.php (optional override)
โ Requirements
| Dependency | Version | 
|---|---|
| PHP | ^8.2 | 
| Laravel | ^11.31 | 
| spatie/laravel-backup | ^9.3 | 
| google/apiclient | ^2.15 | 
| irazasyed/telegram-bot-sdk | ^3.15 | 
| masbug/flysystem-google-drive-ext | ^2.4 | 
| yaza/laravel-google-drive-storage | ^4.1 | 
๐ค Contributing
Contributions are welcome! Feel free to fork the repo, submit issues, or open pull requests for any improvements or fixes.
๐ License
This package is open-sourced software licensed under the MIT license.
๐จโ๐ป Author
Ahmed Web ๐ง ahmedwry588@gmail.com ๐ GitHub
๐ Resources
- Google Developer Console โ Create and manage your credentials
- OAuth 2.0 Playground โ Retrieve your refresh token
- Spatie Laravel Backup Docs
- Telegram Bot API