使用 bash 脚本压缩 hadoop 中的不同目录

Zip different directories in hadoop using bash script

我在 hadoop 中有一个位置,其中有不同的目录,如 dir1 dir2 等。我需要将这些不同的目录压缩为不同的 zip 文件。

我使用了以下脚本,但它不起作用。

for d in ${directory_to_move_files}/*/ ;

do
    echo "$d" ;
//zip the folders printed in echo

done

谁能指出正确的做法。

简单的解决方案是使用 hadoop fs -copyToLocal 转到本地 linux 文件夹的父目录,您要在其中执行并通过保存在 shell 脚本中执行以下操作 查看 FileSystem 命令 reference.

#!/bin/bash
for eachindex in */; do zip -r "${eachindex%/}.zip" "$eachindex"; done

据我了解,您的问题具有深刻的洞察力(不仅仅是 unix bash 命令和 shell 脚本)并且您只想在 hadoop 环境中使用 zip 而不是将其复制到本地 unix/linux 文件系统。

我对此进行了研究,我发现的唯一方法是使用 FUSE aka (Filesystem in Userspace) interface into HDFS 另见 MountableHDFS

我不知道它对你来说可行到什么程度。在我们的实现中,我通过将 hdfs 文件复制到本地文件系统并执行 shell 个脚本来完成。

find ${directory_to_move_files}/* -maxdepth 1 -type d -exec zip -r {}.zip {} \;