# 假设A服务器为源文件,B服务器为接收A推送文件的目标服务器。
# A服务器创建无密码的公钥
#ssh-keygen -f ~/.ssh/id_rsa -q -P “"
# A的公钥拷贝到B服务器,实现登录免密
#scp ~/.ssh/id_rsa.pub user@10.1.1.1/home/user/.ssh/authorized_keys

if [ -f /var/tmp/rsync_updates ]; then
echo “Updates via rsync already running."
exit 0
fi

if [ -d /home/update/centos7 ] ; then
touch /var/tmp/rsync_updates

# 同步tsinghua的centos7最新包
rsync -aqzSHP –delete –exclude “local*" –exclude “isos" –exclude “atomic" –exclude “cloud" –exclude “dotnet" –exclude “configmanagement" –exclude “cr" –exclude “fasttrack" –exclude “infra" –exclude “messaging" –exclude “nfv" –exclude “opstools" –exclude “paas" –exclude “rt" –exclude “sclo" –exclude “storage" –exclude “virt" mirrors.tuna.tsinghua.edu.cn::centos/7/ /home/update/centos7/

# 同步tsinghua的epel7最新包
rsync -aqzSHP –delete –exclude “local*" –exclude “SRPMS" –exclude “aarch64″ –exclude “ppc64″ –exclude “ppc64le" –exclude “source" mirrors.tuna.tsinghua.edu.cn::epel/7/ /home/update/epel7/

# 推送centos7的最新包到下游更新服务器
rsync -aqzSHP –delete -e ‘ssh -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null’ /home/update/centos7/ user@10.1.1.1:/home/user/www/centos7/

# 推送epel7的最新包到下游更新服务器
rsync -aqzSHP –delete -e ‘ssh -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null’ /home/update/epel7/ user@10.1.1.1:/home/user/www/epel7/
/bin/rm -f /var/tmp/rsync_updates
else
echo “Target directory /home/update/centos7 not present."
fi

============BTW:rsync参数说明
-a, –archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
-v, –verbose 详细模式输出
-q, –quiet 精简输出模式
-S, –sparse 对稀疏文件进行特殊处理以节省DST的空间
-H, –hard-links 保留硬链结
-P, -partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输
-z, –compress 对备份的文件在传输时进行压缩处理