#! /bin/bash
tempfifo=$$.fifo
#获取同步路径
sdir=$1
ddir=$2
#ddir=${ddir%/*}
dirfile=/tmp/dirfile.txt
file_f=/tmp/file_f.txt
file_l=/tmp/file_l.txt
echo "获取源数据信息"
find ${sdir} -type d >${dirfile}
find ${sdir} -type f >${file_f}
find ${sdir} -type l >${file_l}
echo "获取源数据信息完成"
echo "建立目录中"
trap "exec 1000>&-;exec 1000<&-;exit 0" 2
mkfifo $tempfifo
exec 1000<>$tempfifo
rm -rf $tempfifo
for ((i=1; i<=1000; i++))
do
echo >&1000
done
while read fileurl
do
read -u1000
{
echo mkdir: ${ddir}${fileurl}
mkdir -p ${ddir}${fileurl}
echo >&1000
} &
done <${dirfile}
echo "目录建立完成"
echo "同步正常文件"
while read fileurl
do
read -u1000
{
echo sync: ${fileurl}
/bin/cp -a ${fileurl} ${ddir}${fileurl}
echo >&1000
} &
done <${file_f}
echo "同步正常文件完成"
echo "同步链接文件"
while read fileurl
do
read -u1000
{
echo sync: ${fileurl}
/bin/cp -ad ${fileurl} ${ddir}${fileurl}
echo >&1000
} &
done <${file_l}
echo "同步链接文件完成"
wait
exec 1000>&-
exit 0
网友评论