承接 tito10047/migration-backup 相关项目开发

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

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

tito10047/migration-backup

Composer 安装命令:

composer require tito10047/migration-backup

包简介

Symfony bundle that automatically backs up your database (MySQL, PostgreSQL, SQLite) before running migrations. Supports Gzip compression and automatic cleanup.

README 文档

README

Build Status Latest Stable Version License PHP Version Symfony Version Coverage Status

Did you run a migration and it "crashed" in the middle? Welcome to hell. 🔥

You know the drill: you run doctrine:migrations:migrate, the third command out of ten fails, and you're left with a broken database. Revert doesn't work because half the changes were applied and half weren't. You don't know exactly what was executed and what wasn't. Manual repair is a nightmare, and if you had settings or data in the database that can't just be "re-run" via fixtures... well, good luck.

Migration Backup Bundle is your rescue parachute. It automatically backs up your database right before the first migration starts. If anything goes wrong, you have a clean restore point to return to immediately.

✨ Features

  • 🚀 Automatic backup before running migrations.
  • 🗜️ Compression support: Multi-format support (Gzip, Bzip2, Zstandard, Zip, LZ4) to reduce backup size.
  • 🧹 Automatic Cleanup: Keep e.g. only the last 10 backups and save space.
  • 🧩 Extensible: Easily add your own custom compressor.
  • 🐘 Multi-DB support: Full support for MySQL, PostgreSQL, and SQLite.
  • 🔔 Events: Ability to hook into your own logic (Slack notifications, logging, etc.).

📦 Installation

composer require tito10047/migration-backup

(If you are not using Symfony Flex, don't forget to register the bundle in config/bundles.php)

⚙️ Configuration

Create the file config/packages/migration_backup.yaml:

migration_backup:
    # Directory for storing backups (default is %kernel.project_dir%/backup)
    backup_path: '%kernel.project_dir%/var/backups'
    
    # Which DB connections you want to back up (can be multiple)
    database: ['default']
    
    # How many last backups to keep (0 = all)
    keep_last_n_backups: 5
    
    # Should the backup be compressed?
    compress: true

    # Compression format to use (default: gzip)
    # Available options: gzip, bzip2, zstd, zip, lz4, none
    compression_format: 'gzip'

    # Paths to binaries (if not available globally in PATH)
    backup_binary: 'mysqldump'    # For MySQL
    pg_dump_binary: 'pg_dump'      # For PostgreSQL

🚀 Usage

The bundle does not activate itself automatically during every migration (to avoid slowing you down during development). To create a backup, just add the --backup flag (or the shortcut -b) to the command:

Note: This bundle is primarily intended for the development environment, but there is nothing stopping you from using it in production as well.

php bin/console doctrine:migrations:migrate --backup

The console output will inform you of the success: Backup of database default created in /your/project/var/backups/default-2024-03-11-15-55-01.sql.gz

🗜️ Compression

The bundle supports several compression formats. Each format requires its corresponding PHP extension to be installed:

Format Extension File Extension Recommendation
Gzip zlib .gz Standard, well-balanced.
Bzip2 bz2 .bz2 Better compression ratio, slower.
Zstandard zstd .zst Modern, fast with great compression.
Zip zip .zip Highly compatible across OS.
LZ4 lz4 .lz4 Extremely fast compression.
None - - No compression.

If the required extension is missing, the bundle will throw a RuntimeException when attempting to use that format.

Custom Compressor

You can implement your own compression logic by creating a class that implements Tito10047\MigrationBackup\Compressor\CompressorInterface.

Then, register your service and alias the migration_backup.compressor to it:

# config/services.yaml
services:
    App\Backup\MyCustomCompressor:
        arguments: ['@symfony_filesystem_service']

    migration_backup.compressor:
        alias: App\Backup\MyCustomCompressor

Note: If you override the migration_backup.compressor service, the compression_format setting in migration_backup.yaml will be ignored. It's cleaner to set it to none to avoid confusion.

🛠️ Supported Databases

  • MySQL: requires mysqldump to be installed.
  • PostgreSQL: requires pg_dump to be installed.
  • SQLite: standard file access is enough (automatically copies the .db file).

🪝 Events for Developers

The bundle triggers the following events that you can listen to:

  • Tito10047\MigrationBackup\Event\BackupStartedEvent
  • Tito10047\MigrationBackup\Event\BackupFinishedEvent
  • Tito10047\MigrationBackup\Event\BackupFailedEvent

Developed for a peaceful sleep with every deploy. 😊

tito10047/migration-backup 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 634
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-26