Creating internal/local Centos 5 repository with rsync

Below is the bash script I use to mirror Centos repository into our local server. Due to storage limitation, we have to be selective and only copies the packages/branches that we need. Currently we only mirror Centos 5 for “os and updates” base packages limited to i386 and x86_64 architecture only.

During the initial intensive downloading when the server is replicating for the first time, I run the script below in cron for every 30 minutes. The script will check whether the previous instance is still running or dead (sometimes we got disconnected). If dead then it will restart and continue the rsync process. Once everything is in place and all needed packages have been downloaded, I modify the cron job to do the job once in every 6 hours to make sure my server is up to date.

The script below is inspired by the script posted here by jlar310

#!/bin/sh
# created by Jalte @ http://www.ridinglinux.org

DATE=`/bin/date +%Y-%m-%d`
OUTFILE=/var/www/html/mirror/centos-mirror.log
RSYNC="/bin/nice /usr/bin/rsync --verbose --progress --delete-excluded --stats --archive --partial --timeout=600"
MIRROR=mirrors.kernel.org::centos
VER=5
ARCHLIST="i386 x86_64"
BASELIST="os updates"
LOCAL=/var/www/html/mirror/centos

date >> /var/log/rsynccentos.log

if [ -f "/var/run/rsynccentos.pid" ]; then
   RUNPID=`cat /var/run/rsynccentos.pid`
   if ps -p $RUNPID; then
      echo "Mirror is already running..."
      echo "Mirror is already running..." >> /var/log/rsynccentos.log
      exit 1
   else
      echo "Mirror pid found but process dead, cleaning up"
      rm -f /var/run/rsynccentos.pid
      echo "Mirror pid found but process dead, cleaning up" >> /var/log/rsynccentos.log

   fi
else
   echo "No process Detected"
   echo "No process Detected" >> /var/log/rsynccentos.log

fi

echo $$ > /var/run/rsynccentos.pid

echo -n "Rsync Started at "
echo "Rsync Started " >> /var/log/rsynccentos.log
date

for ARCH in $ARCHLIST
do
  for BASE in $BASELIST
    do
        DIR=$LOCAL/$VER/$BASE/$ARCH/
        if [ -d $DIR ]
        then
         echo "Directory exists."
        else
         echo "Directory does not exist, and will be created."
         mkdir -p $DIR
        fi
        REMOTE=$MIRROR/$VER/$BASE/$ARCH/
        $RSYNC $REMOTE $DIR > $OUTFILE 2>&1
    done
done

echo "`date`" > /var/www/html/mirror/centos-last-updated.log
chown -R apache:apache $LOCAL

Any comments are greatly appreciated

Popularity: 33% [?]



Stumble it!

RSS feed | Trackback URI

3 Comments »

Comment by Dave
2007-08-02 23:24:58

Very nice - this is helpful for when you a have a number of centos servers where it would be helpful having an internal mirror for updates (saving the update bandwidth, or for kickstart purposes)

 
Comment by Eduardo
2007-11-29 04:13:10

This is great but I have a question. How do you modify yum to not go to public mirrors and only go to your private mirror?

 
Comment by danny
2008-02-04 23:55:12

Thanks for the awesome script. Was sriting one myself but stumbled upon yours.

Thanks again

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> in your comment.
Sexy lesbian BDSM squirting pussy pregnant teen asian shemale fuck bisexual teen sex girl foot fetish Adult dating tutorial Housewares Shop PORN FREE VIDEOS levitra purchase uk online viagra buy generic viagra online on line cialis soft tabs buy viagra soft tabs nichole double cum fat booty Blowjob Ninjas Lindsay Enjoys A Fat Cock porn videos free sex cam drunk madyson captain stabbin Evie Delatosso beach trannies boob tits stockings on pornstars klipal cream for women natural tramadol where to buy where to buy valium on line xanax on line uk rx pills Trazodon diazepam called in to local pharmacy viagra order levitra for woman oxazepam 0.5mg 100 tabs free zyban order online buy cialis buy lorazepam uk ed pharmacy women use tenuate free cialis soft tabs without prescription uk viagra soft tabs body building from sports supplement buy levitra in the uk canada online pharmacy cialis natural substitutes for viagra viagra prescription purchase cialis porn sex cialis soft tabs uk viagra soft tabs pharmacy cialis online discount whats a female viagra no prescription levitra natures alternative to cialis soft tabs generic viagra soft tabs cialis cheap levitra cheap viagra and pharmacy humor levitra in woman generic viagra india cialis female opinion