#!/bin/bash
#设置日志文件名，以当前日期为后缀
DATE=`date "+%Y-%m-%d"`
log6=/home/data/mirrors/logs/yumsync7.log$DATE
echo > $log6
#将/etc/yum.repos.d/目录下的所有repo文件加上.bak的后缀，防止之前执行失败而导致有xxx.repo.bak被改为xxx.repo而没有改回xxx.repo.bak
for file in /etc/yum.repos.d/*.repo
do
mv $file $file.bak >> /dev/null 2>> /dev/null
done
#将centos6的repo文件的.bak后缀去除，使之开始生效
mv /etc/yum.repos.d/Centos-7.repo.bak /etc/yum.repos.d/Centos-7.repo
yum clean all
yum makecache
#同步centos6的包到本地
reposync -p /home/data/mirrors/centos7 >> $log6 2>> $log6
#为本地rpm包建立yum的索引
createrepo -p /home/data/mirrors/centos7/base/Packages/ >> $log6 2>> $log6
createrepo -p /home/data/mirrors/centos7/extras/Packages/ >> $log6 2>> $log6
createrepo -p /home/data/mirrors/centos7/updates/Packages/ >> $log6 2>> $log6
createrepo -p /home/data/mirrors/centos7/centosplus/Packages/ >> $log6 2>> $log6
#重新将centos6的repo文件加上后缀.bak，使之不影响其他repo的更新
mv /etc/yum.repos.d/Centos-7.repo /etc/yum.repos.d/Centos-7.repo.bak
#防止新同步的包权限为默认的600，而导致客户端安装包时报错forbidden
chmod -R 755 /home/data/mirrors/centos7
