564 Star 5K Fork 1.5K

GVPdromara / Jpom

 / 详情

[功能建议]: 产物目录能否支持忽略文件

Done
Opened this issue  
2024-02-24 12:48

你的功能建议是否和某个问题相关?

比如:静态文件目录发布传输,配置产物路径为 / ,可能会把 ./git 等无关的文件发布到目标路径。由于大项目 ./git 目录会逐步增大,对于改动频繁的项目可能影响发布效率

建议:可支持文件、文件夹过滤

你希望看到什么解决方案?

1.支持全局配置统一的产物过滤器
2.支持按项目特性配置产物过滤器

你考虑过哪些替代方案?

是否可以借鉴使用 rsync 命令的 方式处理。

rsync -a --exclude-from=/home/www/exclude.txt /home/www/xr/ root@192.168.12.52:/home/www/xr.202311301500/

rsync_192_168_12_52.sh 脚本代码如下:


#!/bin/bash
  
# 定义脚本所在目录的路径  
script_dir=$(cd "$(dirname "$0")" && pwd)  


# 定义默认的exclude_file和include_file  
default_username="root"  
default_server="192.168.12.52"  
default_sources=$(ls $script_dir)  
default_destination="$script_dir/"  
default_exclude_file="$script_dir/exclude.txt"  
default_include_file="$script_dir/include.txt"  

  
#################################################################
####脚本变量定义#################################################
#################################################################

# 移动脚本  
move_script() {  
  read -p "请输入移动路径: " dist_dir  
  mv rsync_*.sh include.txt exclude.txt $dist_dir
}

# 定义主函数  
rsync_files() {  
  read -p "请输入同步的文件(逗号分隔): " key  
  server="$default_server"  
  username="$default_username"
  sources="$default_sources"
  destination="$default_destination"  
  
    
  # 检查必要参数是否提供,否则使用默认值  
  if [[ -z "$server" ]]; then  
    server="$default_server"  
  fi 

  if [[ -z "$username" ]]; then  
    username="$default_username"  
  fi 
  
  # 检查目标目录是否为空,如果是,则设置为当前脚本所在的目录  
  if [[ -z "$sources" ]]; then  
    sources= $(ls $default_sources) 
  fi  
  
  # 检查目标目录是否为空,如果是,则设置为当前脚本所在的目录  
  if [[ -z "$destination" ]]; then  
    destination="$default_destination"  
  fi  
  
  if [[ -z "$exclude_file" ]]; then  
    exclude_file="$default_exclude_file"  
  fi   
    
  if [[ -z "$include_file" ]]; then  
    include_file="$default_include_file"  
  fi  
  
  # 输出信息  
  echo "---------------------------------------------"  
  echo "服务器:$server"  
  echo "用户名:$username"   
  #echo "所有资源:$sources"  
  echo "同步文件:$key"  
  echo "目标目录:$destination"  
  echo "使用 exclude_file 文件: $exclude_file"  
  echo "使用 include_file 文件: $include_file"  
  echo "开始同步至目录..."  
  echo "---------------------------------------------"  
  
  # 检查文件是否存在  
  if [[ ! -f "$exclude_file" ]]; then  
    echo "exclude_file 文件不存在: $exclude_file"  
    exit 1  
  fi  
    
  if [[ ! -f "$include_file" ]]; then  
    echo "include_file 文件不存在: $include_file"  
    exit 1  
  fi  
  
  for source in $sources; do 
	if [ "$source" != "$key" ]; then  
	# 	echo "当前匹配 $script_dir/$key, 当前文件: $source"
		continue  
	fi  

	if [ "$source" == "exclude.txt" ]; then  
		continue  
	fi  
	if [ "$source" == "include.txt" ]; then  
		continue  
	fi  
	if [[ $source =~ rsync_.*.sh ]]; then 
		continue  
	fi   	
	
    echo "当前同步资源文件: $script_dir/$source"  
	# 判断是否为文件  
	if [ -f "$script_dir/$source" ]; then  
		echo "文件:rsync -a --exclude-from=$exclude_file "$script_dir/$source" $username@$server:$destination$source"
		
	#	rsync -a --exclude-from="$exclude_file" \  
	#	"$script_dir/$source" \  
	#	"$username@$server:$destination$source"
	fi  
	  
	# 判断是否为目录  
	if [ -d "$script_dir/$source" ]; then  
		echo "目录:rsync -a --exclude-from=$exclude_file "$script_dir/$source/" $username@$server:$destination$source/"
		
	#	rsync -a --exclude-from="$exclude_file" \  
	#	"$script_dir/$source/" \  
	#	"$username@$server:$destination$source/"
	fi


  done 
}


# 定义主函数  
rsync_all_files() {  
  server="$default_server"  
  username="$default_username"
  sources="$default_sources"
  destination="$default_destination"  
  
    
  # 检查必要参数是否提供,否则使用默认值  
  if [[ -z "$server" ]]; then  
    server="$default_server"  
  fi 

  if [[ -z "$username" ]]; then  
    username="$default_username"  
  fi 
  
  # 检查目标目录是否为空,如果是,则设置为当前脚本所在的目录  
  if [[ -z "$sources" ]]; then  
    sources= $(ls $default_sources) 
  fi  
  
  # 检查目标目录是否为空,如果是,则设置为当前脚本所在的目录  
  if [[ -z "$destination" ]]; then  
    destination="$default_destination"  
  fi  
  
  if [[ -z "$exclude_file" ]]; then  
    exclude_file="$default_exclude_file"  
  fi   
    
  if [[ -z "$include_file" ]]; then  
    include_file="$default_include_file"  
  fi  
    
  
  # 输出信息  
  echo "---------------------------------------------"  
  echo "服务器:$server"  
  echo "用户名:$username"   
  # echo "所有资源:$sources"  
  echo "目标目录:$destination"  
  echo "使用 exclude_file 文件: $exclude_file"  
  echo "使用 include_file 文件: $include_file"  
  echo "开始同步至目录..."  
  echo "---------------------------------------------"  
  
  
  # 检查文件是否存在  
  if [[ ! -f "$exclude_file" ]]; then  
    echo "exclude 文件不存在: $exclude_file"  
    exit 1  
  fi  
    
  if [[ ! -f "$include_file" ]]; then  
    echo "include 文件不存在: $include_file"  
    exit 1  
  fi  
  
  
  for source in $sources; do 	
	if [ "$source" == "exclude.txt" ]; then  
		continue  
	fi  
	if [ "$source" == "include.txt" ]; then  
		continue  
	fi  
	if [[ $source =~ rsync_.*.sh ]]; then 
		continue  
	fi   
	
	
    # echo "当前同步资源文件: $script_dir/$source"  
	# 判断是否为文件  
	if [ -f "$script_dir/$source" ]; then  
		echo "rsync -a --exclude-from=$exclude_file "$script_dir/$source" $username@$server:$destination$source"
		
	#	rsync -a --exclude-from="$exclude_file" \  
	#	"$script_dir/$source" \  
	#	"$username@$server:$destination$source"
	fi  
	  
	# 判断是否为目录  
	if [ -d "$script_dir/$source" ]; then  
		echo "rsync -a --exclude-from=$exclude_file "$script_dir/$source/" $username@$server:$destination$source/"
		
	#	rsync -a --exclude-from="$exclude_file" \  
	#	--include-from="$include_file" \  
	#	"$script_dir/$source/" \  
	#	"$username@$server:$destination$source/"
	fi
	
  done 
}



#################################################################
#################################################################

show(){
	echo -e "\n"
	echo "----------------------------------"
	echo "please enter your choise:"
	echo "(1) 异步迁移指定文件|目录"
	echo "(2) 异步迁移所有文件"
	echo "(3) 移动脚本"
	echo "(6) 退出菜单"
	echo "----------------------------------"
}

menu(){
	input=0
	while [ $input -ne 6 ]
	do
	show
	read input
	case $input in
		1) rsync_files;;  #异步迁移指定
		2) rsync_all_files;;  #异步迁移所有文件
		3) move_script;;  #移动脚本
		6) exit;;
	esac
	done
}

menu

输入图片说明
输入图片说明

你有其他上下文或截图吗?

意向参与贡献

  • 我有意向参与具体功能的开发实现并将代码贡献回到上游社区

Comments (1)

SchuckBate created任务
SchuckBate added
 
enhancement
label
SchuckBate changed description
SchuckBate changed description
Expand operation logs

简单的排除可以使用配置,如果需要复杂的规则请自行使用脚本实现

输入图片说明

蒋小小 changed issue state from 待办的 to 已完成

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(2)
804942 bwcx jzy 1706672302
Java
1
https://gitee.com/dromara/Jpom.git
git@gitee.com:dromara/Jpom.git
dromara
Jpom
Jpom

Search

53164aa7 5694891 3bd8fe86 5694891