承接 redaelfillali/laravel-backup 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

redaelfillali/laravel-backup

Composer 安装命令:

composer require redaelfillali/laravel-backup

包简介

Laravel Backup solution for shared hosting

README 文档

README

A simple Laravel package for backing up files and databases with support for different backup types and scheduling. This package allows you to perform backups without the use of proc_open, and can be triggered via a console command or a custom controller route.

Requirements

  • Laravel: ^10.0 | ^11.0 | ^12.0
  • PHP:
    • For Laravel 10: ^8.1
    • For Laravel 11 and 12: ^8.2

Features

  • Backup Path: Easily set the destination folder for backups.
  • Backup Types:
    • Full Backup (both files and database)
    • Files Only
    • Database Only
  • No proc_open Dependency: The package works without relying on proc_open, ensuring compatibility with restrictive hosting environments.
  • Command and Controller Support: Can be used via a console command or integrated into your application with a custom controller and route.
  • Scheduled Backups: Utilize Laravel's task scheduling system to automate backups.
  • Retention Cleanup: When running database backups, the package automatically deletes backup files older than a configurable number of days from the configured backup.path directory.

Installation

You can install this package via Composer:

composer require redaelfillali/laravel-backup

Configuration

After installation, publish the configuration file using the following Artisan command:

php artisan vendor:publish --provider="Redaelfillali\LaravelBackup\BackupServiceProvider"

This will copy the configuration file to the config/backup.php file, where you can adjust settings such as the backup path, timeout, and retention period.

Usage

Running Backups via Command

You can run a backup using the following Artisan command:

php artisan backup:run

Specify a backup type (full, files, or database):

php artisan backup:run full
php artisan backup:run database
php artisan backup:run files

Override the backup path:

php artisan backup:run full --path=/your/custom/path

Running Backups via Controller

You can trigger a backup by sending a POST request to the built-in routes or by calling BackupManager directly:

use Redaelfillali\LaravelBackup\Helpers\BackupManager;

class BackupController extends Controller
{
    public function createBackup()
    {
        BackupManager::backup('full', config('backup.path'));

        return response()->json(['message' => 'Backup completed successfully']);
    }
}

Built-in Routes

The package registers the following POST routes automatically:

Method URI Description
POST /backup/run Run a backup (pass type and optional path in the request body)
POST /backup/database Run a database-only backup
POST /backup/files Run a files-only backup

Example request using the /backup/run route:

Route::post('/trigger-backup', function () {
    return Http::post(url('/backup/run'), ['type' => 'database']);
});

Scheduling Backups

You can schedule backups using Laravel's task scheduling system. Add the following to your App\Console\Kernel class (Laravel 10) or routes/console.php (Laravel 11+):

Laravel 10 — app/Console/Kernel.php:

use Illuminate\Console\Scheduling\Schedule;

protected function schedule(Schedule $schedule)
{
    $schedule->command('backup:run database')
             ->daily();
}

Laravel 11+ — routes/console.php:

use Illuminate\Support\Facades\Schedule;

Schedule::command('backup:run database')->daily();

Custom Route Definition

If you prefer to define your own route, you can do so by calling BackupManager directly:

use Redaelfillali\LaravelBackup\Helpers\BackupManager;

Route::post('/backup', function () {
    BackupManager::backup('full', config('backup.path'));
    return response()->json(['message' => 'Backup completed successfully']);
})->middleware('auth');

Note: It is strongly recommended to protect backup routes with authentication middleware to prevent unauthorised access.

Configuration Reference

Key Default Description
path storage/backups/Y/m/d Destination directory for backup files
types ['full', 'files', 'database'] Available backup types
timeout 3600 Maximum execution time in seconds
retention_period 7 Days to keep old backups before automatic deletion
backup_name backup-Y-m-d-H-i-s Filename prefix for database backup files
enable_notifications true Enable/disable backup notifications

Testing

The package includes a full test suite built with PHPUnit and Orchestra Testbench.

Running the Tests

Install the development dependencies and run the test suite:

composer install
composer test

Or run PHPUnit directly:

./vendor/bin/phpunit

Test Structure

tests/
├── TestCase.php                       # Base test case (Orchestra Testbench)
├── Unit/
│   └── BackupManagerTest.php          # Unit tests for BackupManager
└── Feature/
    ├── BackupCommandTest.php          # Feature tests for the Artisan command
    └── BackupControllerTest.php       # Feature tests for the HTTP routes
Suite File Tests
Unit BackupManagerTest Directory creation, zip validity, no duplicate entries, SQL dump content, PDO quoting, null value handling, dynamic DB connection, retention cleanup, full backup
Feature BackupCommandTest All backup types, default type, configured path, exception → exit code 1
Feature BackupControllerTest All three routes, invalid type → HTTP 422, exception → HTTP 500

License

This package is open-source software licensed under the MIT license.

redaelfillali/laravel-backup 适用场景与选型建议

redaelfillali/laravel-backup 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.1k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 redaelfillali/laravel-backup 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 redaelfillali/laravel-backup 我们能提供哪些服务?
定制开发 / 二次开发

基于 redaelfillali/laravel-backup 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-22