Home > other >  How to use backup HDFS data springboot project?
How to use backup HDFS data springboot project?

Time:09-24

I made a springboot project, but the school requires the system based on hadoop, but complex and I won't, so I just want to can only HDFS to back up your data? I am using springboot + Mybatis + MySQL,

(1) springboot how to integrate the HDFS,
(2) how the data backup,


For a small white self-learning ability is very poor, a person at home to write you really pain, beg you support a move bosses, help the younger brother through casually,

CodePudding user response:

HDFS is according to the file storage, cannot be achieved similar to Mysql as the relationship between table and table, moreover
HDFS itself does not apply to update, delete individual records of operation; Update tables in Mysql environment you delete records,
Yes, HDFS cannot be achieved; Depends on you want to use those features of HDFS instead of mysql, but from the usage scenario
Two completely different, there is no alternative.

CodePudding user response:

reference 1st floor response:
HDFS is according to the file storage, cannot be achieved similar to Mysql as the relationship between table and table, moreover
HDFS itself does not apply to update, delete individual records of operation; Update tables in Mysql environment you delete records,
Yes, HDFS cannot be achieved; Depends on you want to use those features of HDFS instead of mysql, but from the usage scenario
Two completely different, there is no alternative.


Students well, my system is to use excel to upload information to mysql, now I just want to let my springboot project can give HDFS uploading files, need not mysql guide to the HDFS, can also upload the excel file, I just want to save a part of data stored in the HDFS, does not need other operations,

CodePudding user response:

(1) springboot how to integrate the HDFS,
First, in pom. Add hadoop - XML client rely on
 

Org. Apache. Hbase
Hbase - client
The ${hbase. Current. Version} & lt;/version>

Write you install Hadoop version, version
Then, in you to define the XML of Bean (suggestion is XML, the most simple), add the following Bean definition:
 






Then, in any Bean (service/dao/controller) can rely on HDFS Bean, HDFS write files below:
 
@ the Resource (name="HDFS")
Private FileSystem HDFS;

Public void uploadToHDFS (File File) {
Try {
Byte buffer []=new byte [1024].
int len;
FSDataOutputStream hdfsFile=HDFS. Create (new Path ("/user/HDFS/" + file. GetName ()));
FileInputStream fis=new FileInputStream(file);

While ((len=fis. Read (4) buffer, 0102).=1) {
HdfsFile. Write (buffer, 0, len);
HdfsFile. Flush ();
}
Fis. Close (); HdfsFile. Close ();
} the catch (Exception e) {
e.printStackTrace();
}
}

(2) how the data backup,
Timing task, just throw file to the HDFS

CodePudding user response:

reference LinkSe7en reply: 3/f
(1) springboot how to integrate the HDFS,
First, in pom. Add hadoop - XML client rely on
 

Org. Apache. Hbase
Hbase - client
The ${hbase. Current. Version} & lt;/version>

Write you install Hadoop version, version
Then, in you to define the XML of Bean (suggestion is XML, the most simple), add the following Bean definition:
 






Then, in any Bean (service/dao/controller) can rely on HDFS Bean, HDFS write files below:
 
@ the Resource (name="HDFS")
Private FileSystem HDFS;

Public void uploadToHDFS (File File) {
Try {
Byte buffer []=new byte [1024].
int len;
FSDataOutputStream hdfsFile=HDFS. Create (new Path ("/user/HDFS/" + file. GetName ()));
FileInputStream fis=new FileInputStream(file);

While ((len=fis. Read (4) buffer, 0102).=1) {
HdfsFile. Write (buffer, 0, len);
HdfsFile. Flush ();
}
Fis. Close (); HdfsFile. Close ();
} the catch (Exception e) {
e.printStackTrace();
}
}

(2) how the data backup,
Timing task, just throw file into HDFS

Rely on to write wrong, is
 

Org. Apache. Hadoop
Hadoop - client
${hadoop, current version} & lt;/version>

CodePudding user response:

Thank you bosses, has been solved
  • Related