sykez / laravel-storage-copy
Laravel Artisan 命令,用于在 Laravel 文件系统/存储磁盘之间复制文件。
v1.2.0
2022-03-08 15:06 UTC
Requires
- php: ^7.4 || ^8.0
- illuminate/console: 5.5 - 9
- illuminate/filesystem: 5.5 - 9
- illuminate/log: 5.5 - 9
- illuminate/support: 5.5 - 9
- league/flysystem: ~1.0 || ^3.0
- league/flysystem-aws-s3-v3: ~1.0 || ^3.0
README
Laravel Artisan 命令,用于在 Laravel 文件系统/存储磁盘之间复制文件。
安装
composer require sykez/laravel-storage-copy
用法
storage:copy [options] [--] <source> <destination>
参数
source Name of the Filesystem disk you want to copy from
destination Name of the Filesystem disk you want to copy to
选项
-d, --delete Delete files on destination disk which aren't on the source disk
-o, --overwrite If files already exist on destination disk, overwrite them instead of skip
-nv, --novisibility Skip getting visibilty on the source
-x, --exclude Regex filter for excluding files
-l, --log Log all actions into Laravel log
-O, --output Output all actions
示例
-
复制
public
磁盘到s3
。默认情况下,如果修改时间相同,则跳过现有文件。php artisan storage:copy public s3
-
将
s3
磁盘复制到custom
。使用delete
选项将删除目标磁盘(custom
)上不在源磁盘(s3
)上的任何文件。overwrite
选项会在目标磁盘上存在文件时覆盖它们,而不是跳过。php artisan storage:copy --delete --overwrite s3 custom
-
从 S3 存储桶复制到另一个 S3 存储桶
由于 Laravel 默认只有一个 S3 磁盘,为了将一个存储桶复制到另一个存储桶,需要将另一个磁盘添加到config/filesystems.php
'disks' => [ // ... other disks 'another-s3' => [ 'driver' => 's3', 'key' => env('ANOTHER_AWS_ACCESS_KEY_ID'), 'secret' => env('ANOTHER_AWS_SECRET_ACCESS_KEY'), 'region' => env('ANOTHER_AWS_DEFAULT_REGION'), 'bucket' => env('ANOTHER_AWS_BUCKET'), 'url' => env('ANOTHER_AWS_URL'), ], ],
将新磁盘的详细信息(
ANOTHER_AWS
)添加到.env
后,现在可以将s3
磁盘复制到another-s3
磁盘。php artisan storage:copy -od s3 another-s3
-
使用
log
选项将所有对文件执行的操作记录到 Laravel 的日志中,而使用debug
选项则将这些操作输出到控制台。php artisan storage:copy --log --output s3 rackspace