This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 07578e14d70 Fixed backup path detection and optimized output log file
names (#12454)
07578e14d70 is described below
commit 07578e14d70510a0c3b341cba0e07e6609057d73
Author: CloudWise-Lukemiao <[email protected]>
AuthorDate: Tue May 7 18:56:06 2024 +0800
Fixed backup path detection and optimized output log file names (#12454)
Co-authored-by: luke.miao <[email protected]>
---
distribution/src/assembly/all.xml | 5 +
distribution/src/assembly/cli.xml | 5 +
.../src/assembly/resources/conf/logback-cli.xml | 19 +-
.../cli/src/assembly/resources/tools/backup.bat | 127 ++++++++++++
.../cli/src/assembly/resources/tools/backup.sh | 134 +++++++++++++
.../org/apache/iotdb/tool/IoTDBDataBackTool.java | 223 +++++++++++++++++----
6 files changed, 471 insertions(+), 42 deletions(-)
diff --git a/distribution/src/assembly/all.xml
b/distribution/src/assembly/all.xml
index dd95f2a4e73..5768f197563 100644
--- a/distribution/src/assembly/all.xml
+++ b/distribution/src/assembly/all.xml
@@ -88,6 +88,11 @@
<directory>${maven.multiModuleProjectDirectory}/iotdb-client/cli/src/assembly/resources/tools</directory>
<fileMode>0755</fileMode>
</fileSet>
+ <fileSet>
+ <outputDirectory>conf</outputDirectory>
+
<directory>${maven.multiModuleProjectDirectory}/iotdb-client/cli/src/assembly/resources/conf</directory>
+ <fileMode>0755</fileMode>
+ </fileSet>
<!-- <fileSet>-->
<!-- <outputDirectory>datanode</outputDirectory>-->
<!--
<directory>${maven.multiModuleProjectDirectory}/distribution/target/apache-iotdb-${project.version}-all-bin/apache-iotdb-${project.version}-all-bin/datanode</directory>-->
diff --git a/distribution/src/assembly/cli.xml
b/distribution/src/assembly/cli.xml
index 701b1bfa50f..0258de92a24 100644
--- a/distribution/src/assembly/cli.xml
+++ b/distribution/src/assembly/cli.xml
@@ -42,6 +42,11 @@
<directory>${maven.multiModuleProjectDirectory}/iotdb-client/cli/src/assembly/resources/sbin</directory>
<fileMode>0755</fileMode>
</fileSet>
+ <fileSet>
+ <outputDirectory>conf</outputDirectory>
+
<directory>${maven.multiModuleProjectDirectory}/iotdb-client/cli/src/assembly/resources/conf</directory>
+ <fileMode>0755</fileMode>
+ </fileSet>
<fileSet>
<outputDirectory>tools</outputDirectory>
<directory>${maven.multiModuleProjectDirectory}/iotdb-client/cli/src/assembly/resources/tools</directory>
diff --git a/iotdb-client/cli/src/assembly/resources/conf/logback-cli.xml
b/iotdb-client/cli/src/assembly/resources/conf/logback-cli.xml
index 1f80786a9c5..78fa22572f0 100644
--- a/iotdb-client/cli/src/assembly/resources/conf/logback-cli.xml
+++ b/iotdb-client/cli/src/assembly/resources/conf/logback-cli.xml
@@ -26,7 +26,24 @@
<level>ERROR</level>
</filter>
</appender>
- <root level="error">
+ <appender class="ch.qos.logback.core.rolling.RollingFileAppender"
name="backup">
+ <Encoding>UTF-8</Encoding>
+ <file>${IOTDB_HOME}/logs/log_backup.log</file>
+ <rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+
<fileNamePattern>${IOTDB_HOME}/logs/log-backup-%d{yyyyMMdd}.log.gz</fileNamePattern>
+ <maxHistory>30</maxHistory>
+ </rollingPolicy>
+ <append>true</append>
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <pattern>%d [%t] %-5p %C{25}:%L - %m %n</pattern>
+ <charset>utf-8</charset>
+ </encoder>
+ <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+ <level>INFO</level>
+ </filter>
+ </appender>
+ <root level="all">
<appender-ref ref="stdout"/>
+ <appender-ref ref="backup"/>
</root>
</configuration>
diff --git a/iotdb-client/cli/src/assembly/resources/tools/backup.bat
b/iotdb-client/cli/src/assembly/resources/tools/backup.bat
new file mode 100644
index 00000000000..315fd44e53c
--- /dev/null
+++ b/iotdb-client/cli/src/assembly/resources/tools/backup.bat
@@ -0,0 +1,127 @@
+@REM
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM
+
+@echo off
+setlocal enabledelayedexpansion
+
+if "%OS%" == "Windows_NT" setlocal
+
+pushd %~dp0..
+if NOT DEFINED IOTDB_HOME set IOTDB_HOME=%CD%
+popd
+
+if NOT DEFINED JAVA_HOME goto :err
+
+set JAVA_OPTS=-ea^
+ -DIOTDB_HOME="%IOTDB_HOME%"
+
+SET IOTDB_CONF=%IOTDB_HOME%\conf
+IF EXIST "%IOTDB_CONF%\datanode-env.bat" (
+ CALL "%IOTDB_CONF%\datanode-env.bat" > nul 2>&1
+) ELSE (
+ echo Can't find datanode-env.bat
+)
+
+IF EXIST "%IOTDB_CONF%\iotdb-datanode.properties" (
+ for /f "eol=# tokens=2 delims==" %%i in ('findstr /i "^dn_rpc_port"
+ "%IOTDB_CONF%\iotdb-datanode.properties"') do (
+ set dn_rpc_port=%%i
+ )
+) ELSE (
+ set dn_rpc_port=6667
+)
+
+IF EXIST "%IOTDB_CONF%\iotdb-confignode.properties" (
+ for /f "eol=# tokens=2 delims==" %%i in ('findstr /i "^cn_internal_port"
+ "%IOTDB_CONF%\iotdb-confignode.properties"') do (
+ set cn_internal_port=%%i
+ )
+) ELSE (
+ set cn_internal_port=10710
+)
+
+set "local_iotdb_occupied_ports="
+set "operation_dirs="
+set dn_rpc_port_occupied=0
+set cn_internal_port_occupied=0
+
+for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
+ if %%i==TCP (
+ if %%j==%dn_rpc_port% (
+ if !dn_rpc_port_occupied!==0 (
+ set spid=%%k
+ call :checkIfIOTDBProcess !spid! is_iotdb
+ if !is_iotdb!==1 (
+ set local_iotdb_occupied_ports=%dn_rpc_port%
!local_iotdb_occupied_ports!
+ )
+ )
+
+ ) else if %%j==%cn_internal_port% (
+ if !cn_internal_port_occupied!==0 (
+ set spid=%%k
+ call :checkIfIOTDBProcess !spid! is_iotdb
+ if !is_iotdb!==1 (
+ set local_iotdb_occupied_ports=%cn_internal_port%
!local_iotdb_occupied_ports!
+ )
+ )
+ )
+ )
+)
+
+if defined local_iotdb_occupied_ports (
+ goto :checkFail
+)
+echo ------------------------------------------
+echo Starting IoTDB Client Data Back Script
+echo ------------------------------------------
+
+set CLASSPATH="%IOTDB_HOME%\lib\*"
+if NOT DEFINED MAIN_CLASS set
MAIN_CLASS=org.apache.iotdb.tool.IoTDBDataBackTool
+
+set logsDir="%IOTDB_HOME%\logs"
+if not exist "%logsDir%" (
+ mkdir "%logsDir%"
+)
+
+set IOTDB_CLI_CONF=%IOTDB_HOME%\conf
+set
"iotdb_cli_params=-Dlogback.configurationFile=!IOTDB_CLI_CONF!\logback-cli.xml"
+start /B "" cmd /C "("%JAVA_HOME%\bin\java" -DIOTDB_HOME=!IOTDB_HOME!
!iotdb_cli_params! !JAVA_OPTS! -cp !CLASSPATH! !MAIN_CLASS! %*) > nul 2>&1"
+exit /b
+
+:checkIfIOTDBProcess
+setlocal
+
+set "pid_to_check=%~1"
+set "is_iotdb=0"
+
+for /f "usebackq tokens=*" %%i in (`wmic process where
"ProcessId=%pid_to_check%" get CommandLine /format:list ^| findstr
/c:"CommandLine="`) do (
+ set command_line=%%i
+)
+echo %command_line% | findstr /i /c:"iotdb" >nul && set is_iotdb=1
+endlocal & set "is_iotdb=%is_iotdb%"
+exit /b
+
+:err
+echo JAVA_HOME environment variable must be set!
+set ret_code=1
+exit /b
+
+:checkFail
+echo Please stop IoTDB
+exit /b
\ No newline at end of file
diff --git a/iotdb-client/cli/src/assembly/resources/tools/backup.sh
b/iotdb-client/cli/src/assembly/resources/tools/backup.sh
new file mode 100644
index 00000000000..6d605812825
--- /dev/null
+++ b/iotdb-client/cli/src/assembly/resources/tools/backup.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+echo ------------------------------------------
+echo Starting IoTDB Client Data Back Script
+echo ------------------------------------------
+
+
+if [ -z "${IOTDB_INCLUDE}" ]; then
+ #do nothing
+ :
+elif [ -r "$IOTDB_INCLUDE" ]; then
+ . "$IOTDB_INCLUDE"
+fi
+
+if [ -z "${IOTDB_HOME}" ]; then
+ export IOTDB_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+fi
+
+if [ -n "$JAVA_HOME" ]; then
+ for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
+ if [ -x "$java" ]; then
+ JAVA="$java"
+ break
+ fi
+ done
+else
+ JAVA=java
+fi
+
+if [ -z $JAVA ] ; then
+ echo Unable to find java executable. Check JAVA_HOME and PATH environment
variables. > /dev/stderr
+ exit 1;
+fi
+
+datanodeclassname=org.apache.iotdb.db.service.DataNode
+
+confignodeclassname=org.apache.iotdb.db.service.ConfigNode
+
+check_tool_env() {
+ if ! type lsof > /dev/null 2>&1 ; then
+ echo ""
+ echo " Warning: No tool 'lsof', Please install it."
+ echo " Note: Some checking function need 'lsof'."
+ echo ""
+ return 1
+ else
+ return 0
+ fi
+}
+
+get_properties_value() {
+ local file_name=$1
+ local property_name=$2
+ local default_value=$3
+ local property_value=$(sed "/^${property_name}=/!d;s/.*=//"
"${IOTDB_HOME}/conf/${file_name}.properties")
+ if [ -z "$property_value" ]; then
+ property_value="$default_value"
+ fi
+ echo "$property_value"
+}
+iotdb_listening_ports=()
+check_running_process() {
+ DATANODE="iotdb-datanode"
+ CONFIGNODE="iotdb-confignode"
+ dn_rpc_port=$(get_properties_value $DATANODE "dn_rpc_port" "6667")
+ cn_internal_port=$(get_properties_value $CONFIGNODE "cn_internal_port"
"10710")
+ local_ports+=("$dn_rpc_port")
+ local_ports+=("$cn_internal_port")
+ for port in "${local_ports[@]}"; do
+ # Check if lsof command is available
+ if command -v lsof >/dev/null 2>&1; then
+ listening=$(lsof -i :$port -sTCP:LISTEN -P -n | grep LISTEN)
+ if [ -n "$listening" ]; then
+ process_command=$(echo "$listening" | awk '{print $2}')
+ iotdb_check=$(ps -p "$process_command" -o args= | grep "iotdb")
+ if [ -n "$iotdb_check" ]; then
+ iotdb_listening_ports+=("$port ")
+ fi
+ fi
+ elif command -v netstat >/dev/null 2>&1; then
+ listening=$(netstat -tln | awk '{print $4}' | grep ":$port$")
+ if [ -n "$listening" ]; then
+ process_command=$(echo "$listening" | awk '{print $2}')
+ iotdb_check=$(ps -p "$process_command" -o args= | grep "iotdb")
+ if [ -n "$iotdb_check" ]; then
+ iotdb_listening_ports+=("$port ")
+ fi
+ fi
+ else
+ echo "Error: Unable to detect port occupation. Please install 'lsof'
or 'netstat' command."
+ exit 1
+ fi
+ done
+ if [ ${#iotdb_listening_ports[@]} -gt 0 ]; then
+ echo " Please stop IoTDB" >&2
+ exit 1
+ fi
+}
+
+check_running_process
+
+for f in ${IOTDB_HOME}/lib/*.jar; do
+ CLASSPATH=${CLASSPATH}":"$f
+done
+
+MAIN_CLASS=org.apache.iotdb.tool.IoTDBDataBackTool
+
+logs_dir="${IOTDB_HOME}/logs"
+
+if [ ! -d "$logs_dir" ]; then
+ mkdir "$logs_dir"
+fi
+
+IOTDB_CLI_CONF=${IOTDB_HOME}/conf
+iotdb_cli_params="-Dlogback.configurationFile=${IOTDB_CLI_CONF}/logback-cli.xml"
+exec nohup "$JAVA" -DIOTDB_HOME=${IOTDB_HOME} $iotdb_cli_params -cp
"$CLASSPATH" "$MAIN_CLASS" "$@" 2>&1 > /dev/null <&- &
diff --git
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/IoTDBDataBackTool.java
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/IoTDBDataBackTool.java
index 19388312050..7d3315d1f67 100644
---
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/IoTDBDataBackTool.java
+++
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/IoTDBDataBackTool.java
@@ -66,7 +66,7 @@ public class IoTDBDataBackTool {
static AtomicInteger fileCount = new AtomicInteger(0);
static AtomicInteger targetFileCount = new AtomicInteger(0);
static AtomicInteger processFileCount = new AtomicInteger(0);
- static final String filename = "data.txt";
+ static final String filename = "backup.log";
private static final Logger LOGGER =
LoggerFactory.getLogger(AbstractDataTool.class);
@@ -159,6 +159,7 @@ public class IoTDBDataBackTool {
}
public static void main(String[] args) {
+ System.setProperty("IOTDB_HOME", System.getenv("IOTDB_HOME"));
argsParse(args);
File sourceDir = new File(sourcePath);
Properties dataProperties = getProperties(IoTDBConfig.CONFIG_NAME);
@@ -178,38 +179,83 @@ public class IoTDBDataBackTool {
.append(File.separatorChar)
.append("iotdb_backup");
File targetDir = new File(targetDirString.toString());
- if (!targetDir.exists()) {
- targetDir.mkdirs();
- } else {
+ if (targetDir.exists()) {
LOGGER.error("The backup folder already exists:{}", targetDirString);
System.exit(0);
}
- countConfigNodeFile(targetDirString.toString(), copyMap,
cnMapProperties);
- countDataNodeFile(targetDirString.toString(), copyMap, dnDataDirsMap,
dnMapProperties);
- countNodeBack(targetDirString.toString(), copyMap);
- for (Map.Entry<String, String> entry : copyMap.entrySet()) {
- countFiles(entry.getKey());
- }
- for (Map.Entry<String, String> entry : dnDataDirsMap.entrySet()) {
- countFiles(entry.getKey());
+ if (nodeTypeParam.equalsIgnoreCase("confignode")) {
+ if (!targetDir.exists()) {
+ targetDir.mkdirs();
+ }
+ countConfigNodeFile(targetDirString.toString(), copyMap,
cnMapProperties);
+ countNodeBack(targetDirString.toString(), copyMap);
+ for (Map.Entry<String, String> entry : copyMap.entrySet()) {
+ countFiles(entry.getKey());
+ }
+
+ ioTDBDataBack(copyMap, dnDataDirsMap);
+ propertiesFileUpdate(
+ targetDirString.toString()
+ + File.separatorChar
+ + "conf"
+ + File.separatorChar
+ + CONFIG_NODE_CONF_NAME,
+ cnMapProperties);
+ } else if (nodeTypeParam.equalsIgnoreCase("datanode")) {
+ countDataNodeFile(targetDirString.toString(), copyMap, dnDataDirsMap,
dnMapProperties);
+ countNodeBack(targetDirString.toString(), copyMap);
+ checkQuickMode(dnDataDirsMap);
+ if (!targetDir.exists()) {
+ targetDir.mkdirs();
+ }
+ for (Map.Entry<String, String> entry : copyMap.entrySet()) {
+ countFiles(entry.getKey());
+ }
+ for (Map.Entry<String, String> entry : dnDataDirsMap.entrySet()) {
+ countFiles(entry.getKey());
+ }
+
+ ioTDBDataBack(copyMap, dnDataDirsMap);
+ propertiesFileUpdate(
+ targetDirString.toString()
+ + File.separatorChar
+ + "conf"
+ + File.separatorChar
+ + DATA_NODE_CONF_NAME,
+ dnMapProperties);
+ } else if (nodeTypeParam.equalsIgnoreCase("all") ||
nodeTypeParam.isEmpty()) {
+ countConfigNodeFile(targetDirString.toString(), copyMap,
cnMapProperties);
+ countDataNodeFile(targetDirString.toString(), copyMap, dnDataDirsMap,
dnMapProperties);
+ countNodeBack(targetDirString.toString(), copyMap);
+ checkQuickMode(dnDataDirsMap);
+ if (!targetDir.exists()) {
+ targetDir.mkdirs();
+ }
+ for (Map.Entry<String, String> entry : copyMap.entrySet()) {
+ countFiles(entry.getKey());
+ }
+ for (Map.Entry<String, String> entry : dnDataDirsMap.entrySet()) {
+ countFiles(entry.getKey());
+ }
+
+ ioTDBDataBack(copyMap, dnDataDirsMap);
+ propertiesFileUpdate(
+ targetDirString.toString()
+ + File.separatorChar
+ + "conf"
+ + File.separatorChar
+ + CONFIG_NODE_CONF_NAME,
+ cnMapProperties);
+ propertiesFileUpdate(
+ targetDirString.toString()
+ + File.separatorChar
+ + "conf"
+ + File.separatorChar
+ + DATA_NODE_CONF_NAME,
+ dnMapProperties);
}
- ioTDBDataBack(copyMap, dnDataDirsMap);
- propertiesFileUpdate(
- targetDirString.toString()
- + File.separatorChar
- + "conf"
- + File.separatorChar
- + CONFIG_NODE_CONF_NAME,
- cnMapProperties);
- propertiesFileUpdate(
- targetDirString.toString()
- + File.separatorChar
- + "conf"
- + File.separatorChar
- + DATA_NODE_CONF_NAME,
- dnMapProperties);
} else {
if (targetDirParam != null && targetDirParam.length() > 0) {
targetDirString.append(targetDirParam);
@@ -225,6 +271,7 @@ public class IoTDBDataBackTool {
for (Map.Entry<String, String> entry : copyMap.entrySet()) {
countFiles(entry.getKey());
}
+ isDirectoryInsideOrSame(copyMap);
ioTDBDataBack(copyMap, dnDataDirsMap);
propertiesFileUpdate(
targetDirString.toString()
@@ -236,12 +283,15 @@ public class IoTDBDataBackTool {
} else if (nodeTypeParam.equalsIgnoreCase("datanode")) {
countNodeBack(targetDirString.toString(), copyMap);
countDataNodeFile(targetDirString.toString(), copyMap, dnDataDirsMap,
dnMapProperties);
+
for (Map.Entry<String, String> entry : copyMap.entrySet()) {
countFiles(entry.getKey());
}
for (Map.Entry<String, String> entry : dnDataDirsMap.entrySet()) {
countFiles(entry.getKey());
}
+ isDirectoryInsideOrSame(copyMap);
+ isDirectoryInsideOrSame(dnDataDirsMap);
ioTDBDataBack(copyMap, dnDataDirsMap);
propertiesFileUpdate(
targetDirString.toString()
@@ -260,6 +310,10 @@ public class IoTDBDataBackTool {
for (Map.Entry<String, String> entry : dnDataDirsMap.entrySet()) {
countFiles(entry.getKey());
}
+
+ isDirectoryInsideOrSame(copyMap);
+ isDirectoryInsideOrSame(dnDataDirsMap);
+
ioTDBDataBack(copyMap, dnDataDirsMap);
propertiesFileUpdate(
targetDirString.toString()
@@ -281,6 +335,60 @@ public class IoTDBDataBackTool {
delFile(filename);
}
+ private static void checkQuickMode(Map<String, String> dnDataDirsMap) {
+ for (Map.Entry<String, String> entry : dnDataDirsMap.entrySet()) {
+ File backupDir = new File(entry.getValue());
+ if (backupDir.exists()) {
+ LOGGER.error("The backup folder already exists:{}", entry.getValue());
+ System.exit(0);
+ }
+ }
+ }
+
+ private static void isDirectoryInsideOrSame(Map<String, String> copyMap) {
+ for (Map.Entry<String, String> sourceEntry : copyMap.entrySet()) {
+ for (Map.Entry<String, String> targetEntry : copyMap.entrySet()) {
+ File file = new File(sourceEntry.getKey());
+ if (file.exists()) {
+ Path targetPath = Paths.get(targetEntry.getValue());
+ Path parentPath = Paths.get(sourceEntry.getKey());
+ Path normalizedTargetPath = targetPath.normalize();
+ Path normalizedParentPath = parentPath.normalize();
+ if (normalizedTargetPath.startsWith(normalizedParentPath)
+ || normalizedTargetPath.equals(normalizedParentPath)) {
+ if (targetDirParam.length() > 0
+ && targetDataDirParam.length() > 0
+ && targetWalDirParam.length() > 0) {
+ LOGGER.error(
+ "The directory to be backed up cannot be in the source
directory, please check:{},{},{}",
+ targetDirParam,
+ targetDataDirParam,
+ targetWalDirParam);
+ System.exit(0);
+ } else if (targetDirParam.length() > 0 &&
targetDataDirParam.length() > 0) {
+ LOGGER.error(
+ "The directory to be backed up cannot be in the source
directory, please check:{},{}",
+ targetDirParam,
+ targetDataDirParam);
+ System.exit(0);
+ } else if (targetDirParam.length() > 0 &&
targetWalDirParam.length() > 0) {
+ LOGGER.error(
+ "The directory to be backed up cannot be in the source
directory, please check:{},{}",
+ targetDirParam,
+ targetWalDirParam);
+ System.exit(0);
+ } else if (targetDirParam.length() > 0) {
+ LOGGER.error(
+ "The directory to be backed up cannot be in the source
directory, please check:{}",
+ targetDirParam);
+ System.exit(0);
+ }
+ }
+ }
+ }
+ }
+ }
+
private static void ioTDBDataBack(
Map<String, String> copyMap, Map<String, String> dnDataDirsMap) {
@@ -404,7 +512,16 @@ public class IoTDBDataBackTool {
}
String targetDnDataDirs = "";
if (targetDataDirParam.isEmpty()) {
- targetDnDataDirs =
sourceDnDataDirsCoverTargetDnDataDirsHandler(dnDataDirs);
+ targetDataDirParam =
+ targetDirParam
+ + File.separatorChar
+ + "data"
+ + File.separatorChar
+ + "datanode"
+ + File.separatorChar
+ + "data";
+ targetDnDataDirs = getCreateDnDataPathString(dnDataDirs,
targetDataDirParam, "data");
+ // targetDnDataDirs =
sourceDnDataDirsCoverTargetDnDataDirsHandler(dnDataDirs);
} else {
targetDnDataDirs = getCreateDnDataPathString(dnDataDirs,
targetDataDirParam, "data");
}
@@ -506,7 +623,7 @@ public class IoTDBDataBackTool {
StringBuilder subTargetDataDir = new StringBuilder();
for (int i = 0; i < sourcePathList.length; i++) {
String path = sourcePathList[i];
- path = path + "_back";
+ path = path + "_backup";
if (i == sourcePathList.length - 1) {
subTargetDataDir.append(path);
} else {
@@ -527,7 +644,16 @@ public class IoTDBDataBackTool {
StringBuilder subTargetDataDir = new StringBuilder();
for (int i = 0; i < sourcePathList.length; i++) {
if (i == sourcePathList.length - 1) {
-
subTargetDataDir.append(targetDirs).append(File.separatorChar).append("wal").append(i
+ 1);
+ if (sourcePathList.length == 1) {
+ subTargetDataDir.append(targetDirs);
+ } else {
+ subTargetDataDir
+ .append(targetDirs)
+ .append(File.separatorChar)
+ .append("wal")
+ .append(i + 1);
+ }
+
} else {
subTargetDataDir
.append(targetDirs)
@@ -559,7 +685,9 @@ public class IoTDBDataBackTool {
String[] sourcePathArray = sourcePathsList[i].split(",");
for (int j = 0; j < sourcePathArray.length; j++) {
String newPath = targetPathsList[0];
- if (sourcePathsList.length == 1 && targetPathsList.length == 1) {
+ if (sourcePathsList.length == 1
+ && targetPathsList.length == 1
+ && sourcePathArray.length == 1) {
newPath = newPath + File.separatorChar + dirType;
} else {
newPath = newPath + File.separatorChar + dirType + num;
@@ -583,7 +711,9 @@ public class IoTDBDataBackTool {
if (targetPathArray.length == 1) {
for (int j = 0; j < sourcePathArray.length; j++) {
String newPath = "";
- if (sourcePathsList.length == 1 && targetPathsList.length == 1) {
+ if (sourcePathsList.length == 1
+ && targetPathsList.length == 1
+ && sourcePathArray.length == 1) {
newPath = targetPathArray[0] + File.separatorChar + dirType;
} else {
newPath = targetPathArray[0] + File.separatorChar + dirType +
num;
@@ -630,7 +760,9 @@ public class IoTDBDataBackTool {
String[] sourcePathArray = sourcePathsList[i].split(",");
for (int j = 0; j < sourcePathArray.length; j++) {
String newPath = targetPathsList[0];
- if (sourcePathsList.length == 1 && targetPathsList.length == 1) {
+ if (sourcePathsList.length == 1
+ && targetPathsList.length == 1
+ && sourcePathArray.length == 1) {
newPath = newPath + File.separatorChar + dirType;
} else {
newPath = newPath + File.separatorChar + dirType + num;
@@ -649,7 +781,9 @@ public class IoTDBDataBackTool {
if (targetPathArray.length == 1) {
for (int j = 0; j < sourcePathArray.length; j++) {
String newPath = "";
- if (sourcePathsList.length == 1 && targetPathsList.length == 1) {
+ if (sourcePathsList.length == 1
+ && targetPathsList.length == 1
+ && sourcePathArray.length == 1) {
newPath = targetPathArray[0] + File.separatorChar + dirType;
} else {
newPath = targetPathArray[0] + File.separatorChar + dirType +
num;
@@ -771,7 +905,10 @@ public class IoTDBDataBackTool {
if (processFileCount.get() > targetFileCount.get()) {
writeFileData(filename, processFileCount.get());
LOGGER.info(
- "total file number:" + fileCount + ",backup file number:"
+ processFileCount);
+ "total file number:"
+ + fileCount
+ + ",verify the number of files:"
+ + targetFileCount);
} else {
writeFileData(filename, targetFileCount.get());
LOGGER.info(
@@ -825,12 +962,12 @@ public class IoTDBDataBackTool {
try {
Files.createLink(targetFile, file);
} catch (UnsupportedOperationException | IOException e) {
- LOGGER.error("link file error {}", sourceDirectory, e);
+ LOGGER.error("link file error {}", e);
try {
Files.copy(file, targetFile,
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException ex) {
targetFileCount.decrementAndGet();
- LOGGER.error("copy file error {}", sourceDirectory, ex);
+ LOGGER.error("copy file error {}", ex);
}
}
}
@@ -838,8 +975,10 @@ public class IoTDBDataBackTool {
if (processFileCount.get() > targetFileCount.get()) {
writeFileData(filename, processFileCount.get());
LOGGER.info(
- "total file number:" + fileCount + ",backup file number:"
+ processFileCount);
-
+ "total file number:"
+ + fileCount
+ + ",verify the number of files:"
+ + targetFileCount);
} else {
writeFileData(filename, targetFileCount.get());
LOGGER.info(
@@ -942,10 +1081,10 @@ public class IoTDBDataBackTool {
}
public static int readFileData(String filename) {
- Path filePath = Paths.get(filename);
+ filename = sourcePath + File.separatorChar + "logs" + File.separatorChar +
filename;
createFile(filename);
-
try {
+ Path filePath = Paths.get(filename);
List<String> lines = Files.readAllLines(filePath,
StandardCharsets.UTF_8);
if (!lines.isEmpty()) {
return Integer.parseInt(lines.get(0));
@@ -957,6 +1096,7 @@ public class IoTDBDataBackTool {
}
public static void delFile(String filename) {
+ filename = sourcePath + File.separatorChar + "logs" + File.separatorChar +
filename;
File file = new File(filename);
if (file.exists()) {
file.delete();
@@ -964,6 +1104,7 @@ public class IoTDBDataBackTool {
}
public static void writeFileData(String filename, int data) {
+ filename = sourcePath + File.separatorChar + "logs" + File.separatorChar +
filename;
Path filePath = Paths.get(filename);
try {
Files.write(filePath,
Integer.toString(data).getBytes(StandardCharsets.UTF_8));