功能 将当前目录下文件拷贝至另一目录下,且拷贝前先备份
#!/bin/sh
#脚本功能
#覆盖文件前先备份
cfsuffix=$(date +%Y%m%d); #备份文件后缀
if [ $# -lt ]; then #输入参数说明
echo "error...need args\n"
echo "eg:path1 path2"
echo "path1 files backup and copy to path2"
exit
else
path1=$;
path2=$;
echo $path1;
echo $path2;
#if [ [ -d "$path1" ] && [ -d "$path2" ] ]; then
if [ -d "$path1" -a -d "$path2" ]; then
ls $path1 | awk -F'[ ]' '{print $1}' | while read filename
do
sfile=$path1'/'$filename; #源文件
pfile=$path2'/'$filename; #需备份文件
cfile=$path2'/'$filename'.'$cfsuffix; #备份后文件
if [ -f $sfile ]; then
if [ -f $pfile ]; then
cp $pfile $cfile && a= || a=;
if [ $a -eq ]; then
echo $filename "backup success!";
cp $sfile $path2;
else
echo $filename "backup error!"
fi
else
echo $pfile "not find!";
cp $sfile $path2;
fi
fi
done
else
echo "error...args path not find!";
fi
fi