|
@@ -163,7 +163,9 @@ public class CreateDatabasesByV3File {
|
|
|
}
|
|
|
// 解析SQL语句,提取数据
|
|
|
String[] data = parseSQLLine(line);
|
|
|
-
|
|
|
+ for (int i = 0; i < data.length; i++) {
|
|
|
+ data[i] = data[i].replace(",", "\\,");
|
|
|
+ }
|
|
|
if (data != null) {
|
|
|
// 将数据以CSV格式写入文件
|
|
|
fileWriterMap.get(tableName).write(String.join(",", data));
|
|
@@ -185,9 +187,12 @@ public class CreateDatabasesByV3File {
|
|
|
if (startIndex == -1 || endIndex == -1) {
|
|
|
return null;
|
|
|
}
|
|
|
- String data = line.substring(startIndex + 1, endIndex).replaceAll("'", "");
|
|
|
-
|
|
|
- return data.replace(", ", ",").replace("\\", "").split(",");
|
|
|
+ String data = line.substring(startIndex + 1, endIndex);
|
|
|
+ String[] b = data.replace("null", "'null'").split("',");
|
|
|
+ for (int i = 0; i < b.length; i++) {
|
|
|
+ b[i] = b[i].replace("'", "").trim();
|
|
|
+ }
|
|
|
+ return b;
|
|
|
}
|
|
|
return null;
|
|
|
|
|
@@ -235,6 +240,10 @@ public class CreateDatabasesByV3File {
|
|
|
String line;
|
|
|
int lineSize = 0;
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
+ //有的导出来的带这个,如果带这个则无法解析,需要处理
|
|
|
+ if (line.contains("ROW_FORMAT=COMPACT")) {
|
|
|
+ line = line.replace("ROW_FORMAT=COMPACT", "");
|
|
|
+ }
|
|
|
if (line.startsWith("Navicat") || line.startsWith("/")
|
|
|
|| line.startsWith("INSERT") || line.startsWith("--") || line.startsWith("#")
|
|
|
|| line.startsWith("//")) {
|
|
@@ -261,8 +270,9 @@ public class CreateDatabasesByV3File {
|
|
|
if (createTable(databasesName, sqlStatements, conn)) {
|
|
|
flag = true;
|
|
|
log.info("执行数据库和数据表创建成功,其中数据共:{}", lineSize);
|
|
|
+ } else {
|
|
|
+ log.info("执行数据库和数据表创建失败,第{}次重复执行", num + 1);
|
|
|
}
|
|
|
- log.info("执行数据库和数据表创建失败,第{}次重复执行", num + 1);
|
|
|
num++;
|
|
|
}
|
|
|
if (num == 2) {
|
|
@@ -294,10 +304,16 @@ public class CreateDatabasesByV3File {
|
|
|
insertData(databasesName, csv);
|
|
|
}
|
|
|
}
|
|
|
- log.info("数据导入完毕!!!");
|
|
|
- //FileUtil.del(sqlPath);
|
|
|
+
|
|
|
FileUtil.del(csvFilePath);
|
|
|
FileUtil.move(f, new File(path + File.separator + "backUps" + DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN) + File.separator + f.getName()), true);
|
|
|
+ try {
|
|
|
+ Runtime.getRuntime().exec("sh /home/dataDump/restart.sh");
|
|
|
+ log.info("重启成功");
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("重启失败");
|
|
|
+ }
|
|
|
+ log.info("数据导入完毕!!!");
|
|
|
}
|
|
|
}
|
|
|
}
|