diff options
| author | shizhendong <[email protected]> | 2022-08-16 18:00:04 +0800 |
|---|---|---|
| committer | shizhendong <[email protected]> | 2022-08-16 18:00:04 +0800 |
| commit | 2de607aa2ce8a6c0696e8a3f9c057a6b6a389af5 (patch) | |
| tree | a1e559de79a668ad8951da4d2d5c8bff1afd8993 | |
| parent | e411eabc2960bba5b9b9a5f4b8720752f5adfe09 (diff) | |
fix: NEZ-2132 nz-agent rpm -U 升级支持还原组件配置文件rel-22.07.04
1. 在 rpm -U 升级时 备份 prometheus,loki 等配置文件,待升级完成后,恢复配置文件
| -rw-r--r-- | tools/afterinstall.sh | 46 | ||||
| -rw-r--r-- | tools/beforeinstall.sh | 47 |
2 files changed, 82 insertions, 11 deletions
diff --git a/tools/afterinstall.sh b/tools/afterinstall.sh index 066e946..26abb8c 100644 --- a/tools/afterinstall.sh +++ b/tools/afterinstall.sh @@ -150,6 +150,23 @@ compareMD5(){ fi } +# 还原配置文件 +# $1 需要还原的文件目录 /opt/nezha/nz-agent/config /opt/nezha/nz-agent/prometheus ... +# $2 备份文件目录 /tmp/nezha/nz-agent/config /tmp/nezha/nz-agent/prometheus ... +restoreComponentConfig(){ + if [ ! -d $1 ] || [ ! -d $2 ];then + echo "Directory does not exist" + return 1 + fi + + for i in $(ls $2);do + if [ 1 -eq `compareMD5 $1/$i $2/$i` ];then + echo 'return config file '$1/${i} + cp -f $2/$i $1/$i + fi + done +} + # Find Java if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then JAVA_EXE="$JAVA_HOME/bin/java" @@ -221,14 +238,27 @@ if [ 2 -eq $1 ];then TMP_PATH=/tmp/nezha/nz-agent echo 'move backup config file...' if [ -d $TMP_PATH ];then - for i in $(ls $AGENT_PATH/config);do - if [ 1 -eq `compareMD5 $AGENT_PATH/config/$i $TMP_PATH/config/$i` ];then - echo 'return config file '${i} - #mv -f $AGENT_PATH/config/$i $AGENT_PATH/config/$i - cp -f $TMP_PATH/config/$i $AGENT_PATH/config/$i - #cat $AGENT_PATH/config/token.auth'.oldconfig' > $AGENT_PATH/config/token.auth && rm -f $AGENT_PATH/config/token.auth'.oldconfig' - fi - done + #for i in $(ls $AGENT_PATH/config);do + # if [ 1 -eq `compareMD5 $AGENT_PATH/config/$i $TMP_PATH/config/$i` ];then + # echo 'return config file '${i} + # #mv -f $AGENT_PATH/config/$i $AGENT_PATH/config/$i + # cp -f $TMP_PATH/config/$i $AGENT_PATH/config/$i + # #cat $AGENT_PATH/config/token.auth'.oldconfig' > $AGENT_PATH/config/token.auth && rm -f $AGENT_PATH/config/token.auth'.oldconfig' + # fi + #done + + # nz-agent config + restoreComponentConfig $AGENT_PATH/config $TMP_PATH/config + # blackbox_exporter + restoreComponentConfig $AGENT_PATH/blackbox_exporter $TMP_PATH/blackbox_exporter + # snmp_exporter + restoreComponentConfig $AGENT_PATH/snmp_exporter $TMP_PATH/snmp_exporter + # cortex + restoreComponentConfig $AGENT_PATH/cortex $TMP_PATH/cortex + # loki + restoreComponentConfig $AGENT_PATH/loki $TMP_PATH/loki + # prometheus + restoreComponentConfig $AGENT_PATH/prometheus $TMP_PATH/prometheus fi # restart all components diff --git a/tools/beforeinstall.sh b/tools/beforeinstall.sh index 08d9795..57c60ae 100644 --- a/tools/beforeinstall.sh +++ b/tools/beforeinstall.sh @@ -6,11 +6,52 @@ AGENT_PATH=/opt/nezha/nz-agent TMP_PATH=/tmp/nezha/nz-agent # 备份配置 +# nz-agent if [ -d $AGENT_PATH/config ];then - rm -rf $TMP_PATH - mkdir -p $TMP_PATH + rm -rf $TMP_PATH/config + mkdir -p $TMP_PATH/config cp -rf $AGENT_PATH/config $TMP_PATH - echo 'backup config file from '${AGENT_PATH} + echo 'backup config file from '${AGENT_PATH}/config +fi + +# blackbox_exporter +if [ -d $AGENT_PATH/blackbox_exporter ];then + rm -rf $TMP_PATH/blackbox_exporter + mkdir -p $TMP_PATH/blackbox_exporter + cp -rf $AGENT_PATH/blackbox_exporter/{config.conf,blackbox.yml} $TMP_PATH/blackbox_exporter + echo 'backup config file from '${AGENT_PATH}/blackbox_exporter +fi + +# snmp_exporter +if [ -d $AGENT_PATH/snmp_exporter ];then + rm -rf $TMP_PATH/snmp_exporter + mkdir -p $TMP_PATH/snmp_exporter + cp -rf $AGENT_PATH/snmp_exporter/{config.conf,snmp.yml} $TMP_PATH/snmp_exporter + echo 'backup config file from '${AGENT_PATH}/snmp_exporter +fi + +# cortex +if [ -d $AGENT_PATH/cortex ];then + rm -rf $TMP_PATH/cortex + mkdir -p $TMP_PATH/cortex + cp -rf $AGENT_PATH/cortex/{config.conf,cortex.yml,rule.yml} $TMP_PATH/cortex + echo 'backup config file from '${AGENT_PATH}/cortex +fi + +# loki +if [ -d $AGENT_PATH/loki ];then + rm -rf $TMP_PATH/loki + mkdir -p $TMP_PATH/loki + cp -rf $AGENT_PATH/loki/{config.conf,loki.yml} $TMP_PATH/loki + echo 'backup config file from '${AGENT_PATH}/loki +fi + +# prometheus +if [ -d $AGENT_PATH/prometheus ];then + rm -rf $TMP_PATH/prometheus + mkdir -p $TMP_PATH/prometheus + cp -rf $AGENT_PATH/prometheus/{config.conf,prometheus.yml,rule.yml} $TMP_PATH/prometheus + echo 'backup config file from '${AGENT_PATH}/prometheus fi # 停止服务并卸载 |
