binbytes / laravel-model-media-backup
为Laravel中的模型进行媒体备份。
1.0.0
2018-12-15 12:27 UTC
Requires
- php: ^7.0
- illuminate/support: ~5
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3.0
- phpunit/phpunit: ^6.1|~7.0
- sempro/phpunit-pretty-print: ^1.0
This package is auto-updated.
Last update: 2024-09-29 05:08:39 UTC
README
备份与任何模型关联的新增媒体,而不是每天进行完整备份。
如果您的模型中有大量媒体/附件,但每天备份所有媒体目录可能不是最佳选择,则此包将非常有用。
BinBytes是印度拉杰科特的网络和移动应用开发公司。您可以在我们的网站上找到我们所有服务的概述在这里。
安装
您可以使用composer安装此包:
$ composer require binbytes/laravel-model-media-backup
该包将自动注册自己。
要发布配置文件到config/modelmediabackup.php
,请运行:
php artisan vendor:publish --provider="BinBytes\ModelMediaBackup\ModelMediaBackupServiceProvider"
这将发布一个名为modelmediabackup.php
的文件到您的配置目录,其内容如下:
return [ /* * Models from which you want to take media for backup */ 'models' => [ // Example 'App\User' ], /* * Backup FILESYSTEM_DRIVER name on which you want to take backup */ 'backup_disk' => null, // FILESYSTEM_DRIVER /* * Number of records to be chunk in backup process */ 'chunk_size' => 100, /* * Notification configuration */ 'notification' => [ /* * Email address where you want to receive email alert */ 'mail_to' => null, /* * Here you can specify the notifiable to which the notifications should be sent. The default * * notifiable will use the variables specified in this config file. */ 'notifiable' => \BinBytes\ModelMediaBackup\Notifications\Notifiable::class, 'notifications' => [ \BinBytes\ModelMediaBackup\Notifications\Notifications\MediaBackupSuccessful::class, ], ], ];
用法
安装包并填写配置文件中的值后,您需要设置从哪个模型中获取媒体。
您的Eloquent模型应使用BinBytes\ModelMediaBackup\Traits\HasBackupRecord
特性。
特性包含一个抽象方法backupFiles()
,您必须自己实现。
以下是实现特性的示例
<?php namespace App; use BinBytes\ModelMediaBackup\Traits\HasBackupRecords; use Illuminate\Database\Eloquent\Model; class YourEloquentModel extends Model { use HasBackupRecords; /** * Media file associated with record * @return string|array */ public function backupFiles() { return $this->path(); // Full path of your media file OR array of paths } }
想要根据自己的策略或需求进行记录吗?没问题!默认情况下,将备份昨天的记录。
/** * Select records to processed */ public static function backupRecords() { return self::latest() ->whereDate('created_at', Carbon::yesterday()->toDateString()); }
现在您可以开始备份了,只需运行以下artisan命令即可:
php artisan model:media:backup
要每天运行备份,请将其添加到App\Console\Kernel
中
$schedule->command('model:media:backup')->daily();
安全性
如果您发现任何与安全相关的问题,请通过作者电子邮件联系,而不是使用问题跟踪器。
致谢
许可证
MIT许可证。有关更多信息,请参阅许可证文件。