feat: dectl 增加备份和恢复功能 #6602

This commit is contained in:
xuwei-fit2cloud 2024-02-05 16:19:12 +08:00
parent 5dc2fd913d
commit ceed75c545

View File

@ -36,14 +36,16 @@ function usage() {
echo " ./dectl --help"
echo
echo "Commands: "
echo " status 查看 DATAEASE 服务运行状态"
echo " start 启动 DATAEASE 服务"
echo " stop 停止 DATAEASE 服务"
echo " restart 重启 DATAEASE 服务"
echo " reload 重新加载 DATAEASE 服务"
echo " upgrade 升级 DATAEASE 服务"
echo " clear-images 清理 DATAEASE 旧版本的相关镜像"
echo " version 查看 DATAEASE 版本"
echo " status 查看 DATAEASE 服务运行状态"
echo " start 启动 DATAEASE 服务"
echo " stop 停止 DATAEASE 服务"
echo " restart 重启 DATAEASE 服务"
echo " reload 重新加载 DATAEASE 服务"
echo " upgrade 升级 DATAEASE 服务"
echo " backup 备份 DATAEASE 服务"
echo " restore xxx.tar.gz 还原 DATAEASE 服务"
echo " clear-images 清理 DATAEASE 旧版本的相关镜像"
echo " version 查看 DATAEASE 版本"
}
function _generate_compose_file_args() {
if [[ $DE_INSTALL_MODE != "community" ]];then
@ -323,6 +325,33 @@ function clear_images() {
echo "清理完毕"
fi
}
function backup() {
backup_file_name=dataease-backup-$(date +%Y%m%d)_$(date +%H%M%S).tar.gz
tar --exclude=logs/dataease -zcf $backup_file_name -C $DE_RUNNING_BASE .
if [ $? -ne 0 ]; then
echo "备份失败"
exit 1
else
echo "备份成功,备份文件 : $backup_file_name"
fi
}
function restore() {
if [[ -z $target ]];then
echo "未指定需要恢复的备份文件!"
exit 1
elif [[ -f $target ]];then
service dataease stop
if [[ ! -d $DE_RUNNING_BASE ]];then
mkdir -p $DE_RUNNING_BASE
fi
echo "恢复备份 $target"
tar -zxf $target --directory=$DE_RUNNING_BASE
service dataease start
else
echo "未找到备份文件 $target"
exit 1
fi
}
function main() {
case "${action}" in
status)
@ -343,6 +372,12 @@ function main() {
upgrade)
upgrade
;;
backup)
backup
;;
restore)
restore $target
;;
clear-images)
clear_images
;;