定制 amoracr/yii2-backup 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

amoracr/yii2-backup

Composer 安装命令:

composer require amoracr/yii2-backup

包简介

Component for creating backups of Yii2 sites.

README 文档

README

Backup and Restore functionality for Yii2 applications.

This extension is based on:

I combined those sources and made a more powerful and easier to use extension.

Supported databases:

  • MySQL
  • MariaDB (via MySQL driver)
  • SQLite
  • PostgreSQL

Supported compression methods:

  • Bzip2
  • Gzip
  • Zip

By default the backup files is a tar file with sql dumps and folders.

Current limitations:

  • Requires a linux system.
  • Currently only MySQL on localhost is supported.
  • Currently only MariaDB on localhost is supported.
  • Currently only PostgreSQL on localhost is supported.

Getting started

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist amoracr/yii2-backup "*"

or add

"amoracr/yii2-backup": "*"

to the require section of your composer.json file.

Configuration

Once the extension is installed, add it in your config file:

Basic config/console.php

Advanced console/config/main.php

Minimal Config

'components' => [
    ...
    'backup' => [
            'class' => 'amoracr\backup\Backup',
            // Path for storing the backups
            'backupDir' => '@app/backups',
            // Directories that will be added to backup
            'directories' => [
                // format: <inner backup filename> => <path/to/dir>
                'images' => '@app/web/images',
                'uploads' => '@app/web/uploads',
            ],
        ],
]

Will create backup for:

directories:
/web/images/*
/web/uploads/*
database:
Yii::$app->db

Result:

/backups/2020-06-29T182436-0600_backup.tar/
>images/
>uploads/
>sql/db.sql

Advanced Config

'components' => [
    ...
    'backup' => [
            'class' => 'amoracr\backup\Backup',
            // Name for the backup
            'fileName' => 'myapp-backup',
            // Maximum age in seconds for a valid backup.
            // Older files are considered deprecated and can be deleted.
            // Minimum age is 86400 secs (1 day).
            // Maximum age is 31536000 secs (1 year).
            'expireTime'=> 86400 * 3,
            // Path for storing the backups
            'backupDir' => '@app/backups',
            // Database components to backup
            'databases' => ['db', 'db1'],
            // Compression method to apply to backup file.
            // Available options:
            // 'none' or 'tar' for tar files, backup file is not compressed.
            // 'bzip2' for tar.bz2 files, backup file is compressed with Bzip2 compression.
            // 'gzip' for tar.gz files, backup file is compressed with Gzip compression.
            // 'zip' for zip files, backup file is compressed with Zip compression.
            'compression' => 'zip',
            // Directories that will be added to backup
            'directories' => [
                // format: <inner backup filename> => <path/to/dir>
                'images' => '@app/web/images',
                'uploads' => '@app/web/uploads',
                // format: <inner backup filename> => array('path'=><path/to/dir>,'regex'=><regular/expression/>)
                // Key 'path' for setting the directory to include
                // Key 'regex' for setting the regular expression for selecting the files to include
                'pdf' => [
                   'path' => '@app/web/documents',
                   'regex' => '/\.pdf$/',
                ],
            ],
            // Files to avoid in backup accross all directories
            'skipFiles' => [
                '.gitignore',
            ]
        ],
]

Result:

/backups/2020-06-29T182436-0600_myapp-backup.zip/
>images/
>uploads/
>pdf/
>sql/db.sql
>sql/db1.sql

Usage

You can use this component in a console command.

/console/controllers/BackupController.php:/

<?php
namespace console\controllers;

class BackupController extends \yii\console\Controller
{
    public function actionBackup()
    {
        $backup = \Yii::$app->backup;
        $databases = ['db', 'db1', 'db2'];
        foreach ($databases as $k => $db) {
            $index = (string)$k;
            $backup->fileName = 'myapp-part';
            $backup->fileName .= str_pad($index, 3, '0', STR_PAD_LEFT);
            $backup->directories = [];
            $backup->databases = [$db];
            $file = $backup->create();
            $this->stdout('Backup file created: ' . $file . PHP_EOL, \yii\helpers\Console::FG_GREEN);
        }
    }
}

amoracr/yii2-backup 适用场景与选型建议

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

它主要适用于以下技术方向: 「dump」 「extension」 「backup」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-11