Skip to content

Instantly share code, notes, and snippets.

@didip
Last active March 13, 2019 13:53
Show Gist options
  • Save didip/4506837 to your computer and use it in GitHub Desktop.
Save didip/4506837 to your computer and use it in GitHub Desktop.
Simple script to download CentOS mirror. You can totally put this in cron.
#!/bin/bash
# Number of arguments should be at least 1
if [ $# -lt 1 ]; then
echo "Usage: $0 centos-version-number"
exit 1
fi
VERSION=$1
# Change these variables as appropriate
LOCK_FILE=/tmp/centos_mirror_rsync_updates
DOWNLOAD_LOCATION=rsync://mirrors.usc.edu/centos
TARGET_DIR=/tmp/centos
RSYNC_RETVAL=1
if [ -f $LOCK_FILE ]; then
echo "CentOS updates via rsync already running."
exit 0
fi
echo "Starting rsync from $DOWNLOAD_LOCATION/$VERSION to $TARGET_DIR/$VERSION..."
mkdir -p $TARGET_DIR/$VERSION
touch $LOCK_FILE
# add --exclude as necessary
rsync -avSHP --delete --exclude "centosplus" --exclude "contrib" --exclude "cr" --exclude "extras" --exclude "fasttrack" --exclude "isos" --exclude "os/i386" --exclude "updates/i386" $DOWNLOAD_LOCATION/$VERSION $TARGET_DIR/
RSYNC_RETVAL=$?
/bin/rm -f $LOCK_FILE
if [ $RSYNC_RETVAL -eq 0 ]; then
echo "Finished rsync from $DOWNLOAD_LOCATION/$VERSION to $TARGET_DIR/$VERSION."
fi
exit 0
@donnydavis
Copy link

Works like a boss, thanks man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment