简体   繁体   English

Hadoop:如何将HDFS文件从一个目录移动到另一目录?

[英]Hadoop: How to move HDFS files in one directory to another directory?

I have an HDFS soure directory, and a destination archive directory in HDFS. 我在HDFS中有一个HDFS源目录和一个目标存档目录。 At the beginning of every run of my job, I need to move (or copy, then delete) all the part files present in my Source directory to my Archive directory. 在每次运行作业的开始,我需要将Source目录中存在的所有零件文件移动(或复制,然后删除)到我的Archive目录中。

SparkSession spark = SparkSession.builder().getOrCreate();
JavaSparkContext jsc = new JavaSparkContext(spark.sparkContext());
String hdfsSrcDir = "hdfs://clusterName/my/source";
String archiveDir = "hdfs://clusterName/my/archive";
try{
    FileSystem fs = FileSystem.get(new URI(hdfsSrcDir ),jsc.hadoopConfiguration());
}

I don't know how to proceed further. 我不知道该如何进一步。 Presently my fs object has reference to only my source directory. 目前,我的fs对象仅引用我的目录。
Creating an fs2 with archive location won't help I believe. 我相信,创建具有存档位置的fs2不会有所帮助。

I have found out about FileSystem.rename() , but that takes filenames as parameters. 我发现了有关FileSystem.rename() ,但这需要使用文件名作为参数。 I need to move /my/source/* to /my/archive/ . 我需要将/my/source/*移至/my/archive/

Check if this will works for you, 检查这是否适合您,

Configuration configuration = new Configuration(); 
configuration.set("fs.defaultFS", "hdfs://xyz:1234"); 
FileSystem filesystem = FileSystem.get(configuration); 
FileUtil.copy(filesystem, new Path("src/path"), 
              filesystem, new Path("dst/path"), false, configuration); 
filesystem.delete(new Path("src/path"), true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Hadoop HDFS目录中移动文件? - How to move files within the Hadoop HDFS directory? 如何在hadoop hdfs中列出目录及其子目录中的所有文件 - How to list all files in a directory and its subdirectories in hadoop hdfs 如何将所有文件从一个目录移动并覆盖到另一个目录? - How to move and overwrite all files from one directory to another? 使用JAVA从HDFS中的一个目录复制到HDFS中的另一个目录 - Copying from one directory in HDFS to another directory in HDFS using JAVA 如何使用java将文件一个目录移动到另一个目录 - How to move file one directory to another directory using in java Java:将文件从一个目录复制/移动到另一个目录的安全方法 - Java: Safe way to copy/move files from one directory to another 如何根据Spring Integration中的某些验证将文件从一个目录移动到另一个目录? - how to move files from one directory to another depending on some validations in spring integration? 如何在HDFS Hadoop(Cloudera)Java中制作目录文件 - How make directory to file in HDFS Hadoop (Cloudera) java java如何将不同的子目录和文件移动到一个目录 - how to move different sub directories and files in to one directory in java 如何将文件从一个目录移动到另一个目录 - How can move file from one directory to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM