当您有几个目录(大约 70 个),每个目录都有很多文件时,s3fs 挂载上的任何递归
chown
或 chmod
命令都需要很长时间。
这些命令中的任何一个都可能需要将近 24 小时。我必须这样做,否则 Apache 进程无法访问这些文件/目录。普通挂载上的命令大约需要 20 秒。
安装方式:
/storage -o noatime -o allow_other -o use_cache=/s3fscache -o default_acl=public-read-write
在
/etc/fuse.conf
:
user_allow_other
使用最新版本:1.78
关于如何更快地做到这一点有什么想法吗?
一段时间后,我发现最好并行处理以加快速度。例子:
find /s3fsmount/path/to/somewhere -print | xargs --max-args=1 --max-procs=100 chmod 777
它仍然很慢,但远没有以前那么慢。
aws cli
可能会有所帮助。
我做什么:
aws cli
获取目标目录的完整文件列表。chmod 777
到每个文件(用> /dev/null 2>&1 &
)然后我发现 chmod 作业立即完成,从
ps -ef
.
我的PHP代码:
<?php
$s3_dir = 'path/to/target/';
$s3fs_dir = '/mnt/s3-drive/' .$s3_dir;
echo 'Fetching file list...' . "\n\n";
sleep(1.5);
$cmd = 'aws s3 ls --recursive s3://<bucket_name>/' . $s3_dir;
exec($cmd, $output, $return);
$num = 0;
if ( is_array($output) ) {
foreach($output as $file_str) {
if ( $num>100 ) {
sleep(4);
$num=0;
}
$n = sscanf( $file_str, "%s\t%s\t%s\t". $s3_dir ."%s", $none1, $none2, $none3, $file );
$cmd = 'chmod 777 ' . $s3fs_dir . $file . ' > /dev/null 2>&1 &';
echo $cmd ."\n";
exec( $cmd );
$num+=1;
}
}
?>
对于更改用户
find /s3fsmount/path/to/somewher -print | xargs --max-args=1 --max-procs=100 sudo chown -R user:user
它对我有用..
这是对 @jafo (https://stackoverflow.com/a/31271219/4867575) 答案的增强,以防只有少数文件需要被关闭: 由于通过 S3FS 更改文件的所有者或组需要重新上传整个文件,这就是为什么它需要非常多的时间(参见:https://stackoverflow.com/a/66080786/4867575)。
当只需要更改几个文件时,您可以只选择需要更改的文件(灵感来自https://stackoverflow.com/a/65218413/4867575):
my_directory=<my_directory>
my_user=<my_user>
my_group=<my_group>
find $my_directory \( ! -user $my_user -o ! -group $my_group \) -print0 | xargs -0 --max-args=1 --max-procs=10 chown -v $my_user:$my_group