repository clone
offline 환경이나 특수한 경우 repository를 별도로 구성해야 하는 경우가 있다.
reposync명령어를 이용하면 레포지토리를 복제 할 수 있다.
# RHEL 7 이하 버전
### 채널 하나씩 복제
reposync -nlmp ${REPO_DIR} --downloadcomps --download-metadata -r ${REPO}
### 모든 리포 복제
reposync -nlmp /repo/ --downloadcomps --download-metadata
# RHEL 8 이상버전
### 채널 하나씩 복제
dnf reposync --download-metadata --downloadcomps --newest-only -p ${REPO_DIR} --repo=${REPO}
### 모든 리포 복제
dnf reposync --download-metadata --downloadcomps --newest-only -p /repodata/
또한 RHEL 7 이하 버전에서는 복제된 리포를 사용하려면 createrepo명령어를 사용하여 메타 디비를 만들어줘야 한다.
createrepo -g $d/comps.xml .
RHEL 8 이상 버전에서는 복제시에 생성되므로 따로 생성해줄 필요가 없다.
스크립트 예제
- RHEL 7 이하버전
#!/bin/bash
DATE=`date "+%F %T"`
REPO_DIR="/repo/"
echo "=== $DATE ===" |tee -a /var/log/reposync.log
echo "=== REPOSYNC START ===" |tee -a /var/log/reposync.log
date >> /var/log/reposync.log
cd ${REPO_DIR}
#rm -rf /var/cache/dnf
REPOS=($(subscription-manager repos --list-enabled |grep " ID:" |sed 's/.*://'))
for REPO in "${REPOS[@]}"; do
echo "##### ${REPO} START" | tee -a /var/log/reposync.log;
#dnf reposync --download-metadata --downloadcomps --newest-only -p ${REPO_DIR} --repo=${REPO} 2>&1 | tee -a /var/log/reposync.log
reposync -nlmp ${REPO_DIR} --downloadcomps --download-metadata -r ${REPO} 2>&1 | tee -a /var/log/reposync.log;
echo "##### ${REPO} END" | tee -a /var/log/reposync.log;
done
# old method
#reposync -nlmp /repo/ --downloadcomps --download-metadata >> /var/log/reposync.log
echo "=== REPOSYNC END ===" | tee -a /var/log/reposync.log;
date >> /var/log/reposync.log
- RHEL 8 이상 버전
#!/bin/bash
DATE=`date "+%F %T"`
REPO_DIR="/data/"
echo "=== $DATE ===" |tee -a /var/log/reposync.log
echo "=== REPOSYNC START ===" |tee -a /var/log/reposync.log
date >> /var/log/reposync.log
cd ${REPO_DIR}
#rm -rf /var/cache/dnf
# 전체 리포 리스트
REPOS=($(subscription-manager repos --list-enabled |grep " ID:" |sed 's/.*://'))
# 삭제할 리스트
DISREPO=()
# 리포리스트에서 하나씩 갱신시도
for REPO in "${REPOS[@]}"; do
echo "##### ${REPO} START" | tee -a /var/log/reposync.log;
RET=$(dnf reposync --download-metadata --downloadcomps --newest-only -p ${REPO_DIR} --repo=${REPO});
RESULT=$?;
echo "${RET}" >> /var/log/reposync.log;
if [ ${RESULT} -eq 1 ]
then
echo "### result : ${RESULT} Disable repo : ${REPO}" | tee -a /var/log/reposync.log;
DISREPO+=("${REPO}");
fi
echo "##### ${REPO} END" | tee -a /var/log/reposync.log;
done
# old method
#dnf reposync --download-metadata --downloadcomps --newest-only -p /repodata/ >> /var/log/reposync.log
### Disable repo 처리
DISSTR=""
for val in ${DISREPO[@]}
do
DISSTR="${DISSTR} --disable=${val}";
done
if [ -n "${DISSTR}" ]; then
echo "### subscription-manager repos ${DISSTR}" | tee -a /var/log/reposync.log;
subscription-manager repos ${DISSTR};
fi
#### 종료
echo "=== REPOSYNC END ===" |tee -a /var/log/reposync.log;
date >> /var/log/reposync.log