| 
					
				 | 
			
			
				@@ -12,6 +12,7 @@ import com.jjt.out.service.IOutMongoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.jjt.out.service.IOutMysqlService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.jjt.out.service.IOutProcessInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.jjt.system.service.ISysConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import net.lingala.zip4j.ZipFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.codec.digest.DigestUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.LoggerFactory; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -42,31 +43,22 @@ public class OutMongoServiceImpl extends OutBaseService implements IOutMongoServ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private IOutProcessInfoService processInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 导出数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public void full() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 增量导出 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 执行备份 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param isInc 是否增量 true:增量 false:全量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public void inc() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void exec(boolean isInc) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String params = sysConfigService.selectConfigByKey("out.mongo.info"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         JSONObject mongoInfo = JSONObject.parseObject(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String host = mongoInfo.getString("host"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String port = mongoInfo.getString("port"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String dir = mongoInfo.getString("dir"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String tmpDir = tmpDIr(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         OutProcessInfo opi = new OutProcessInfo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         opi.setProcessType(SyncType.mongo.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<OutProcessInfo> list = processInfoService.selectOutProcessInfoList(opi); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String time = list.get(0).getProcessKey(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String nowTime = DateUtils.dateTimeNow(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -84,13 +76,18 @@ public class OutMongoServiceImpl extends OutBaseService implements IOutMongoServ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //组装导出命令 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             List<String> commands = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             commands.add("/usr/bin/sh"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            commands.add("mongo-inc-bak.sh"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (isInc) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //增量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                commands.add("mongo-inc-bak.sh"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //全量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                commands.add("mongo-full-bak.sh"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             commands.add(host); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             commands.add(port); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            commands.add(time); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             commands.add(tmpDir); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            LinuxCommand.exec(commands, "/mnt/"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LinuxCommand.exec(commands, dir); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Date et = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             opi.setCostTime(et.getTime() - st.getTime()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -106,14 +103,24 @@ public class OutMongoServiceImpl extends OutBaseService implements IOutMongoServ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //打包目标目录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             File targetDir = new File(tmpDir); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            File zipFile = new File(syncDir + zipName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            CompressZip.zip(targetDir, zipFile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ZipFile zipFile = new ZipFile(syncDir + zipName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             * 获取分卷大小 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String size = sysConfigService.selectConfigByKey("file.split.size"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //GB转换成byte 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            long splitSize = 1024 * 1024 * 1024 * Integer.parseInt(size); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CompressZip.splitZip(targetDir, zipFile, splitSize); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //打包文件--end 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //生成描述json文件--start 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                String descName = syncDir + "sync-70-" + nowTime + ".json"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String descName = syncDir + "sync-78-" + nowTime + ".json"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!isInc) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    //如果是全量,执行顺序要靠前,内网解析时,顺序号77代表全量,78代表增量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    descName = syncDir + "sync-77-" + nowTime + ".json"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.getFile().toPath())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 FileDesc desc = new FileDesc(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 desc.setName(zipName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 desc.setMd5(md5); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -129,4 +136,20 @@ public class OutMongoServiceImpl extends OutBaseService implements IOutMongoServ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 全量备份 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void full() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        exec(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 增量备份 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void inc() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        exec(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |