#! /bin/bash
if [ $# != 1 ];then
echo "USAGE: sh $0 /路径/包名"
exit 1
else
Package_Path_Full=$1
Dir_Path=${Package_Path_Full%/*}
Package_Name=${Package_Path_Full##*/}
if [ -e $Package_Path_Full ];then
if [ -d $Dir_Path/bak ];then
if [ -d $Dir_Path/bak/`date +"%Y%m%d"` ];then
cd $Dir_Path/bak/`date +"%Y%m%d"`
NUM_1=`ls -l | grep "$Package_Name" | wc -l`
NUM_2=`expr $NUM_1 + 1`
cp $Package_Path_Full $Dir_Path/bak/`date +"%Y%m%d"`/$Package_Name.$NUM_2
echo "备份成功"
else
mkdir -p $Dir_Path/bak/`date +"%Y%m%d"`
echo "创建目录 $Dir_Path/bak/`date +"%Y%m%d"`"
cd $Dir_Path/bak/`date +"%Y%m%d"`
NUM_1=`ls -l | grep "$Package_Name" | wc -l`
NUM_2=`expr $NUM_1 + 1`
cp $Package_Path_Full $Dir_Path/bak/`date +"%Y%m%d"`/$Package_Name.$NUM_2
echo "备份成功"
fi
else
mkdir -pv $Dir_Path/bak
if [ -d $Dir_Path/bak/`date +"%Y%m%d"` ];then
cd $Dir_Path/bak/`date +"%Y%m%d"`
NUM_1=`ls -l | grep "$Package_Name" | wc -l`
NUM_2=`expr $NUM_1 + 1`
cp $Package_Path_Full $Dir_Path/bak/`date +"%Y%m%d"`/$Package_Name.$NUM_2
echo "备份成功"
else
mkdir -p $Dir_Path/bak/`date +"%Y%m%d"`
echo "创建目录 $Dir_Path/bak/`date +"%Y%m%d"`"
cd $Dir_Path/bak/`date +"%Y%m%d"`
NUM_1=`ls -l | grep "$Package_Name" | wc -l`
NUM_2=`expr $NUM_1 + 1`
cp $Package_Path_Full $Dir_Path/bak/`date +"%Y%m%d"`/$Package_Name.$NUM_2
echo "备份成功"
fi
fi
else
echo "$Package_Path_Full 不存在"
fi
fi
备份程序包脚本
最新推荐文章于 2024-05-31 03:00:00 发布