CentOS repo

It is my script to sync my internal CentOS with mirrors. Please change it based on your environment such as TARGET


#!/bin/bash
# This script rsyncs rpms down to the local Yumrepo server.
# It then creates a separate shell script (yum-createrepo-post-rsync-$Version2.sh)
# which runs createrepo in necessary folders.


#####
# variables that should be updated
#####
Version1="7.4.1708"  #Actual version of CentOS: 7.4.
Version2="${Version1}"  #Version of CentOS plus type. ex 6.6 basic.
RsyncSource="rsync://mirror.rackspace.com/centos"

#####
# variables
#####
YearMonth=`date "+%Y%m"`
Source1="$RsyncSource/$Version1"

Target1="/data/www"
Target2="yum-rpms/centos$Version2"
Target3="$Version1/os/x86_64"
Target="$Target1/$Target2/$Target3"
Target="/data/www/yum-rpms/centos$Version2" # where rpms are kept on local server

Create="yum-createrepo-post-rsync-$Version2.sh"  # script (to run createrepo) to be generated.
BinFolder="/root/bin"  # where my scripts are kept.
File1="centos$Version1-x86_64-comps.xml" # .xml file to be used for 'createrepo -g' command.
Folder1="/data/yum-comps"  # folder to hold 6.xxx_x86_64-comps.xml.

LogFolder="/root/logs"
LogOutput="yum-rsync-minimal-centos7.3-$YearMonth.log"

###
# script
###
mkdir $LogFolder 2> /dev/null

echo -e "`date`\nRsync and createrepo commands started" 2>&1 | tee -a $LogFolder/$LogOutput
### Rsync rpms down
# Rsync down $SOURCE1 only during initial setup of Yumrepo server or when you are moving from version 6.5 -> 6.6.
# Normally, rsync down of $SOURCE1 should be done only when you are ready to move from 6.5 -> 6.6. If you are ok
# with upgrading whenever CentOS does, then leave below uncommented.


# Rsync down the RPMs.
/usr/bin/rsync -av --bwlimit=4096 --exclude=repodata --exclude=i386 --exclude=debug --exclude=isos --delete $Source1 $Target1/$Target2/.
echo "`date +%F.%H-%M`: Rsync was executed successfully." 2>&1 | tee -a $LogFolder/$LogOutput


# Create $Create
cat <<EOM > $BinFolder/$Create
#!/bin/bash
# This script runs createrepo command in all directories with .rpm filddes.
EOM

find $Target1/$Target2 -name "x86_64" >> $BinFolder/$Create

sed -i "s/\/data/createrepo \/data/g" $BinFolder/$Create

echo "createrepo -g $Folder1/$File1 $Target1/$Target2" >> $BinFolder/$Create
echo "chown -R apache:apache $Target1/$Target2" >> $BinFolder/$Create



# Execute $Create.
chmod 750 $BinFolder/$Create
/bin/bash $BinFolder/$Create
echo -e "`date +%F.%H-%M`: Createrepo was executed successfully.\n" 2>&1 | tee -a $LogFolder/$LogOutput


chown -R apache:apache $Target1/$Target2

exit 0

Comments

Popular posts from this blog

VIOS TIPs

Configure Solaris 10 LDOM on Solaris 11.4

Change P410i from HBA mode to Raid mdoe