Merge pull request #30241 from taosdata/enh/TS-6164

feat: enhance removal script with command-line options for data retention
This commit is contained in:
WANG Xu 2025-03-18 17:50:47 +08:00 committed by GitHub
commit 5a93f5f61e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 19 deletions

View File

@ -162,9 +162,9 @@ remove_service_of() {
remove_tools_of() { remove_tools_of() {
_tool=$1 _tool=$1
kill_service_of ${_tool} kill_service_of ${_tool}
[ -e "${bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${bin_link_dir}/${_tool} || : [ -L "${bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${bin_link_dir}/${_tool} || :
[ -e "${installDir}/bin/${_tool}" ] && ${csudo}rm -rf ${installDir}/bin/${_tool} || : [ -e "${installDir}/bin/${_tool}" ] && ${csudo}rm -rf ${installDir}/bin/${_tool} || :
[ -e "${local_bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${local_bin_link_dir}/${_tool} || : [ -L "${local_bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${local_bin_link_dir}/${_tool} || :
} }
remove_bin() { remove_bin() {
@ -236,21 +236,56 @@ function remove_data_and_config() {
[ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir} [ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir}
} }
echo function usage() {
echo "Do you want to remove all the data, log and configuration files? [y/n]" echo -e "\nUsage: $(basename $0) [-e <yes|no>]"
read answer echo "-e: silent mode, specify whether to remove all the data, log and configuration files."
remove_flag=false echo " yes: remove the data, log, and configuration files."
if [ X$answer == X"y" ] || [ X$answer == X"Y" ]; then echo " no: don't remove the data, log, and configuration files."
confirmMsg="I confirm that I would like to delete all data, log and configuration files" }
echo "Please enter '${confirmMsg}' to continue"
# main
interactive_remove="yes"
remove_flag="false"
while getopts "e:h" opt; do
case $opt in
e)
interactive_remove="no"
if [ "$OPTARG" == "yes" ]; then
remove_flag="true"
echo "Remove all the data, log, and configuration files."
elif [ "$OPTARG" == "no" ]; then
remove_flag="false"
echo "Do not remove the data, log, and configuration files."
else
echo "Invalid option for -e: $OPTARG"
usage
exit 1
fi
;;
h | *)
usage
exit 1
;;
esac
done
if [ "$interactive_remove" == "yes" ]; then
echo -e "\nDo you want to remove all the data, log and configuration files? [y/n]"
read answer read answer
if [ X"$answer" == X"${confirmMsg}" ]; then if [ X$answer == X"y" ] || [ X$answer == X"Y" ]; then
remove_flag=true confirmMsg="I confirm that I would like to delete all data, log and configuration files"
else echo "Please enter '${confirmMsg}' to continue"
echo "answer doesn't match, skip this step" read answer
if [ X"$answer" == X"${confirmMsg}" ]; then
remove_flag="true"
else
echo "answer doesn't match, skip this step"
fi
fi fi
echo
fi fi
echo
if [ -e ${install_main_dir}/uninstall_${PREFIX}x.sh ]; then if [ -e ${install_main_dir}/uninstall_${PREFIX}x.sh ]; then
if [ X$remove_flag == X"true" ]; then if [ X$remove_flag == X"true" ]; then
@ -260,7 +295,6 @@ if [ -e ${install_main_dir}/uninstall_${PREFIX}x.sh ]; then
fi fi
fi fi
if [ "$osType" = "Darwin" ]; then if [ "$osType" = "Darwin" ]; then
clean_service_on_launchctl clean_service_on_launchctl
${csudo}rm -rf /Applications/TDengine.app ${csudo}rm -rf /Applications/TDengine.app
@ -299,7 +333,6 @@ elif echo $osinfo | grep -qwi "centos"; then
${csudo}rpm -e --noscripts tdengine >/dev/null 2>&1 || : ${csudo}rpm -e --noscripts tdengine >/dev/null 2>&1 || :
fi fi
command -v systemctl >/dev/null 2>&1 && ${csudo}systemctl daemon-reload >/dev/null 2>&1 || true command -v systemctl >/dev/null 2>&1 && ${csudo}systemctl daemon-reload >/dev/null 2>&1 || true
echo echo
echo "${productName} is removed successfully!" echo "${productName} is removed successfully!"

View File

@ -57,7 +57,7 @@ function clean_bin() {
${csudo}rm -f ${bin_link_dir}/${dumpName2} || : ${csudo}rm -f ${bin_link_dir}/${dumpName2} || :
${csudo}rm -f ${bin_link_dir}/${uninstallScript2} || : ${csudo}rm -f ${bin_link_dir}/${uninstallScript2} || :
${csudo}rm -f ${bin_link_dir}/set_core || : ${csudo}rm -f ${bin_link_dir}/set_core || :
[ -f ${bin_link_dir}/${inspect_name} ] && ${csudo}rm -f ${bin_link_dir}/${inspect_name} || : [ -L ${bin_link_dir}/${inspect_name} ] && ${csudo}rm -f ${bin_link_dir}/${inspect_name} || :
if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then
${csudo}rm -f ${bin_link_dir}/${clientName2} || : ${csudo}rm -f ${bin_link_dir}/${clientName2} || :
@ -65,7 +65,7 @@ function clean_bin() {
${csudo}rm -f ${bin_link_dir}/${benchmarkName2} || : ${csudo}rm -f ${bin_link_dir}/${benchmarkName2} || :
${csudo}rm -f ${bin_link_dir}/${dumpName2} || : ${csudo}rm -f ${bin_link_dir}/${dumpName2} || :
${csudo}rm -f ${bin_link_dir}/${uninstallScript2} || : ${csudo}rm -f ${bin_link_dir}/${uninstallScript2} || :
[ -f ${bin_link_dir}/${inspect_name} ] && ${csudo}rm -f ${bin_link_dir}/${inspect_name} || : [ -L ${bin_link_dir}/${inspect_name} ] && ${csudo}rm -f ${bin_link_dir}/${inspect_name} || :
fi fi
} }