#!/bin/bash
#亚特兰蒂斯-同步目录
#定时任务
ini_file="/usr/local/sunlight/conf/rsync-file.ini"
target_ip="10.108.144.2"
pk_file="/usr/local/sunlight/sshkeys/init.pk"
if [ ! -f $ini_file ];then
echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` $ini_file does not exist!"
exit 1
fi
if [ ! -e $pk_file ];then
echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` $pk_file does not exist!"
exit 1
fi
while read line
do
if [[ ! -d $line && ! -f $line ]];then
echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` direcoty or file: $line does not exist!"
exit 1
fi
if [ ${line:0:1} != "/" ];then
echo " [ Error ] $line must start with /"
exit 1
fi
if [[ -d $line && ${line:0-1:1} != "/" ]];then
line="$line/"
fi
if [ -d $line ];then
ssh -p2222 -i /usr/local/sunlight/sshkeys/init.pk -o strictHostKeyChecking=no $target_ip "test -d $line || mkdir -p $line"
fi
if [ -f $params ];then
param_dir=${line%/*}
ssh -p2222 -i /usr/local/sunlight/sshkeys/init.pk -o strictHostKeyChecking=no $target_ip "test -d $param_dir || mkdir -p $param_dir"
fi
echo "rsync $line......"
rsync -avztog --progress -e "ssh -p2222 -i /usr/local/sunlight/sshkeys/init.pk -o strictHostKeyChecking=no" ${line} ${target_ip}:${line}
done < $ini_file