度娘知道:http://zhidao.baidu.com/link?url=DD47jm6qDgT7yxsnz9e-NC4Fqd33oRoiIwcGLkw5TL4cbf50VKY2IONbHKH0IE8wOEWsB3p4bhBF2-U3oE4tTa
执行的shell脚本(可看作一个函数吧):
1 #!/bin/sh 2 3 show_usage() { 4 echo "Usage: backup_f.sh src_folder bak_folder bak_date" 5 echo "**********************************************" 6 echo "src_folder - source folder to backup" 7 echo "bak_folder - backup folder" 8 echo "bak_date - backup date in YYYYMMDD format" 9 echo "bak_filename - like this: ROOT.tar" 10 echo "**********************************************" 11 } 12 13 14 if [ $# -ne 4 ]; then 15 show_usage 16 exit 1 17 fi 18 19 src_folder="$1" 20 bak_folder="$2" 21 bak_date="$3" 22 bak_filename="$4" 23 24 bak_file="$bak_folder/$bak_filename" # 这里把备份文件名固定为backup.tar了,你可以根据需要做些修改 25 if [ -f $bak_file ]; then 26 rm $bak_file 27 fi 28 #echo $bak_file 29 #exit 1 30 31 tmpfile="`mktemp`" 32 touch -t ${bak_date}0000 $tmpfile 33 cd $src_folder 34 find . ! -name "persistence.xml" ! -path "./WEB-INF/logs*" ! -path "./Statics/*" ! -path "./scripts/lib/*" -newer $tmpfile -exec tar rvf $bak_file {} \; 35 rm $tmpfile 36 37 if [ -f $bak_file ]; then 38 echo "backup file: $bak_file" 39 fi 40 #ls -l $bak_folder
调用的shel脚本:
1 #!/bin/sh 2 src_folder="/code/git/workSystem/src/main/webapp" 3 bak_folder="/Users/cnblogs/Documents/b2bweb" 4 last_modify_date="20151028" 5 bak_filename="ROOT.tar" 6 7 sh backup_f.sh $src_folder $bak_folder $last_modify_date $bak_filename
原来也用find命令弄过,都一直用着,但是突然在升级到OS X El Capitan后突然用不了,报错了:unknown primary or operator.
我查一下资料,都没有找到解决的办法,遂找回开头的百度知道答案,稍微改改,能用了。
时间: 2024-10-12 15:28:33