Parcourir la source

采集数据增量备份调整

chenwen il y a 1 an
Parent
commit
9de7740477

+ 3 - 2
src/main/java/com/hb/proj/sys/service/DBBackupService.java

@@ -173,7 +173,8 @@ public class DBBackupService {
 	 * @param sql
 	 * @param args
 	 */
-	public void createBackup(String sql,Object... args) {
-		dao.exeUpdate(sql,args);
+	public void createBackup(String sql) {
+		//dao.queryForList(sql,args);
+		dao.getJdbcTemplate().execute(sql);
 	}
 }

+ 11 - 5
src/main/java/com/hb/proj/sysbackup/service/BackupIncreaseTask.java

@@ -68,7 +68,7 @@ public class BackupIncreaseTask implements Runnable {
 				
 				prlog=service.getLastBackup(log.getTaskName());
 				
-				service.createBackup(buildSQL(tab,log.getBackupFile()),getDataTime(prlog),log.getDataEndTime());
+				service.createBackup(buildSQL(tab,getDataTime(prlog),log.getDataEndTime(),log.getBackupFile()));
 				
 				log.setStatus(BackupLogPO.STAT_SUCCESS);
 				log.setEndTime(new Date());
@@ -88,26 +88,32 @@ public class BackupIncreaseTask implements Runnable {
 		
 	}
 	
-	private String buildSQL(String tab,String saveFile) {
+	private String buildSQL(String tab,Date startTime,Date endTime,String saveFile) {
 		String[] tabField=tab.split(":");
 		StringBuilder sql=new StringBuilder();
 		sql.append("select * from "+tabField[0]);
-		sql.append(" where "+tabField[1]+" > ?  and   "+tabField[1]+"<=? into outfile="+saveFile);
+		sql.append(" where "+tabField[1]+" > '"+DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss")+"'  and   "+tabField[1]+" <= '"+DateUtil.format(endTime, "yyyy-MM-dd HH:mm:ss")+"' into outfile '"+saveFile+"'");
 		return sql.toString();
 	}
 	
 	private BackupLogPO buildLog(String tab) throws IOException {
 		tab=tab.split(":")[0];
-		String fileName=sche.getScheduleName()+"["+tab+"]";
+		String fileName="["+tab+"]";  //sche.getScheduleName()+"["+tab+"]";
 		
 		BackupLogPO  backupLog=new BackupLogPO(fileName,sche.getScheduleId(),BackupLogPO.STAT_RUNNING);
 		
 		String path=properties.getSavePath();
-		if(!path.endsWith(File.separator)) {
+		
+		//sql语句中的分隔符特殊处理
+		
+		/*if(!path.endsWith(File.separator)) {
 			path+=File.separator;
         }
 		
 		path+=DateUtil.format(new Date(), "yyyyMM")+File.separator;
+		*/
+		
+		path+="\\\\"+DateUtil.format(new Date(), "yyyyMM")+"\\\\";
 		
 		FileUtils.forceMkdir(new File(path));