Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions distribution/src/assembly/all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>-->
Expand Down
5 changes: 5 additions & 0 deletions distribution/src/assembly/cli.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
19 changes: 18 additions & 1 deletion iotdb-client/cli/src/assembly/resources/conf/logback-cli.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
127 changes: 127 additions & 0 deletions iotdb-client/cli/src/assembly/resources/tools/backup.bat
Original file line number Diff line number Diff line change
@@ -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
134 changes: 134 additions & 0 deletions iotdb-client/cli/src/assembly/resources/tools/backup.sh
Original file line number Diff line number Diff line change
@@ -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 <&- &
Loading