将 70 万个文件移动到同一 FS 内的单个目录时,设备上没有剩余空间

Ali*_*tan 5 find disk-usage mv

我使用以下命令在我的服务器上查找和移动大量文件:

find SomeDir/ -maxdepth 10 -type f -mtime +90 -exec mv {} SomeDir2/ \;
Run Code Online (Sandbox Code Playgroud)

移动大约 700,000 个文件后,我收到此错误:

mv: cannot move ‘SomeDir/Dir1/Dir2/Dir3/file.jpg.gz’ to ‘SomeDir2/file.jpg.gz’: No space left on device
Run Code Online (Sandbox Code Playgroud)

df -i 有以下结果:

/dev/sdb1           322125824 144163358 177962466   45% /files
Run Code Online (Sandbox Code Playgroud)

df -h 有以下结果:

/dev/sdb1            4.8T  3.5T  1.1T   78%   /files
Run Code Online (Sandbox Code Playgroud)

我做所有的操作/files,没有其他目录

文件系统是ext4.

更新

按照建议我跑dmesg -Hwx,输出是EXT4-fs warning (device sdb1): ext4_dx_add_entry:2016: Directory index full!

Mar*_*ler 3

max_dir_size_kb您可能在目录挂载时超出设置(或保留默认值):

Linux 文档

max_dir_size_kb=n
    This limits the size of the directories so that any
    attempt to expand them beyond the specified limit in
    kilobytes will cause an ENOSPC error. This is useful in
    memory-constrained environments, where a very large
    directory can cause severe performance problems or even
    provoke the Out Of Memory killer. (For example, if there
    is only 512 MB memory available, a 176 MB directory may
    seriously cramp the system's style.)
Run Code Online (Sandbox Code Playgroud)

(翻译为ENOSPC错误消息)No space left on deviceperror

因此,请确保在安装时未指定该选项(或指定了一个非常大的数字)。

另外,备注:

  • 一个文件夹中的文件太多听起来不是一个好主意。您可能想要一个关系数据库吗?对象存储?
  • 4.8 TB:这对于现代硬盘来说并不罕见,但老实说,下次在当今时代设置某些东西时,请使用像 LVM 这样的存储池。这样你就可以获得诸如实时系统快照之类的东西。

  • 您的测试用例在第二次安装之前执行“cd /tmp/mymount”,因此您将在“/tmp”文件系统中创建这些文件。 (2认同)