#! /bin/bash
D_DIR_CHANGED="lk/"
D_DIR_BAK="bak_"$D_DIR_CHANGED
len_D_DIR_CHANGED=`echo $D_DIR_CHANGED | wc -L`
D_DIR_ORG="lk_org/"
F_RESULT="res.txt"
F_LIST="list.txt"
if [ -e $F_RESULT ]; then
rm $F_RESULT
fi
if [ -e $F_LIST ]; then
rm $F_LIST
fi
find $D_DIR_CHANGED -type f > $F_LIST
while read st1; do
st1=${st1:$len_D_DIR_CHANGED}
F_ORG=$D_DIR_ORG$st1
F_CHANGED=$D_DIR_CHANGED$st1
if [ ! -e $F_ORG ]; then
echo "add: "$F_CHANGED
echo $st1 >> $F_RESULT
else
md5_org=`md5sum $F_ORG | awk '{print $1}'`
md5_changed=`md5sum $F_CHANGED | awk '{print $1}'`
#echo $st1 $md5_org $md5_changed
if [ ! "$md5_org" == "$md5_changed" ]; then
echo $st1
echo $st1 >> $F_RESULT
fi
fi
done < $F_LIST
if [ -e $F_LIST ]; then
rm $F_LIST
fi
while read st1; do
#echo $st1
#echo ${st1%/*} ${st1##*/}
if [ ! -d $D_DIR_BAK${st1%/*} ]; then
mkdir -p $D_DIR_BAK${st1%/*}
fi
cp $D_DIR_CHANGED$st1 $D_DIR_BAK${st1%/*}
done < $F_RESULT