Setting up a local CentOS mirror

I decided to set up a local CentOS mirror. Having never done so before, I searched for some examples, and then tweaked things to fit my needs. The basis of the script below was borrowed from here


MIRROR=[public mirror]

# Make sure rsync isn't already running
# not the best method, but should prevent cron from starting multiple copies
if [ -f $LOCKFILE ] && kill -0 `cat $LOCKFILE`; then
    echo "CentOS mirror sync is currently running"
    exit 1

# Write current pid to lock file
echo $$ > $LOCKFILE

# Build rsync filter for desired versions
filter="--exclude \"isos\" --exclude \"local*\" "
for version in $VERSIONS; do
    filter="$filter --include \"$version*/***\""
    filter="$filter --include \"$version\"" 
filter="$filter --exclude \"*\""

# Start rsync
# eval is needed because there are quotes in the 'filter' variable
eval /bin/rsync -aqSH --partial --timeout=300 --delete $filter $MIRROR::centos $DESTINATION

# Remove lock
/bin/rm -f $LOCKFILE

This should also capture the major version symlinks, so you can setup your local CentOS machines with the proper repo url, as opposed to a specific minor version. Make sure your web server is configured to properly serve symlinked files/directories.