|
@@ -60,9 +60,7 @@ public class OutMongoServiceImpl extends OutBaseService implements IOutMongoServ
|
|
|
|
|
|
JSONObject mongoInfo = JSONObject.parseObject(params);
|
|
|
String host = mongoInfo.getString("host");
|
|
|
- int port = mongoInfo.getIntValue("port");
|
|
|
- String user = mongoInfo.getString("user");
|
|
|
- String pass = mongoInfo.getString("pass");
|
|
|
+ String port = mongoInfo.getString("port");
|
|
|
|
|
|
String tmpDir = tmpDIr();
|
|
|
OutProcessInfo opi = new OutProcessInfo();
|
|
@@ -73,49 +71,61 @@ public class OutMongoServiceImpl extends OutBaseService implements IOutMongoServ
|
|
|
String nowTime = DateUtils.dateTimeNow();
|
|
|
|
|
|
tmpDir += "mongo/" + nowTime + "/";
|
|
|
- String queryStr = String.format("{\"ts\":{\"$gt\":{\"$timestamp\":{\"t\":%s,\"i\":1}}},\"op\":{\"$ne\":\"d\"},\"op\":{\"$ne\":\"n\"}}", time);
|
|
|
- String cmd = String.format("/usr/bin/mongodump --host %s --port %s -d local -c oplog.rs -q '%s' -o %s", host, port, queryStr, tmpDir);
|
|
|
- opi = new OutProcessInfo();
|
|
|
- opi.setProcessType(SyncType.mongo.toString());
|
|
|
- Date st = new Date();
|
|
|
- opi.setCreateTime(st);
|
|
|
try {
|
|
|
- LinuxCommand.exec(cmd);
|
|
|
+ //创建目录及父目录
|
|
|
+ Files.createDirectories(Paths.get(tmpDir));
|
|
|
+
|
|
|
+ opi = new OutProcessInfo();
|
|
|
+ opi.setProcessType(SyncType.mongo.toString());
|
|
|
+ Date st = new Date();
|
|
|
+ opi.setCreateTime(st);
|
|
|
+ opi.setProcessKey(String.valueOf(System.currentTimeMillis() / 1000));
|
|
|
+
|
|
|
+ //组装导出命令
|
|
|
+ List<String> commands = new ArrayList<>();
|
|
|
+ commands.add("/usr/bin/sh");
|
|
|
+ commands.add("mongo-inc-bak.sh");
|
|
|
+ commands.add(host);
|
|
|
+ commands.add(port);
|
|
|
+ commands.add(tmpDir);
|
|
|
+
|
|
|
+ LinuxCommand.exec(commands, "/mnt/");
|
|
|
+
|
|
|
+ Date et = new Date();
|
|
|
+ opi.setCostTime(et.getTime() - st.getTime());
|
|
|
+ processInfoService.insertOutProcessInfo(opi);
|
|
|
+
|
|
|
+
|
|
|
+ //获取外网同步正式目录
|
|
|
+ String syncDir = syncDIr();
|
|
|
+
|
|
|
+ //打包文件--start
|
|
|
+ //生成zip文件全路径名
|
|
|
+ String zipName = "sync-mongo-" + time + ".zip";
|
|
|
+
|
|
|
+ //打包目标目录
|
|
|
+ File targetDir = new File(tmpDir);
|
|
|
+ File zipFile = new File(syncDir + zipName);
|
|
|
+ CompressZip.zip(targetDir, zipFile);
|
|
|
+ //打包文件--end
|
|
|
+
|
|
|
+ //生成描述json文件--start
|
|
|
+ try {
|
|
|
+ String descName = syncDir + "sync-70-" + time + ".json";
|
|
|
+ String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath()));
|
|
|
+ FileDesc desc = new FileDesc();
|
|
|
+ desc.setName(zipName);
|
|
|
+ desc.setMd5(md5);
|
|
|
+ desc.setType(SyncType.mongo);
|
|
|
+ File descFile = new File(descName);
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ mapper.writeValue(descFile, desc);
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ //生成描述json文件--end
|
|
|
} catch (Exception e) {
|
|
|
log.error("报错啦:{}", e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- Date et = new Date();
|
|
|
- opi.setCostTime(et.getTime() - st.getTime());
|
|
|
- processInfoService.insertOutProcessInfo(opi);
|
|
|
-
|
|
|
-
|
|
|
- //获取外网同步正式目录
|
|
|
- String syncDir = syncDIr();
|
|
|
-
|
|
|
- //打包文件--start
|
|
|
- //生成zip文件全路径名
|
|
|
- String zipName = "sync-mongo-" + time + ".zip";
|
|
|
-
|
|
|
- //打包目标目录
|
|
|
- File targetDir = new File(tmpDir);
|
|
|
- File zipFile = new File(syncDir + zipName);
|
|
|
- CompressZip.zip(targetDir, zipFile);
|
|
|
- //打包文件--end
|
|
|
-
|
|
|
- //生成描述json文件--start
|
|
|
- try {
|
|
|
- String descName = syncDir + "sync-70-" + time + ".json";
|
|
|
- String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath()));
|
|
|
- FileDesc desc = new FileDesc();
|
|
|
- desc.setName(zipName);
|
|
|
- desc.setMd5(md5);
|
|
|
- desc.setType(SyncType.mongo);
|
|
|
- File descFile = new File(descName);
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- mapper.writeValue(descFile, desc);
|
|
|
- } catch (IOException e) {
|
|
|
- }
|
|
|
- //生成描述json文件--end
|
|
|
}
|
|
|
}
|