laravel-backup-service maintained by ahmedweb
Laravel Backup Service
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