s3distcp 在单个命令中将文件和目录从 HDFS 复制到 S3

sas*_*hmi 1 amazon-s3 s3distcp

我在 HDFS 中有以下 2 个文件和 1 个目录。

-rw-r--r-- 1 hadoop hadoop 11194859 2017-05-05 19:53 hdfs:///outputfiles/abc_output.txt
drwxr-xr-x - hadoop hadoop 0 2017-05-05 19:28 hdfs:///outputfiles/sample_directory
-rw-r--r-- 1 hadoop hadoop 68507436 2017-05-05 19:55 hdfs:///outputfiles/sample_output.txt

I want to copy abc_output.txt and sample_directory in gzip format onto S3 from HDFS in a single command. I don't want the files to be combined on S3.

My S3 bucket should contain the following: abc_output.txt.gzip sample_directory.gzip

I tried the following:

s3-dist-cp --s3Endpoint=s3.amazonaws.com --src=hdfs:///outputfiles/ --dest=s3://bucket-name/outputfiles/ --outputCodec=gzip

But this copies all files and folders from source to destination.

By referring Deduce the HDFS path at runtime on EMR , I also tried the below command:

s3-dist-cp --s3Endpoint=s3.amazonaws.com --src=hdfs:///outputfiles/ --dest=s3://bucket-name/outputfiles/ --srcPattern=.*abc_output.txt.sample_directory. --outputCodec=gzip but this failed.

jc *_*nem 5

S3DistCp 支持两种关于如何压缩从源到目标的复制数据的选项。--srcPattern --groupBy http://docs.aws.amazon.com/emr/latest/ReleaseGuide/UsingEMR_s3distcp.html

关于可以做什么,文档是不言而喻的。其余的..无法完成。

使用 srcPattern ,您可以编写与源文件匹配的正则表达式。s3distcp 只会将那些匹配的文件单独复制到目标中。

例如:--srcPattern='.*(txt|sample_folder).*'将复制所有具有txt扩展名的文件&它将在目标中创建匹配的目录以将具有名称的源文件夹中的文件复制sample_folder到目标

http://regexr.com/3ftn0 (您可以根据您的要求设计 ReGex。)

如果--outputCodec=gzip 除 之外还应用选项,--srcPattern则将相应地压缩单个匹配的文件。它们不会被整体压缩。如果您需要将所有匹配的文件压缩到一个单独的文件中(不连接其内容),那么您将分别运行 s3-dist-cp 和压缩命令输出。

如果要将文件 abc_output.txt 和 sample_directory 中的所有文件连接成一个文件并以 gzip 格式压缩它,则需要使用 --groupBy。对于使用 groupby ,匹配的正则表达式模式应该是相似的,您需要在正则表达式中有一个括号,指示文件应该如何分组,与括号语句匹配的所有项目被组合到一个输出文件中。

例如 :

--groupBy='.*(file|noname).*[0-9].*' --outputCodec=gz 
Run Code Online (Sandbox Code Playgroud)

http://regexr.com/3ftn9 上将连接所有匹配的文件内容并创建一个 .gz 文件