MCPcopy Create free account
hub / github.com/epcdiy/timemachineplus / XCopy

Method XCopy

src/main/java/serviceRun.java:173–247  ·  view source on GitHub ↗
(Backuproot backuproot)

Source from the content-addressed store, hash-verified

171
172
173 private void XCopy(Backuproot backuproot) throws SQLException, IOException {
174 logger.info("Loading File list:"+backuproot.getRootpath());
175 List<String> fileList=new ArrayList<>();
176 Map<String,Long> mapFile=new HashMap<>();
177 loadAllFiles(new File(backuproot.getRootpath()),fileList);
178 logger.info("Loading CurrentFile In Db:"+ backuproot.getId());
179 {
180 String sqlquery = "select id,filepath from tb_backfiles where backuprootid=" + backuproot.getId();
181 ResultSet ret = mysqlHelper.querySql(sqlquery);
182 while(ret!=null&&ret.next())
183 {
184 mapFile.put(ret.getString("filepath"),ret.getLong("id"));
185 }
186 }
187 logger.info("begin xcopy! total:"+ fileList.size());
188 long counter=0;
189 long timestamp=new Date().getTime()/1000;
190 for(String file:fileList)
191 {
192 if(file.indexOf("/.")!=-1||file.indexOf("\\.")!=-1)
193 {
194 //不拷贝.开头的文件夹和文件
195 continue;
196 }
197 counter++;
198 if(new Date().getTime()/1000!=timestamp)
199 {
200 timestamp=new Date().getTime()/1000;
201 System.out.println("copy progress:"+counter*100/fileList.size()+"% "+counter+"/"+fileList.size());
202 }
203 File fileHandle=new File(file);
204 long id=0;
205 if(!mapFile.containsKey(file))
206 {
207 String sqlquery="select * from tb_backfiles where filepath='"+file.replace("\\","\\\\").replace("'","\\'")+"' and backuprootid="+backuproot.getId();
208 //ResultSet ret= mysqlHelper.querySql(sqlquery);
209 //if(ret==null||!ret.next()) {
210 //第一次拷贝,创建档案
211 mysqlHelper.exeSql("insert into tb_backfiles (backuprootid,filepath,versionhistorycnt,lastbackuptime) values (" +
212 backuproot.getId() + ",'" + file.replace("\\","\\\\").replace("'","\\'") + "',0,now())");
213 ResultSet ret= mysqlHelper.querySql(sqlquery);
214 if(ret==null||!ret.next())
215 {
216 logger.error("内部错误!数据库异常,退出...");
217 break;
218 }
219 id=ret.getLong("id");
220 }
221 else
222 {
223 id=mapFile.get(file);
224 }
225 //判断文件是否有修改
226 ResultSet ret=mysqlHelper.querySql("select * from tb_backfilehistory where backupfileid="+id+" order by id desc limit 1");
227 if(ret!=null&&ret.next())
228 {
229 long lastmotify=ret.getLong("motifytime");
230 long filesize=ret.getLong("filesize");

Callers 1

mainMethod · 0.95

Calls 6

loadAllFilesMethod · 0.95
exeCopyMethod · 0.95
beginbackupMethod · 0.95
finishbackupMethod · 0.95
querySqlMethod · 0.80
exeSqlMethod · 0.80

Tested by

no test coverage detected