watheqalshowaiter/backup-tables 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

watheqalshowaiter/backup-tables

Composer 安装命令:

composer require watheqalshowaiter/backup-tables

包简介

Backup single or multiple database tables with ease.

README 文档

README

Package cover

Backup Tables

Required Laravel Version Required PHP Version Latest Version on Packagist GitHub Test Matrix Action Status GitHub Code Style Action Status Total Downloads GitHub Stars StandWithPalestine ko-fi

Backup single or multiple database tables with ease.

Note

If you want a full database backup with many features, go for Spatie Laravel Backup.

Installation

You can install the package via Composer:

composer require watheqalshowaiter/backup-tables

Usage

Use the BackupTables::generateBackup($tableToBackup) Facade anywhere in your application and it will generate $tableToBackup_backup_2024_08_22_17_40_01 table in the database with all the data and structure. Note that the datetime 2024_08_22_17_40_01 will be varied based on your datetime.

You can also use the php artisan backup:tables <targets> command to back up tables, where <targets> is a space-separated list of table names or models.

use WatheqAlshowaiter\BackupTables\BackupTables; // import the facade

class ChangeSomeData
{
    public function handle()
    {
        BackupTables::generateBackup('users');
        // result: users_backup_2024_08_22_17_40_01
       
        // change some data..
    }
}

And More Customizations

  • You can use an array to back up more than one table
BackupTables::generateBackup(['users', 'posts']); 
// users_backup_2024_08_22_17_40_01
// posts_backup_2024_08_22_17_40_01 
  • Or add Classes as parameters, It will backup their tables
BackupTables::generateBackup(User::class);
// users_backup_2024_08_22_17_40_01

// or

BackupTables::generateBackup([User::class, Post::class]);
// users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01 
  • You can customize the $dataTime format to whatever you want
BackupTables::generateBackup('users', 'Y_d_m_H_i');
// users_backup_2024_22_08_17_40

Warning

When customizing the datetime format, be aware that backups with identical datetime values will be skipped. For example, if you use this Y_d_m_H you cannot generate the same backup in the same hour. The default format (Y_m_d_H_i_s) is recommended for most cases.

BackupTables::generateBackup('users', 'Y_d_m_H');
// can not generate the same backup in the same hour

BackupTables::generateBackup('users', 'Y_d_m');
// can not generate the same backup in the same day
  • Using the artisan command for one or more tables/models
php artisan backup:tables users posts
# users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01

php artisan backup:tables \\App\\Models\\User \\App\\Models\\Post
# users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01

Why?

Sometimes you want to back up some database tables before changing data for whatever reason, this package serves this need.

I used it personally before adding foreign keys to tables that required removing unlinked fields from parent tables.

You may find some situation where you play with table data, or you're afraid of missing data, so you back up these tables beforehand.

Features

✅ Backup tables from the code using (Facade) or from the console command.

✅ Supports Laravel versions: 13, 12, 11, 10, 9, 8, 7, and 6.

✅ Supports PHP versions: 8.4, 8.3, 8.2, 8.1, 8.0, and 7.4.

✅ Supports SQL databases: SQLite, MySQL/MariaDB, PostgreSQL, and SQL Server.

✅ Fully automated tested with PHPUnit.

✅ Full GitHub Action CI pipeline to format code and test against all Laravel and PHP versions.

Testing

composer test

Changelog

Please see CHANGELOG for more information on recent changes.

Contributing

If you have any ideas or suggestions to improve it or fix bugs, your contribution is welcome.

I encourage you to look at issues which are the most important features that need to be added.

If you have something different, submit an issue first to discuss or report a bug, then do a pull request.

Security Vulnerabilities

If you find any security vulnerabilities don't hesitate to contact me at watheqalshowaiter[at]gmail[dot]com to fix them.

Related Packages

Support this project

If this project helps you, consider supporting it on Ko-fi ☕.

Credits

And a special thanks to The King Creative for the logo ✨

License

The MIT License (MIT). Please see License File for more information.

watheqalshowaiter/backup-tables 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 38
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

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