shell脚本复制文件夹内容到另外的文件夹,如果存在则自动备份

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/sh
upload_dir=/alidata/www/sh/useful-shell-script/upload/
www_dir=/alidata/www/sh/useful-shell-script/www/
backexist()
{
filelist=`ls $1`
for file in $filelist
do
if [ -f $1$file ]
then
if [ -f $2$file ]
then
cp $2$file $2$file”_bak_”`date +%Y-%m-%d`
fi
else
backexist $1$file”/” $2$file”/”
fi
done
}
backexist $upload_dir $www_dir
cp -R $upload_dir”.” $www_dir